Baudrate changes after boot

Hello there,

I am using an ESP32 TTGO Lora Oled V1 and uploaded this simple sketch

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
}
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  
  Serial.println("on");
  delay(1000);                      
  digitalWrite(LED_BUILTIN, LOW);  
    Serial.println("off");
  delay(1000);                       
}

The board boots and the serial monitor shows this:

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

but then immediately after the serial monitor only shows gibberish.
Only after changing the baudrate in the serial monitor to 74880 the 'on'... 'off' shows up correctly.

I also tried setting the baudrate to a different value but the problem is the same.
The baudrate during boot stays 115200 but after it is one baudrate lower than selected. With low baudrates like 9600 it doesn't work at all

can anyone help? What's going on here?

The baudrate in the Serial.begin(baudrate) and the setting on the serial monitor have to be the same.

if they are the same only gibberish shows up.

this shows up on the serial monitor with the baudrate 74880

�P�V��ET�Q�UU�T��-�QRQT�JU�WU�J���u��\j��T�J�R�J�u�uT�T��U���-QBU��j��EJ�R�Zq��R�Zq�uT�Zq���R�Zq��WխQ(���խQ(Eե�I���T�U�UZ�Eu����(U�UVKU�QD�Qi���U�u��Q��T�\EԱQ�UV+U�Q��T�\EQE��jZUEu��TQQER��U�Ej��PqQQ*XQ�started

on

off

on

off

on

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$

Do you have the correct board and revision selected in board manager?

Just wondering whether it might be a CPU clock speed configuration problem.

I'm pretty sure I have. I have used this board before and it worked just fine.
I selected TTGO LoRa32-OLED
I also tried this with a different board of the same model and the problem is the same.

If you look under Tools, when you have selected that board, you also further down get a 'Board revision' option. In the IDE here I see 3 revision options.

I know its pretty basic, but have you tried another USB cable - just in case?

I don't suppose there is anything else connected to the serial port?

Just as an experiment, if you set the baudrate to 57600, does it then work if you set serial monitor to 37440? Or at 9600, does t show correctly at 6240 in serial monitor? Just wondering whether the timing is consistent or random.

I tried all 3 options under the menu Board revision.

If I set the baudrate to 57600 the monitor shows the text at 38400.
If set to 9600 the monitor shows only gibberish at any baudrate. I cannot select a baudrate of 6240.

I also used different cables.

Hmm...
I believe a delay is required after Serial.begin(115200) to allow a bit of time for the serial port to start:

  Serial.begin(115200);
  delay(5000);

Maybe try that first and see what happens.

Also you can add the following after the delay(5000) to report back what speed the CPU and Crystal are running at:

  Freq = getCpuFrequencyMhz();
  Serial.print("CPU Freq = ");
  Serial.print(Freq);
  Serial.println(" MHz");
  Freq = getXtalFrequencyMhz();
  Serial.print("XTAL Freq = ");
  Serial.print(Freq);
  Serial.println(" MHz");

I added the delay

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  delay(5000);

  float Freq = getCpuFrequencyMhz();
  Serial.print("CPU Freq = ");
  Serial.print(Freq);
  Serial.println(" MHz");
  Freq = getXtalFrequencyMhz();
  Serial.print("XTAL Freq = ");
  Serial.print(Freq);
  Serial.println(" MHz");
}
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  
  Serial.println("on");
  delay(1000);                      
  digitalWrite(LED_BUILTIN, LOW);  
    Serial.println("off");
  delay(1000);                       
}

this is what I get from the serial monitor at 74880

�P�V��ET�Q�UU�T��-�QRQT�JU�WU�J���u��\j��T�J�R�J�u�uT�T��U���-QBU��j��EJ�R�Zq��R�Zq�uT�Zq���R�Zq��WխQ(���խQ(Eե�I���T�U�UZ�Eu����(U�UVKU�Q��T�\EԱQ�UV+U�QQD�Qi���U�u��Q��T�\EQE��jZUEu��TQQER��U�UEj��PqQQTQ�CPU Freq = 240.00 MHz

XTAL Freq = 40.00 MHz

on

off

on

what Tools>Board are you using?
with my TTGO Lora Oled V1 if I use "TTGO LoRa-OLED" I get with serial Monitor baud rate 115200

CPU Freq = 240.00 MHz
XTAL Freq = 40.00 MHz
on
off
on
off
on
off
on
off
on

note LED is on GPIO2

Hi, @asqwas
Welcome to the forum.

Can you please post some images, top and bottom of your ESP32 controller?

What IDE version are you using?
What OS?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

It is some time since I used the ESP32 TTGO Lora Oled V1 and I remembered that the Tools>Board I used was "Heltec WiFi LoRa32"
however, using ESP32 core 3.1.0 if I run any program the serial output is garbage, e.g. at Serial.begin() and Serial Monitor set to 115200

9��*��C��R_e!�8x*DI�C��WS!�9��"ep`D�y0*8��*$	���WS!�1��"e��C��y0
8��*$��"�R_e!�8x de�C�b�P_!�1�� d9"G�Re!�8x*de�C�"��y0
8��*$0bD�WS!�9��"ee��c���T

changing Serial Monitor baudrate to 7488, 57600, 38400, still gives garbage

if I use ESP32 core 2.0.17 Serial Output is OK

also ran P2P LoRaReceiver etc OK- see ttgo-lora32-sx1276-arduino-ide

I’ve noticed this issue with ESP devices as well. The reason, I believe, is that they program at a specific baud rate, regardless of the terminal’s settings. When the IDE uploads code, it temporarily changes the baud rate to match what the programmer needs. After the upload is complete, it switches the baud rate back to the user-defined setting.

During the upload process, data is exchanged between the ESP device and the programmer at the programming baud rate. If the buffers aren’t flushed properly before switching back to the user-defined baud rate, you may see garbage output. This issue might also include the acknowledgment for the final code record being processed.

To address this, I typically add a delay after the upload and then explicitly set the desired baud rate. This approach has worked reliably for me.

using the ESP32 TTGO Lora Oled V1 tried delay() after upload before Serial.begin() same problem of corrupt output with WSP32 Core 3.1.0
also tried closing the Serial and calling begin again, e.g.

void setup() {
  delay(5000);
  Serial.begin(115200);
  delay(2000);
  Serial.end();
  delay(2000);
  Serial.begin(115200);

still corrupt output

EDIT: as I mentioned in post 12 if I use ESP32 core 2.0.17 Serial Output is OK

just checked ESP32 TTGO Lora Oled V2 and V3 serial output OK with ESP32 core 3.1.0

Is your terminal set at that baud?

@TomGeorge Here are the photos of the board:


I am using Arduino IDE 2.3.4 on windows 10 64bit.

@horace
I have a Heltec WIfi Lora32 V3.2 too and that one doesn't have that problem

@gilshultz
In the program I set the baudrate at 115200 but in the terminal the data only shows at 74880

At this point it appears you have a bad unit. See if you can get it replaced under warranty.

when using ESP32 core 3.1.0 the serial monitor on my ESP32 TTGO Lora Oled V1 shows garbage all at baud rates -serial output OK with ESP32 core 2.0.17
maybe worth raising a post on the Espressif Arduino Forum

I have two of these boards and they both have the same problem. Also they worked just fine a week ago. It is pretty unlikely that both of them broke at the same time.

I found a fix to the problem.
I downgraded the esp32 library to 2.0.17 and now everything works fine again. Here is a link on how to do that and how to turn off the automatic update suggestions
https://forum.arduino.cc/t/downgrade-from-v3-0-x-to-v2-0-x/1272211/2