arduino compatibility, writing to serial monitor from setup does not work?

vsurducan

Member
Hi all,

Teensy 3.1, Tensduino 1.24, arduino 1.6.5r2
or
Teensy 3.1, Tensduino 1.23, arduino 1.6.3

Running the next sketch return in the serial monitor only "Test writing from loop"
Under Arduino uno writing from setup works. Do I miss something?

thank you,
Vasile

#include <Wire.h>

void setup() {
// put your setup code here, to run once:

Serial.begin(9600);
Serial.println("Test writing from setup");
delay(1000); // delay 1 second
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println("Test writing from loop");
delay(1000); // delay 1 second
 
You need a delay or "while (!Serial) ;" at the beginning of setup. The same is required on Arduino Leonardo, because it's native USB.
 
You need a delay or "while (!Serial) ;" at the beginning of setup. The same is required on Arduino Leonardo, because it's native USB.

Thx Paul, with "while (!Serial) ;" works ok, but with 1s delay at the beginning of setup it doesn't, I've tried before sending the email...
Is there a documentation for those funny "tricks" ? Maybe on Leonardo?
 
The delay would go after
Serial.begin(9600);
but before the
Serial.println("Test writing from setup");

so if below does not work try increasing to 2 seconds,
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); // delay 1 second
Serial.println("Test writing from setup");
}
 
Thank you Fretless, I've got it finally.

It seems either a "delay(x)" or a "while (!Serial);" is must before any attempt to "serial print()" from setup.
 
Back
Top