Go Down

Topic: while (!Serial) needed for Arduino Micro? (Read 104 times) previous topic - next topic

liudr

I just got an Arduino Micro. I remember that you need the following for arduino Leonardo:

Code: [Select]
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only


Is this also needed for Micro since Micro uses the same 32U4? Thanks.

I tested printing stuff from Micro to PC. It seems to work without the while but I was printing analog values repeatedly and I didn't check if the first line printed out.

Grumpy_Mike

Quote
Is this also needed for Micro since Micro uses the same 32U4? Thanks.

Yes.

liudr

Thanks Mike. For some reason I was able to print to serial port without it. Is this needed if you want Micro to receive stuff from serial port, send stuff to serial port, or to make sure the first messages get sent or received? If I do serial methods without connecting to the usb, will the code throw exception and stop?

Grumpy_Mike

I think it is to give time for the USB to enumerate on the host machine. I could well see that this could have happened in the time that the bootloader is looking for an upload. It would depend on the speed of your computer, so maybe this is for older slower computers. But this is pure speculation on my part.

Quote
For some reason I was able to print to serial port without it.

Yes I think it is only critical for uploading a new sketch.

Go Up