phdoerfler
phdoerfler

Reputation: 479

How to prevent serial garbage at the beginning

Whenever I connect to my ESP32 using pio device monitor I initially get a bunch of garbage data before my program takes over and from there on everything is fine:

$ pio device monitor
--- Miniterm on /dev/cu.wchusbserial1450  500000,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

x��xxxx�x�␀�␀�␀����␀�x����␀�␀�␀�������������x�����x␀�xx␀�x��x�x�x��␀�␀x␀�␀�␀x␀x��xxxxx�x��x�xx��xx␀x�xx␀xxx�x␀x�␀x�x�x�x��␀�␀x␀����␀�␀x��x␀xx�xx�␀x␀x�x␀xxx�␀x�x␀x�x␀�xx�␀x�x�xxx�xx␀�x�␀x�x�x�x��x�x�x��xx��␀�␀�␀x␀���x␀xx�xxxx���␀�␀xxxxx�␀�x�␀x�xxxx␀�x�x�x��␀�␀x�␀�␀xxxx␀�x�x�x��␀�␀x�␀�␀x␀�xx␀�x�x�x��␀�␀x�␀�␀x�␀x�x��x␀�x�x�x��␀�␀x�␀�␀x␀�x�xx␀�x�x�x��␀�␀x�␀�␀x��xxx␀�x�x�x��␀�␀x�␀�x␀�xx�x�x�xxx��␀␀x��x�xx␀��␀x�x�x␀xxx�␀�x��x�x�����x␀�x␀�x�x␀x�x��␀�␀x����x�x�x�␀�x�␀�␀x␀�xxx�x��␀��x␀�x␀�x�x␀x�x��␀�␀x����x�x�x�␀�x��␀xx␀�xxx�x��x�␀�␀��␀��x␀�x␀�x�x␀x�x��␀�␀x��␀�␀����␀�␀�␀�␀�␀x␀�xxx�x��␀�␀�x����x␀�x␀�x�x␀x�x��␀�␀x��␀�␀�␀�␀�␀��␀�␀�␀x␀�xxx�x��x��␀����␀�x␀�xx�x�x�x�x�x�␀�␀x��␀�␀�␀�␀����xx␀x�␀�x�
Locating devices… 0 found.

Searching the web yielded mostly "Make sure your baud rates match" and they do. They are both 500000:

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino
upload_port = /dev/cu.wchusbserial1450
upload_speed = 500000
monitor_speed = 500000
monitor_port = /dev/cu.wchusbserial1450
lib_deps = 
    OneWire
    DallasTemperature
void setup() {
  Serial.begin(500000);
  Serial.println();
  // …

Using a baud rate of 9600 only changes the amount of garbage at the beginning. It is a lot less but it's still not gone completely.

Here's a hexdump (excerpt):

00000000: 78ef bfbd 78ef bfbd 78ef bfbd 78ef bfbd  x...x...x...x...
00000010: efbf bd78 7878 78ef bfbd 78ef bfbd e290  ...xxxx...x.....
00000020: 80ef bfbd e290 80ef bfbd e290 80ef bfbd  ................
00000030: efbf bdef bfbd efbf bde2 9080 efbf bd78  ...............x
00000040: efbf bdef bfbd efbf bdef bfbd e290 80ef  ................
00000050: bfbd e290 80ef bfbd e290 80ef bfbd efbf  ................

Any clue what's going on here? My theory is that the serial monitor connects before my program on the ESP32 is actually running. I get the exact same behaviour using the serial monitor in the Arduino IDE. I'm using macOS Catalina. The module is a ESP32 Lolin32 Lite using a CH340 chip for serial communication: https://www.makershop.de/plattformen/arduino/esp32-lolin32-lite/

Upvotes: 2

Views: 1972

Answers (1)

Pat Niemeyer
Pat Niemeyer

Reputation: 6408

I had a similar issue where I seemed to be getting garbage upon connect and this was causing problems using ampy to work with files on the board. It turned out to be the bootloader "message" that for this particular board apparently is printed on each reset. (I was just catching the last part of it on connect.) In my case I worked around the issue using the provided -d delay switch on ampy to just wait a second until it had passed / stabilized.

Upvotes: 1

Related Questions