Serial connection question

Status
Not open for further replies.

Bullone

Well-known member
Hi all!
I'm using Teensy v3.6 and on my setup I have something like this:

// Wait Serial Monitor to open
Serial.begin(SERIAL_BAUD);
while (!Serial) ;

I use this kind of Serial init on my Arduino board but on Teensy it seems that if I don't connect the serial monitor (Arduino IDE or Putty) the code stack on "while (!Serial) ;".
Is that the correct behaviour? My problem is that my board won't startup if I just power it with no serial monitor opened.
I just remove that line and everything seems work fine but I'd like to understand better.

PS: I also can't see the setup Serial dump messages when I connect the board with Putty...
 
That is normal Teensy Behavior, !Serial is an absolute and it will never leave the while until connected.

Teensy has TRUE USB hardware on the processor and until the Teensy starts up and gets to setup in about 300ms - the PC has not yet recognized the Teensy as a USB device until about 400 ms has passed.

In the case of Arduino they may have an always on USB chip that the PC never loses connection with during program and restart - the Arduino starts more slowly - but it talks to USB over UART and that offers different behavior.

Put something like this in setup() to wait - in this case 2 seconds - then continue without Serial.
Code:
while ( !Serial && millis() < 2000 );
 
Status
Not open for further replies.
Back
Top