0

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

enter image description here

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

Jack Walton
  • 181
  • 11
  • This can be HW problem. What is the serial link, 5V TLL or RS-232? What is length of USB section and what is the length of serial link? What cables do you use? You can try loopback connection on both serial link ends (just connect RX and TX) and check from both devices... – Roman Pavelka Jul 05 '21 at 19:15
  • RS-232, The USB section 25cm the serial link 20cm. The cables are a short micro-USB data cable and a handful of short breadboard wires with Dupont connectors on. Loop back on both devices is fine. – Jack Walton Jul 06 '21 at 16:21
  • Do you have a good ground connection in addition to *"pins 8 and 10"*? – sawdust Jul 06 '21 at 19:11
  • yes its grounded to the Jetson – Jack Walton Jul 06 '21 at 19:51
  • "yes its grounded to the Jetson" GND pin definitely should be connected on both sides, and shield as well: https://www.emcstandards.co.uk/cable-shield-grounded-at-one-end-only Isn't this it? – Roman Pavelka Jul 06 '21 at 23:27
  • Instead of this tedious piecemeal description, you need to provide a complete description of the connections and ports at both ends of the serial link. FYI a successful loopback tends to indicate that the problem is a connection issue or incompatible line setting or baudrate, since the TX and RX of a serial port share the exact same ground, voltage levels & polarity, line settings, and clocks. **Are you confusing RS-232 ports with serial (UART) TTL ports, or 3.3V with 5V TTL?** You claim to be using RS-232, but neither Nvidia Jetson Nano or ESP8266 come standard with RS-232 ports! – sawdust Jul 07 '21 at 07:50
  • Apologies I am no electrical engineer I'm trying to resolve this issue and get back to the software as soon as possible. It is not using RS-232 my mistake, this is something someone has quoted to me incorrectly and caused confusion. I'm attempting to provide all information I know and understand about the issue. I am using the standard serial UART ports on 8 and 10 on the Jetson. See the J6 Header here https://developer.nvidia.com/embedded/learn/jetson-nano-2gb-devkit-user-guide. All gpio pins on the Jetson are at 3.3V. The serial converter as stated uses C340G chip into a micro-usb lead – Jack Walton Jul 07 '21 at 10:33
  • On the software side both devices are setup using an identical library and settings however I have no method of checking whether the Jetson is really transmitting at the Buad rate it claims to be. Would the fact that the error is only in one direction suggest a clock error on the Jetson? – Jack Walton Jul 07 '21 at 10:35
  • Apologies Roman that article means very little to me – Jack Walton Jul 07 '21 at 10:35

1 Answers1

1

Unfortunatly this problem is caused by unreliabilities in the UART TX pin of the 40 Pin header on the Jetson Nano's carrier board. This causes unreliable transmission to a wide range of devices, I have personally found this with CH340G USB-tty, ESP8266 and RP2040 chips. While it was compatible with a Raspberry Pi Zero W.

There is no well documented solution (that I could find) but the common work around appears to be to use an FTDI usb to serial converter to turn one of the Jetson's USB ports into a serial header. (Although as my jetson's usb ports are already in use I will be switching my microcontroller for a dedicated PWM Controller over I2C to escape thos uart nightmare)

Apologies for anyone who later finds this with a similar problem, I know the frustration of only finding a work around. For more information below is what appears to be the main thread of a few on the official Nvidia Developer Forums regarding this issue;

https://forums.developer.nvidia.com/t/unreliable-serial-communcation-via-the-uart-tx-rx-gpio-pins/158249/30

Jack Walton
  • 181
  • 11