Serial Monitor doesn't show output from setup function

Original issue: getting Serial.println("debug string") debug output is currently not working. So any type of debugging with usb-connection only is not happening.

edit: the serial monitor is showing something in the loop() but nothing in the setup().

Edit: adding delay(3000); into the setup() waits enough time to get the Serial.println("debug string") working inside setup().

I wonder why the setup() does not wait by default until all the default devices are setup and running.

With Nano I think you could try and see if adding this will do the job:

...
void setup() {
  Serial.begin(115200); // or whatever...
  while(!Serial) ; // Wait for the serial...
  Serial.println("STARTED");
...

yep while(!Serial); worked.

fyi, I assumed something was broken when the debug did not work (Debugging in blank fresh install of ide v2.3.4 fails).
because the debug button is a front page feature/button.

Good.
That while() is required for any board with a physical USB chip onboard to make sure the USB serial is ready (i.e. if you don't have the USB connected). Only if the USB connection is not required for the sketch to run, don't add it.
It's useless for the other boards, but you can still keep it, as "Serial" always returns "true" for other boards, so the while() won't stop,

HOWEVER, if he ever wants to not use USB for power but a battery on VIN, the WHILE will never end. I AND that with a millis check in order to progress beyond the while.

while (!Serial && (millis() < 5000)) ;  // Wait up to 5 secs for Serial to be ready
1 Like

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