How to communicate Jetson Nano Developer Kit to Arduino? (Ubuntu 18.04, ROS)

Hi. I have Jetson Nano Developer Kit and Arduino Mega.
Additionally, I have LiDar, YD Robotis Corp., and a camera for Raspberry Pi, rcmbm-sy101-a.
I succeed in connecting Jetson Nano to Arduino Mega using ttyTHS1(J41) on Jetson Nano with any devices(LiDar or the camera).
I tried to connecting both using ttyTHS2(J44) but It doesn’t work at all.

Following both is my code on Jetson Nano, Ubuntu 18.04, ROS.
The difference between codes is only “port=”/dev/ttyTHS2"" lower part of the codes.

Additionally, one guy suggested to me below, and then I checked following.

‘ls-al / dev / ttyTHS *’
crw-rw ---- 1 root dialout 238, 1 2 월 16 04:24 / dev / ttyTHS1
crw-rw ---- 1 root dialout 238, 2 2 월 15 17:16 / dev / ttyTHS2

As you see, I can checked two serial communication port.

Is there any setting what I have to do or additional codes?

Thank you.
regards.


ttyTHS1(It works)

#!/usr/bin/env python

Lidar

import rospy
from sensor_msgs.msg import LaserScan
import serial

variable

#========== LiDar Spec. ============
#angle_min: -3.14159274101
#angle_max: 3.14159274101
#angle_increment: 0.0124666374177
#time_increment: 0.000199999994948
#scan_time: 0.0993999987841
#range_min: 0.10000000149
#range_max: 16.0
#===================================

m_to_cm = 100 # converse meter unit to centi-meter unit
max_detection_distance = 25.0 # Unit is “centi-meter”
min_detection_distance = 0.0 # Unit is “centi-meter”
factor = 504 # (angle_max - angle_increment) / angle_increment

Lidar main

def sift_lidar_data(data):

lidar_data_buf = []
lidar_data_buf = [0] * factor
lidar_data_buf_int = 0

for num in range(factor):
    lidar_data_buf[num] = data.ranges[num]
    
    if lidar_data_buf[num] * m_to_cm <= max_detection_distance and lidar_data_buf[num] * m_to_cm > min_detection_distance:
        print "distance [",num,"] : ",lidar_data_buf[num] * m_to_cm,"cm"

        # converse float unit to int unit
        lidar_data_buf_int = int(lidar_data_buf[num] * m_to_cm)
        print "distance [",num,"] : ",lidar_data_buf_int,"cm"

        # Serial Communication with Arduino
        serial_port.write(bytes(bytearray([lidar_data_buf_int])))

def lidar():
rospy.init_node(‘Total_yj’, anonymous=True)
rospy.Subscriber("/scan", LaserScan, sift_lidar_data)
rospy.spin()

Total main

if name == ‘main’:

serial_port = serial.Serial(
    port="/dev/ttyTHS1",
    baudrate=115200,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
)
lidar()

ttyTHS2(It doesn’t work)

#!/usr/bin/env python

Lidar

import rospy
from sensor_msgs.msg import LaserScan
import serial

variable

#========== LiDar Spec. ============
#angle_min: -3.14159274101
#angle_max: 3.14159274101
#angle_increment: 0.0124666374177
#time_increment: 0.000199999994948
#scan_time: 0.0993999987841
#range_min: 0.10000000149
#range_max: 16.0
#===================================

m_to_cm = 100 # converse meter unit to centi-meter unit
max_detection_distance = 25.0 # Unit is “centi-meter”
min_detection_distance = 0.0 # Unit is “centi-meter”
factor = 504 # (angle_max - angle_increment) / angle_increment

Lidar main

def sift_lidar_data(data):

lidar_data_buf = []
lidar_data_buf = [0] * factor
lidar_data_buf_int = 0

for num in range(factor):
    lidar_data_buf[num] = data.ranges[num]
    
    if lidar_data_buf[num] * m_to_cm <= max_detection_distance and lidar_data_buf[num] * m_to_cm > min_detection_distance:
        print "distance [",num,"] : ",lidar_data_buf[num] * m_to_cm,"cm"

        # converse float unit to int unit
        lidar_data_buf_int = int(lidar_data_buf[num] * m_to_cm)
        print "distance [",num,"] : ",lidar_data_buf_int,"cm"

        # Serial Communication with Arduino
        serial_port.write(bytes(bytearray([lidar_data_buf_int])))

def lidar():
rospy.init_node(‘Total_yj’, anonymous=True)
rospy.Subscriber("/scan", LaserScan, sift_lidar_data)
rospy.spin()

Total main

if name == ‘main’:

serial_port = serial.Serial(
    port="/dev/ttyTHS2",
    baudrate=115200,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
)
lidar()

How do I make it work.

hello 715jin,

please also update the configuration file to update the port definition. i.e. "console=ttyTHS2,115200n8
you may also refer to below threads as see-also.
thanks