UART

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
tom.ferreira
Posts: 7
Joined: Fri Jul 29, 2022 5:47 pm

Re: UART

Post by tom.ferreira » Sun Jul 31, 2022 8:15 pm

im getting <none> as response.... and it is supost to get a array...
i can figure it out

tom.ferreira
Posts: 7
Joined: Fri Jul 29, 2022 5:47 pm

Re: UART

Post by tom.ferreira » Sun Jul 31, 2022 8:23 pm

Now i get "none" again as a response. Maybe its some error in the connections i made but i don't think so:
Tx and Rx connected to the TX2 and RX2 os the esp32
The Receiver enable and Driver enable are both connected to GPIO23
vin serving as power supply to the max485 converter

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

Re: UART

Post by Roberthh » Sun Jul 31, 2022 8:26 pm

<none> means, there is no data at the moment of calling uart.read(). There may be data later, maybe never. I do not know which device you like to control, and from a distance I can hardly tell you more.

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

Re: UART

Post by Roberthh » Mon Aug 01, 2022 6:10 am

So you're using a RS485 connection, which explains the sleep(1) in the code. But sleep(1) may be too long. You have to switch the direction immediately after sending. At 9600, sending 1 byte takes about 1 ms.So the sleep time would be roughly:

utime.sleep_ms(len(hex) + 1)

or whatever msg you send. Or if the value of the baudrate is in the variable baud, you could estimate the sleep time as:

sleep_time_ms = len(msg) * 1_000 * 10 // baud + 1

You may have to align the sleep time a little bit. For actions like these a low cost logic analyzer (~12 USD) is extremely valuable. It#s almost impossible to get the timing right without being able to measure the timing.
Sample links for the logic analyzer, to explain, what I mean:
https://www.amazon.com/-/de/dp/B07KW445 ... 73&sr=8-13
As software for the logic analyzer, you can use Saleae Logic or Pulseview.

Post Reply