1
votes

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/

1
it should be the boot log at 1152200 baudJuraj
Try add while(Serial.available()); after Serial.begin(500000);.hcheung
@hcheung Serial.available() simply returns the number of bytes available for reading. It does not consume input. I fail to see how this would help here. Please explain.phdoerfler
@Juraj this does change the garbage to a lot of "␀␀␀␀␀" eventually ending in a "�", or in hex: efbfbd, followed by a repeating e29080 and eventually ending in efbfbd again. Why is that?phdoerfler
@hcheung I did try your suggestion but as expected it had no visible effect. To me this suggests there is no data available for reading. If there was this would be an endless loop.phdoerfler

1 Answers

1
votes

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.