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/
while(Serial.available());
afterSerial.begin(500000);
. – hcheung