Jack Walton
Jack Walton

Reputation: 181

Access Micropython REPL on UART(0) not USB

Background

I'm working on a robotics project that requires using an ESP8266 based board (Lolin D1 mini pro v2) as a microcontroller. I have Micropython on this board along with a set of functions that I have to be able to call from an Nvidia Jetson Nano over UART.

Setup

I have the Jetson's UART1_TXD pin wired to the D1's RX pin, and the D1's TX pin to the Jetson UART1_RXD pin. (https://developer.nvidia.com/embedded/learn/jetson-nano-2gb-devkit-user-guide#id-.JetsonNano2GBDeveloperKitUserGuidevbatuu_v1.0-40-PinHeader(J6))

On the Jetson this interface is /dev/ttyTHS1.

Using machine.UART on the D1, and pyserial on the Jetson.

Micropython version: esp8266-20210202-v1.14

Process so far

Initially I attempted to setup a simple connection between these two devices both at baud=9600 with default settings (which I check and I believe to workout the same). I ran a while True loop on the Jetson to run print(ser.readline()), ser being the serial object I had set up.

At the same time I ran a while true loop containing uart.write(b'hello world\n') on the D1. uart being the machine.UART object initialized with the above parameters.

This left the Jetson continually printing blank lines. I switched the Jetson's loop to run print(ser.read()) to read a byte at a time, to see if data was getting through at all, this gave me the same situation as before.

Micropython REPL

Since this wasn't working I'm now attempting to use a known interface on one side, the raw Micropython REPL. This is actually preferable to me as if I can directly send the REPL commands to execute I can import my Library on the microcontroller and run an arbitrary method.

The documentation is a little hazy on whether you can access the REPL directly over UART (as opposed to through the USB serial converter) however I believe it to be possible form what I have read (If it isn't, then this problem falls back to getting the original simple UART connection working).

With the above physical setup, I removed the program from the D1 which tried to use UART0 so that the REPL would be left on this port as default on boot. And using a terminal simulator on the Jetson attempted to connect to it on /dev/ttyTHS1 -b 115200.

picocom -b 115200 /dev/ttyTHS1 shows the parameters of the connection but then the prompt is blank as opposed to the >>> and wont accept any input.

rshell --port /dev/ttyTHS1 --baud 115200 waits forever on connecting.

screen /dev/ttyTHS1 115200 produces a black screen, no prompt.

I also attempted to establish a connection to /dev/ttyTHS1 and baud 115200 using pyserial and listen for some kind of response, however this gave nothing.

My Question

So my question is, if it is possible, how can I connect to the raw Micropython REPL directly over UART and send commands to the D1, and otherwise how can I establish my own connection on each side to send strings between the two devices?

This is the first time I'm attempting to use UART in this way and I am not overly familiar with micro python (I rarely venture out my IDE into the world of IoT projects) so I could be making some big oversights.

I understand this is a rather wide problem, and I wouldn't usually post something so open ended on here but I haven't been able to narrow this down and I am limited to a schedule with the project so all help would be appreciated.

Upvotes: 2

Views: 1713

Answers (1)

larsks
larsks

Reputation: 311288

So my question is, if it is possible, how can I connect to the raw Micropython REPL directly over UART and send commands to the D1, and otherwise how can I establish my own connection on each side to send strings between the two devices?

I have MicroPython (v1.14) running on a Wemos D1 mini. I'm currently using this to connect to the REPL over the UART. I didn't have to make any configuration changes to the D1 itself; the entire process was:

  1. Connect TX wire from serial adapter to RX pin on D1
  2. Connect RX wire from serial adapter to TX pin on D1
  3. Run picocom -b 115200 /dev/ttyUSB0

I was also able to get it to work by connecting directly from the TX/RX pins on a Raspberry Pi (Pi TX -> D1 RX, etc...), also using picocom (although in this case, the serial port on the Pi was /dev/ttyAMA0).


In addition to the diagnostic steps suggested by Michael Guidry, if you have any other devices available locally (another Jetson? A Raspberry Pi? Something else?) that you can use to establish a "known working" configuration (that is, a configuration in which you're able to successfully communicate using the Jetson's serial pins), that gives you a good starting point.

Upvotes: 2

Related Questions