usb serial speed

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
iconoclastica
Posts: 14
Joined: Wed Apr 24, 2019 10:47 am

usb serial speed

Post by iconoclastica » Wed Nov 25, 2020 3:28 pm

I have a new D1 mini (which is probably an old one, as it reports version '2.2.0-dev(9422289)') to replace the lolin32-lite I had before but which got fried. It works, more or less, but the serial communication to the computer by USB picks up a lot of invalid characters. On arduinos I would lower the serial speed in such a case, but I can't find how to change this on the D1, and in microPython in general.
I am using pyboard.py as the base of my serail communications.

So, what's the equivalent of

Code: Select all

Serial.begin(57600);
in microPython?

example of damged communication result (notice the last lines):

Code: Select all

print(scanDir("/", False))
[('D1.py', '/', (32768, 0, 0, 0, 0, 0, 1556, 3348282665, 3348282665, 3348282665)), 
('boot.py', '/', (32768, 0, 0, 0, 0, 0, 848, 3348282539, 3348282539, 3348282539)), 
('communication.py', '/', (32768, 0, 0, 0, 0, 0, 9216, 3348285105, 3348285105, 3348285105)),
 ('component.py', '/', (32768, 0, 0, 0, 0, 0, 1434, 3348282564, 3348282564, 3348282564)), 
 ('fileDescriptor.py', '/', (32768, 0, 0, 0, 0, 0, 1462, 3348284507, 3348284507, 3348284507)), 
 ('mpError.py', '/', (32768, 0, 0, 0, 0, 0, 3131, 3348282612, 3348282612, 3348282612)), 
 ('mpFTP.py', '/', (32768, 0, 0, 0, 0, 0, 11664, 3348282600, 3348282600, 3348282600)), 
 ('platformSpecific.py', '/', (32768, 0, 0, 0, 0, 0, 2596, 3348282609, 3348282609, 3348282609)), 
 ('stepperMotor.py', '/', (32768, 0, 0, 0, 0, 0, 4228, 3348282611, 33221, ¦&’Â’²ŠŠJJbB:º¥™¥
½µÁ½¹•¹Ñ.py' '/', (32768, 0, 0, 0, 0, 0, 4014, 3348282613, 3348282613, 3348282613))]

User avatar
jimmo
Posts: 2072
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: usb serial speed

Post by jimmo » Wed Nov 25, 2020 11:22 pm

iconoclastica wrote:
Wed Nov 25, 2020 3:28 pm
So, what's the equivalent of
CODE: SELECT ALL

Serial.begin(57600);
in microPython?
On ESP32, I think this has to be done in firmware as UART(0) can't be accessed from Python. (Hopefully someone can correct me if I'm wrong). Unfortunately means you'll have to build the firmware from source.

I haven't tested this, but I'm fairly sure you can configure this in the IDF, via MicroPython's sdkconfig fragments.

Add

Code: Select all

CONFIG_ESP_CONSOLE_UART_BAUDRATE=57600
to ports/esp32/boards/YOURBOARD/sdkconfig.board (if using a non-generic board definition) or ports/esp32/boards/sdkconfig.base
iconoclastica wrote:
Wed Nov 25, 2020 3:28 pm
example of damged communication result (notice the last lines):
This is really weird. I'm surprised this is happening at 115200. Maybe someone else has ideas, but unless your TX/RX wires are excessively long or there's a bad connection, does seem surprising.

iconoclastica
Posts: 14
Joined: Wed Apr 24, 2019 10:47 am

Re: usb serial speed

Post by iconoclastica » Thu Nov 26, 2020 11:16 am

I have come to the belief that it is a clone board and as such a bad specimen of them. It doesn't bear any Wemos marks and the voltage regulator is a '4B2X'. Already I have ordered new ones from the official shop. I hoped to get on with my project until the new boards arrive by lowering the baud rate.

Anyway, there's nothing I can do now until I have figured out how to enter the safe mode. I screwed up the boot .py and can't contact it now, not even to reflash it.

User avatar
jimmo
Posts: 2072
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: usb serial speed

Post by jimmo » Fri Nov 27, 2020 6:27 am

iconoclastica wrote:
Thu Nov 26, 2020 11:16 am
Anyway, there's nothing I can do now until I have figured out how to enter the safe mode. I screwed up the boot .py and can't contact it now, not even to reflash it.
I assume you've seen this already, but you need to hold GPIO0 low while resetting. Then esptool.py should be able to connect to it.

iconoclastica
Posts: 14
Joined: Wed Apr 24, 2019 10:47 am

Re: usb serial speed

Post by iconoclastica » Fri Nov 27, 2020 2:46 pm

jimmo wrote:
Fri Nov 27, 2020 6:27 am
I assume you've seen this already, but you need to hold GPIO0 low while resetting. Then esptool.py should be able to connect to it.
I had found that (and a few other similar advices) and tried it, but to no avail. However, after reading your suggestion I tried it once again with a bit more confidence now, and then it did work. My best guess is that yesterday I didn't leave the connecting wire in place for subsequent boot-ups.

So, thanks, repeating the apparently obvious did help :D

Post Reply