Serial Monitor not displaying anything - my solution

It is about outputting debug messages via Serial.print on the “IDE Serial Monitor”. This worked for me in one sketch and not in another, but then suddenly it did. Strange.
It took me a quite long time to find out why. I would like to share the result with you in case someone falls into the same trap.
This code should work:

void setup() {
  Serial.begin();
  delay(100); // **<-- this is important, the delay is necessary!** 
  Serial.println("Moin! ”); // doesn't matter
}
void loop() {
  while (1) {
    Serial.print(“*”);
    delay(1000);
  }
}

A baud rate does not have to be specified for begin(), and the “while(!Serial);” is also unnecessary. The baud rate in the monitor is also irrelevant, whether it says 9600 or 2000000 does not matter. The only important thing is the delay(100) after begin(). At least that's what my experiments have shown. It may be that the delay is different depending on the processor speed. I have a 160MHz ESP32-C3, using IDE 2.3.3.

I compiled your sketch for both a SparkFun Pro Micro and an ESP32-C3 dev module. Both broke their neck over the Serial.begin() without an paramter.

That's the case for boards with native USB as they don't use a UART to communicate with a PC.

If you do not want to miss the first printed data in a board with native USB, you will need the while(!Serial); Your board will go through your code after the delay and if e.g. serial monitor is not open you will never see the messages that you might print in setup().

Both compiles were done using that latest versions of the board packages in IDE 2.3.3.

Good points, thank you. I didn't know that other boards are working different. I have no other board than the ESP32-C3 super mini, so please take everything I wrote only for this board. Sorry, I didn't want to confuse anybody.
But perhaps it helps somebody.

But it still does not compile due to the missing baud rate in Serial.begin(). Did I pick the correct board (ESP32-C3 dev module) or do I need to select another board ESP32 board?

I'm using ESP32-C3 dev module with COM3, IDE 2.3.3. No compile & build errors with this:

void setup() {
  Serial.begin();
  delay(100);
  Serial.println("Moin!");
}
void loop() {
  Serial.println("");
  while (1) {
    Serial.print("*");
    delay(1000);
  }
}

Just tried compiling code in post #5 out of curiosity.

ESP32-C3 dev module, ESP32 version 3.0.7 - USB CDC on boot - enabled. Compiles fine:

Sketch uses 273548 bytes (20%) of program storage space. Maximum is 1310720 bytes.
Global variables use 12284 bytes (3%) of dynamic memory, leaving 315396 bytes for local variables. Maximum is 327680 bytes.

However, with USB CDC on boot - disabled it "broke its neck" :wink:.

C:\Users\wille\AppData\Local\Temp\.arduinoIDE-unsaved20241020-9032-1x43zwt.si4p\sketch_nov20a\sketch_nov20a.ino: In function 'void setup()':
C:\Users\wille\AppData\Local\Temp\.arduinoIDE-unsaved20241020-9032-1x43zwt.si4p\sketch_nov20a\sketch_nov20a.ino:2:15: error: no matching function for call to 'HardwareSerial::begin()'
    2 |   Serial.begin();
In file included from C:\Users\wille\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:200,
                 from C:\Users\wille\AppData\Local\Temp\arduino\sketches\5C0212A79AD1FB82C026BF184B9E5D92\sketch\sketch_nov20a.ino.cpp:1:
C:\Users\wille\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/HardwareSerial.h:252:8: note: candidate: 'void HardwareSerial::begin(long unsigned int, uint32_t, int8_t, int8_t, bool, long unsigned int, uint8_t)'
  252 |   void begin(
      |        ^~~~~
C:\Users\wille\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/HardwareSerial.h:252:8: note:   candidate expects 7 arguments, 0 provided

exit status 1

Compilation error: no matching function for call to 'HardwareSe

This is expected.

I would, however think the while(!Serial); is necessary for native USB. On some of my sketches I need to add a delay as well else I miss the start of a serial monitor message.

1 Like

Ah, learned something again :+1: