Need to convert UART received data.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Need to convert UART received data.

Post by MMliam » Sat Jul 23, 2022 7:48 pm

Another curious thing, is that if I run the complete receive code (no manual REPL) I never get the complete data, in other words I never see the "Hello\r\n" at the end. I only get that if I manually execute the uart.read() in REPL. There seems to be some sort of timing issue also.

I just tried an experiment, twisting the jumpers together as in a twisted-pair; it didn't make any difference either.
BTW: The jumpers are 10cm.

How long were the interconnecting wires in your experiment, and did you use any termination?

This is the response I get with the full code; automatic read:
Receiver waiting......
81

Received Data: b'\xff\x89\x80\x80\x80\x80\x00\x80\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\xd0\xff'
Modified Code:

Code: Select all

rom machine import UART
import ubinascii

uart=UART(2, 115200, timeout=10)
print('\n'+str(uart))
print('\nReceiver waiting......')

byteCnt = 0
while byteCnt==0:
    byteCnt = uart.any()
print(byteCnt)
After manual read in REPL:
Receiver waiting......
61
MicroPython v1.19.1-espnow-6-g44f65965b on 2022-07-09; ESP32 module with ESP32
Type "help()" for more information.
>>> uart.read()
b"\xbf\x8cU\xd5d\x100\x00\x04\x00\x00\x00\x00\x08\x08\x80\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90\xbf'\x02\x00\x80\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00X\xff\x88\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\xfe%@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x10\x00\x80\xee\xff%\x04\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x08\xbe\xfd\xbf\x0b\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xfb\xbf\x03\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Hello\r\n"

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Need to convert UART received data.

Post by Roberthh » Sat Jul 23, 2022 8:02 pm

How long were the interconnecting wires in your experiment, and did you use any termination?
In the ESP32 to ESP32 test they were ~20cm long. No termination (the UART output is low impedance).
In the ESP32 to logic analyzer I used the test probes, also about 20 cm long. The Analyzer has an input impedance of ~50 kOhm.

You could try to change the pins at the Sending ESP32. Maybe there is a problem at the board / breadboard.

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Need to convert UART received data.

Post by MMliam » Sat Jul 23, 2022 8:39 pm

Looks like great minds think alike; I'm beginning to suspect the breadboard. I even tried another ESP32 for the sender; same results.
Initially I was controlling both ESP32's with two instances of Thonny running on the same PC. I ran a test using two PC's; same result.

Today I just received two bread-boards. They were supposed to be for 30 pin units, but they're for the 38pin units; figures :evil:

I'm going to try some other bread-boards. I know it's getting late by you, so I'll keep you informed.

Thanks again for your help,
Mike
New Jersey, US

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Need to convert UART received data.

Post by MMliam » Sat Jul 23, 2022 10:41 pm

Hi Robert,

Hallelujah!

I tighten-up the grounds, and that helped a little more; BUT, what worked was pin re-mapping. Re-mapped rx=5 & tx=18, and I'm running at 115200b/s. I also went back to my original breadboard. Now I can finally get on with making a gateway for my project. It's a pity micropython doesn't implement the full I2C functionality; I'd use that in a heartbeat over the UART.

However, the need to re-map the UART2 pins really doesn't make sense to me, as every pin-out diagram I can find on the boards I have, show GPIO16 to Rx (only) and GPIO17 to Tx (only); no other peripherals involved. The only thing I can think of is that there's some cross-talk on one, or both of those pins from some other on-board peripheral.

BTW: Were the units you tested 30pin, or 38pin, and were the UART pins the default rx=16 & tx=17, or did you re-map the pins?

Thanks again for your help,

Mike
NJ, US

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Need to convert UART received data.

Post by Roberthh » Sun Jul 24, 2022 6:10 am

I used break-out modules from Wemos. One was like WROOM module, without SPIRAM, with the GENERIC firmware, the other had SPIRAM and the GENERIC_SPIRAM firmware. The GENERIC device worked with the regular pin settings at Pins 16 and 17, the GENERIC_SPIRAM device with changed pins, since Pins 16 and 17 are not available at this device.

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Need to convert UART received data.

Post by MMliam » Sun Jul 24, 2022 12:36 pm

The WROOM come in different pin amounts, the most common seem to be the 30 or 38. You are not the only one to mention problems using the default pins, but most comments seem to believe there may be some conflict with the flash-memory. I'm wondering if the problems have something to do with the circuit layout of the 30 pin device, causing cross-talk. I have been using the 30 pin versions, but just receive the larger 38 pin units that includes an I-PEX connector for an external antenna. I've just flashed the latest version of micropython (1.19.1) on the 38 pin devices, and I'm going to test those units.

Your unit appears to be the LOLIN device, in the less common 32 pin format and comes with micropython already installed.

Is this your device?
https://www.wemos.cc/en/latest/d32/d32.html

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Need to convert UART received data.

Post by Roberthh » Sun Jul 24, 2022 1:02 pm

I have like 10 different ESP32 breakout boards. The Lolin32 Lite board I used for testing does not have an espressif module attached to it. It is just a single PCB, with all components soldered to it. I have built and installed the MicroPython version myself for testing.

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Need to convert UART received data.

Post by MMliam » Sun Jul 24, 2022 2:35 pm

Just ran a test on the 38 pin modules; they essentially have the same issue on the default pins. There is a slight difference; after a send, garbage is received first, the receiver loops around and gets the correct data on the second read; weird. Like the 30pin units, the 38 pin versions work well after pin re-mapping.

Something is definitely strange about the default pins on the units I have, whether 30 or 38 pin.

If I understand you correctly, your "Lolin32 Lite board" has a ESP module socket to accommodate an ESP32 module?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Need to convert UART received data.

Post by Roberthh » Sun Jul 24, 2022 3:06 pm

The Lolin32 Lite board is a ESP32 breakout board, not intended to carry espressif esp32 modules. See e.g. here: https://99tech.com.au/esp32-info/wemos- ... s-classic/. It was sold for a while for ~3 €,

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Need to convert UART received data.

Post by MMliam » Sun Jul 24, 2022 4:41 pm


Post Reply