Connecting Jetson Nano to Arduino Uno

So I am using the Jetson Nano to detect birds within frame of a webcam, and then moves some stepper motors so to orientate a sentry to face the bird. This works by finding the co-ordinates of the centre of the bounding box of the bird within frame, calculating stepper motor values based on the field of view and angular rotation of the stepper motors, and then relays a number of steps to the Arduino for both the x and y axes. I am trying to interface the Arduino with the Jetson Nano, and I have gotten serial working with just plugging the USB into the Jetson Nano and the other end into the Arduino Uno, but I have now made the device into one enclosed unit, and would like to switch to using i2c or UART on the Nano to connect to the Uno but have been having difficulties in getting a connection. This should just be a single way communication (from the Nano to the Uno) but can’t even seem to get that working.

Can anyone provide any insight on how to do this? Or any other tutorials that might be relevant? Thanks in advance!

1 Like

I would suggest you use the jetson nano 40 pin header to communicate with the Uno tx/rx pins. Have you checked the pin assignments of the 40 pin header with:

$ sudo /opt/nvidia/jetson-io/jetson-io.py

1 Like

here’s developer guide, Configuring the 40-Pin Expansion Header you may also check.

2 Likes

I have connected the Arduino together to the Nano. So, 5V and GND from Nano to Uno, and then TX (pin 8 on Nano) goes to RX on the Uno, and RX (pin 10 on Nano) goes to TX on the Uno. Do I have to to select a serial port to connect to?

hello ngsteven97,

you may also check the kernel init messages for all registered ports,
for example, $ dmesg | grep THS

Hey Jerry,

I have tried and it seems that there’s are the three serial ports that I can seem to use? And I’m not sure which one to use - I have the standard ttyS0, ttyTHS1 and ttyTHS2. I believe the UART on the J41 connector is linked to ttyTHS1, and I have disabled the nvgetty service, but how can I check to confirm that the communication between the Nano and the Arduino Uno is working?

Sorry in advance, still a noob at this kind of stuff!

hello ngsteven97,

please check Topic 153941, it may helps you to understand the UART mappings.

the serial data should show-up if you’d configure baud-rate correctly, Jetson platform using 115200/8n1 by default.
otherwise, you’ll see garbled logs.

To be clear on this question, the arduino Uno has only 1 serial port. It is shared with the USB port. When you use pin 0 and pin 1 for transmit and receive, it’s the same port as USB. Use serial.begin(); to start it.

See the discussion here, an arduino Mega has more serial ports:

I have given UART communication a go, and seem to be having a slight problem. Even though the COM port is defined as THS1 and not ACM0, the code only works when the USB cable is plugged into the Nano. When the USB cable is plugged in, serial communication works as intended (even though it should be using THS1 to transmit/receive data, i.e. the RX/TX GPIO pins.) When the USB cable is unplugged, the code that was previously flashed to the Arduino no longer works, and doesn’t seem to respond when serial data is sent via the RX/TX pins.

I am looking to calculate two stepper motor values to move in the x and y axes respectively within the python script, and then send these two values down the UART port to the Arduino where it will use those stepper motor values to move two NEMA17 stepper motors using the A4988 stepper motor drivers. The Arduino code also sends a signal to a relay to actuate a laser pointer. The code below is purely to get the communication working so that I can send data from the Nano to the Uno - the data should just be two numbers, so in the code I have sent “500 500” to the Nano.

Python script:

import serial

print("UART Demonstration Program")
print("NVIDIA Jetson Nano Developer Kit")


serial_port = serial.Serial(
    port="/dev/ttyTHS1",
    baudrate=115200,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
)
# Wait a second to let the port initialize
time.sleep(1)

try:
    # Send a message to the Arduino
    serial_port.write("500 500".encode())
    while True:
        if serial_port.inWaiting() > 0:
            data = serial_port.readline().decode()
            print(data)
            
except KeyboardInterrupt:
    print("Exiting Program")

except Exception as exception_error:
    print("Error occurred. Exiting Program")
    print("Error: " + str(exception_error))

finally:
    serial_port.close()
    pass

Arduino script:

int data1;
int data2;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available())
  {
    delay(10);
    data1 = Serial.readStringUntil(' ').toInt();
    data2 = Serial.readStringUntil(' ').toInt();
    delay(10);
    Serial.print("\nReceived Data:");
    Serial.print(data1, data2);
  }
}