Sketch doesn't run after power up

Hello,

I want just to give a feed back from a programming problem (fixed) I had with a Yun board (but I believe existingwith all boards)

Problem: When I download the sketch all is fine it is working, but if i remove usb link and connect it again to my PC the sketch dosn't work ???

Solution found : I use the loop while (!serial.begin) inside the setup up task and this lines blocks the sketch if the serial is not up.

When I comment these lines or open serial monitor window all if working again!

I don't know if it is normal (because I don't use input from serial) but this "work around is working!

If that can help some others beginners it will be fine! :slight_smile:

I think this is expected. The "Arduino" chip on the Yun is an ATmega32U4, and similar fixes involving Serial port are often needed for other types of arduino based on same chip.

Welcome to the forum.

This is a known problem.
When developing a sketch and using debug messages, then the Serial port should run before continuing.

void setup()
{
  Serial.begin(115200);
  while( !Serial);         // wait for Serial
  Serial.println("Debug Message");
}

However, if the Serial Monitor of the Arduino IDE is not opened, then it waits forever.

You could wait for 30 seconds and then continue. But if the Serial port is not opened, then you should not use debug messages to the Serial port.
You could also use debug messages that can be turned off with a #define.

This is not a problem for a Arduino Uno, because it has a separate usb-serial chip.

Thanks you for yours explanations!

Regards

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.