I can't send Mavlink messages to Pixhawk from NVIDIA Jetson Nano: APIException: Timeout in initializing connection

Hi,
I am using Jetson Nano and Pixhawk. Pixhawk is connected with Jetson Nano via USB Cable, on the USB port of Jetson Nano and Micro USB port on Pixhawk. I wrote the codes using Jupyter Notebook with Python 3.8.

After typing this command:
import serial
from pymavlink import mavutil
serial_port = ‘/dev/ttyACM0’
connection = mavutil.mavlink_connection(serial_port)
I didn’t get any errors so they connected properly.

But I got an error when I wrote this command to trigger the servo motor connected to the Pixhawk via the Jetson Nano:

import time
import os
import platform
import sys
from dronekit import connect, VehicleMode,LocationGlobal,LocationGlobalRelative
from pymavlink import mavutil

############DRONEKIT#################
vehicle = connect(‘/dev/ttyACM0’,wait_ready=True)
servo=9
high=1900
low=1100
#########FUNCTIONS###########
def controlServo(servo_number,pwm_value):
msg = vehicle.message_factory.command_long_encode(
0,
0,
mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
0,
servo_number,
pwm_value,
0,
0,
0,
0,
0)
vehicle.send_mavlink(msg)

###########Example execution#####
controlServo(servo,high)
time.sleep(1)
controlServo(servo,low)
#time.sleep(1)

This was the error message:

APIException Traceback (most recent call last)
Cell In[3], line 11
7 from pymavlink import mavutil
8 #############################
9 ############DRONEKIT#################
10 # /dev/ttyTHS1 veya /dev/ttyACM0
—> 11 vehicle = connect(‘/dev/ttyACM0’,wait_ready=True)
12 servo=9
13 high=1900

File ~/newenv/lib/python3.8/site-packages/dronekit/init.py:3166, in connect(ip, _initialize, wait_ready, timeout, still_waiting_callback, still_waiting_interval, status_printer, vehicle_class, rate, baud, heartbeat_timeout, source_system, source_component, use_native)
3163 vehicle._autopilot_logger.addHandler(ErrprinterHandler(status_printer))
3165 if _initialize:
→ 3166 vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
3168 if wait_ready:
3169 if wait_ready is True:

File ~/newenv/lib/python3.8/site-packages/dronekit/init.py:2275, in Vehicle.initialize(self, rate, heartbeat_timeout)
2273 break
2274 if not self._handler._alive:
→ 2275 raise APIException(‘Timeout in initializing connection.’)
2277 # Register target_system now.
2278 self._handler.target_system = self._heartbeat_system

APIException: Timeout in initializing connection.

How can I solve this problem?
Thanks!

Hi,
There are some suggestions for UART communication in
Pixhawk connection problem with Jetson Nano: "MAV> link 1 down" output - #5 by DaneLLL

Please give it a try.

Hello there,

i just came across this question. pixhawk connection with jetson nano
Currently i am planning to interface the pixhawk flight controller with my jetson xavier nx. But i am using custom baord which has has usb3.0 port left for it. Here i wanted to ask you that, since you have mentioned that you have used usb port to micro usb cable, so did you setup any virtual com port here ? (for jetson to act it’s usb port as a serial port) ? if yes can you give some idea of how you did that?

Thank you very much in advance, respect you time.

Please check Px4 Jetson Nano Connection - Jetson & Embedded Systems / Jetson Nano - NVIDIA Developer Forums to see if can help. Thanks

You can follow the steps at this video:

But cause of you are using USB cable you need to type ‘dev/ttyACM0’ instead of ‘dev/ttyTHS1’

thank you very much