Read rc signal from mavlink to raspberry

hi,

Could anyone help with subject as below.

What’s the easiest and most raible way to read rc signal from mavlink to raspberry?

You can use pymavlink to get the RC signal from mavlink data sent to the raspberry pi.

Messages (common) · MAVLink Developer Guide - Check this for more details

Hi,

Thanks for the replay. i have looked at these documentaction and now i have a nother problem. how to create conection in the program. i hve the connection in terminal but i want to create it in the script.

Below is the Python script that will establish a connection with the drone and prints the heartbeat message.

from pymavlink import mavutil

# Connect to the vehicle (modify the connection string as needed)

connection_string = input("Enter protocol, ip and port in this format 'tcp:192.168.2.202:20001': ") # Change this to your specific connection string

mav = mavutil.mavlink_connection(connection_string)

# Wait for the heartbeat from the drone to ensure a successful connection

mav.wait_heartbeat()

print(f"Heartbeat received, System_ID: {mav.target_system} Component_ID: {mav.target_component}")

You can refer to the page for more details.

Ok. so i’ve tried to establish the connection.in the script but received message :

File “/usr/lib/python3/dist-packages/serial/serialposix.py”, line 268, in open
raise SerialException(msg.errno, “could not open port {}: {}”.format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port : [Errno 2] No such file or directory: ‘’

That means that there is no device? MAVlink is connected to raspberry by usb cable.
Connection string :“–master=/dev/ttyACM0, baud=57600”
when i type it in terminal it works and connects.

from pymavlink import mavutil

# Connect to the vehicle (modify the port and baud rate as needed)

serial_port = input("Enter serial port in this format '/dev/ttyUSB0': ") # Change this to your specific connection string
baud_rate = int(input("Enter baud rate: "))

mav = mavutil.mavlink_connection(serial_port, baud=baud_rate)

# Wait for the heartbeat from the drone to ensure a successful connection

mav.wait_heartbeat()

print(f"Heartbeat received, System_ID: {mav.target_system} Component_ID: {mav.target_component}")

Try if this works…

Thanks for the help.

The connection is working. Now i want to read the rc channel values. So far i whose able to read all chanels using command

print(olaf.recv_match(type=‘RC_CHANNELS’, blocking=True))

the result:

RC_CHANNELS {time_boot_ms : 3978116, chancount : 8, chan1_raw : 1498, chan2_raw : 1500, chan3_raw : 899, chan4_raw : 1498, chan5_raw : 1553, chan6_raw : 1498, chan7_raw : 1498, chan8_raw : 1498, chan9_raw : 0, chan10_raw : 0, chan11_raw : 0, chan12_raw : 0, chan13_raw : 0, chan14_raw : 0, chan15_raw : 0, chan16_raw : 0, chan17_raw : 0, chan18_raw : 0, rssi : 255}

Is there a way to read individual channels? Eventually how to split show results.

Below code will split and show the results for individual channels:

rc_channels = olaf.recv_match(type='RC_CHANNELS', blocking=True)

print(f"Channel 1: {rc_channels.chan1_raw}")
print(f"Channel 2: {rc_channels.chan2_raw}")
print(f"Channel 3: {rc_channels.chan3_raw}")
print(f"Channel 4: {rc_channels.chan4_raw}")

Thank You,
i got every thing working now. Some issue with lag on servos but that’s another topic.

1 Like