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
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.
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.
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?
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);