ESP32 Serial Monitor Prints Garbage After Reset Prints Correctly

I built a simple program using ESP-WROOM-32D.
I am using a 2019 Intel Mac with Sonoma.

void setup() {
  pinMode(2, OUTPUT);
  Serial.begin(115200);
  Serial.println("Started");
}
void loop() {
  delay(1000);
  digitalWrite(2, HIGH);
  Serial.println("Hello from the loop");
  delay(1000);
  digitalWrite(2, LOW);
}

Initially, the serial monitor prints garbage.
When I reset the ESP (press the env button) the serial monitor prints correctly.

Intial run:
����������� ��nn.��|?�. �.� n..�

After reset:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4832
load:0x40078000,len:16460
load:0x40080400,len:4
load:0x40080404,len:3504
entry 0x400805cc
Started
Hello from the loop
Hello from the loop

What could be the cause of this?

Wrong baud rate. Generally, ESP devices use a different baud rate for programming and then switch to the user-defined baud rate once programming is finished. During programming, it may send messages, but they would be at the programming baud rate. I always start setup() with Serial.begin(115200); followed by delay(2000);. This helps keep the debug monitor screen clean.

I tried this but still experienced the same problem.
I also tried a delay of 5000 but still have the same problem.

Put it after serial.begin, your code does not show that statement.

Normal initialization. Press the reset button.

This still causes the same problem:

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  delay(2000);
  Serial.println("Started");
}

Pressing the reset button every time after initialization works but its not the normal workflow. What happens if I need to place my ESP inside some device and I do not have access to the reset button.

Try a longer delay after the Serial.begin.
If the ESP is somewhere you don't have access, the problem won't happen. It is caused by initializing the Serial port.

1 Like

I tried a delay of 10000 but still got the same problem.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  delay(10000);
  Serial.println("Started");
}

All I know is that it always happens when I first plug in the cable. I did see someone from Arduino I think explain it and it is normal. You said in post #7 what if inside, I did that and had no issues. You don't have a Serial log in that case.

The problem I experience with garbage being printed occurs every time I upload the program, not just when I first plug in the cable. Also, at times, when I upload the program, it doesn't run at all until I press the reset button. Adding a long delay does not solve it. I do believe that it has something to do with the wrong baud rate. Still uncertain how I can fix my problem.

To reiterate what happens now is I upload the program and it either doesn't run or runs and the serial monitor prints garbage. After I press the reset button it runs correctly.

The correct behaviour should be I upload the program and it runs and the serial monitor prints correctly.

I tried several different cables and experienced the same problem.
I tried the Arduino IDE and PlatformIO IDE and experienced the same problem.
Hoping to try reproducing on a different Mac.
Any advice on how I can debug this further?

That is how it works for me also. Just press the button .

1 Like

I think those are the leftovers of the upload process that are stuck in your PC.

When the serial monitor starts, it just displays these leftovers.

2 Likes

The same program shows this on the serial monitor with 115200 shows this:

ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:1

load:0x3fff0030,len:4604

ho 0 tail 12 room 4

load:0x40078000,len:15488

load:0x40080400,len:4

load:0x40080404,len:3180

entry 0x400805b8

ǃeFÛÒ?�Nad?��?�na$?��?�na$?��?�na$?��?�na$?��?�na$?��?�na$?��?�na$?��?�na$?��?�na$

I had the same problem with serial printing garbage on an ESP32-S3-N16R8 processor. The simple fix was add a one second delay before intialising serial.
500ms doesn't work, 1000ms does... ???

void setup()
{
  delay(1000);   // undocumented delay required after upload, or baud rate is wrong!!
  Serial.begin(115200);
  Serial.println(F("Arduino_GFX LVGL Hello World example\n"));
  delay(100);


1 Like