As part of a robotics project I have to communicate between an Nvidia Jetson Nano 2Gb and a ESP8266 device running Micropython, being used as a motor controller, using their UART interfaces. Allowing me to send command strings from the Jetson to the ESP.
For testing purposes I'm using a CH340G UART to Serial converter to allow me to send / receive from my laptop also. I'm using the UART1 RX and TX pins on the Jetson (Pins 8 and 10) for 3.3V TTL, the ground on the UART side of the serial converter is connected to ground on the Jetson.
I am able to receive messages from the ESP or my laptop successfully on the Jetson with few to no corrupted characters however when I attempt to transmit "Hello World" from the Jetson and receive it on my laptop all of the characters are corrupted.
Both programs are using Pyserial, the Jetson is using /dev/ttyTHS1 on pins 8 and 10.
Receiving On my Laptop (Windows):
import serial
import time
baud = 4800
port = "COM8"
# Defaults as serial.EIGHTBITS, serial.PARITY_NONE, parity.STOPBITS_ONE
ser = serial.Serial(port, baud)
try:
while True:
#ser.write(b'hello world\n\r')
time.sleep(0.5)
line = ser.read_all()
print(line.decode('utf-8'))
except KeyboardInterrupt:
ser.close()
b'\xeb\x8b\xab\xc1\xff\xcd\xdb\x1e_\xf9'
b'\xad_\xb1\xbd$\xf7\x8b;\xeb\xfe'
b'lm\xb6\x7f\xbc\xfd\xb9\xab\xcd\xf9\xa5}'
b'}\x7f\xf2o\xfa\xbe\xf2\x98\x8dS}\xf6\x0b\xd7O'
b'\xb6dp\xb5I\xfb\xfb\xbd(\xdf\xef\xae\xd1\xd8\xcd'
b'Z\xf1[<\xbd\xf3\xbe\x96\xfe\xfe'
b'\xd9\xb3\xf6\x83\x7f{\xf7\xd9\x9a\xfc'
b'r\xd7m\xe1]\xbd\xb9\xb7y\x96\xfe'
b'\x7f\xbf\xfc\x85}\xfdr\x7f_\xa5\xfe'
b'}\xb6\xfb\x0b_o\x17\xcb\xe0['
b'\xfc\xf1\xbf\x98\xf7\xf9\xf6\x8fR'
b'\xae\x7f\xb7\x8b}\xbf\xaf_%'
These characters wont be de-coded as they don't match utf-8
Traceback (most recent call last):
File "C:\Users\Jackr\Desktop\test-serial.py", line 16, in <module>
print(line.decode('utf-8'))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 1: invalid start byte
Just opening a serial terminal in Putty which usually allows me to view the strings coming through gives me this, showing the corrupt characters
Transmitting on the Jetson (Linux 4 Tegra, based on Ubuntu 18.04):
import serial
from time import sleep
baud = 4800
ser = serial.Serial('/dev/ttyTHS1', baud)
print(ser)
try:
While True:
ser.write('Hello World \n'.encode('utf-8')
sleep(0.5)
except KeyboardInterrupt:
print("closing...")
I've Tried:
Nvgetty is disabled on ttyTHS1
Encoding and de-coding the message in each side with UTF-8 to ensure encoding is the same.
Using a lower baud rate (4800) which did prevent corrupted characters from appearing when the Jetson was receiving, but has no effect when the Jetson is transmitting
Update
When I test looping back the TX from the Jetson into it's RX there is no corruption at all. Using the following code;
import serial
ser = serial.Serial('/dev/ttyTHS1', 9600)
ser.write(b'Hello World)
ser.flush()
print(ser.read_all())
I have also now set up a Raspberry Pi W Zero and tested sending and receiving UART directly between the UART interfaces of this device and the Jetson. The traffic is uncorrupted going in both directions.
I have also used the Pi into the serial adapter to read from the pi on my laptop and this also works fine, suggesting there may be a problem specifically between the Jetson and the serial adapter