micropython UART library and Thonny

1,309 views
Skip to first unread message

Enzo Pontone

unread,
Sep 2, 2020, 9:00:14 PM9/2/20
to thonny
Hi Aivar,
I'm trying to code a very simple serial communications between an Arduino and an ESP8266 via RX/TX pins of both boards (0/1 on Arduino and RXD0/TXD0 on ESP8266) .
I crossed TX and RX and passed them through a 5V/3.3V coverter to adapt Arduino pins voltage to ESP one.
I imported the machine.UART library and followed what is explained here: https://docs.micropython.org/en/latest/library/machine.UART.html.
Arduino send a string "0123456789" every 2 seconds.
My ESP8266 test code is quite basic:
from machine import UART
uart = UART(1, 115200)                         # init with given baudrate
# uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
try:
#     buf = bytearray(20)
#     uart.readinto(buf)
    buf = uart.read(10)
    print(buf)
except:
    print("Nothing to read!!!")
I toggled the commented and uncommented version but I always get an error:

"Could not enter REPL. Trying again with 1 second waiting time...
Could not enter REPL. Trying again with 3 second waiting time...
Could not enter REPL. Trying again with 5 second waiting time...
Could not enter REPL. Giving up."

Sometimes I need to re-flash the board firmware, too, because also when I disconnect the TX/RX cables and reset the board I get the error:

"MicroPython v1.12-388-g388d419ba on 2020-04-21; ESP module (1M) with ESP8266
Type "help()" for more information.
>>> <thonny>{'/': {'boot.py': {'size': 537, 'kind': 'file', 'time': 0}, 'main.py': {'size': 345, 'kind': 'file', 'time': 0}}}</thonny>>".

Maybe Thonny uses the TXD0/RXD0 pins for REPL interface and the connection to Arduino interferes with it?
And however do you know how I can use the machine.UART library to send receive a few bytes?
Thanks in advance for your help!

Aivar Annamaa

unread,
Sep 3, 2020, 8:29:50 AM9/3/20
to thonny
Hi!

You could try the beta of next version: https://github.com/thonny/thonny/releases/tag/v3.3.0b2

I haven't tried UART API myself, but I remember that in certain cases it conflicts with REPL and in this case Thonny can't communicate with the device.

Best regards,
Aivar

Enzo Pontone

unread,
Sep 6, 2020, 7:30:20 PM9/6/20
to thonny
Hi Aivar,
trying the new release and it seems far more stable than the previous one! Great job!
Indeed I found that UART conflicts with REPL: I'm trying some workarounds.
I'll let you know if I find a way to communicate by temporarily disabling REPL.
Reply all
Reply to author
Forward
0 new messages