Communicating with Raspberry Pi via MAVLink


#1

Can someone provide a detailed step by step guide on how to setup connection between Raspberry Pi and Pixhawk using MAVLink?

I have not been using APSync (I have used the lite OS version for RPi). I followed the steps in https://ardupilot.org/dev/docs/raspberry-pi-via-mavlink.html but no success.


#2

Hi Elis! To let us better help you, can you specify how far you’ve gotten in the process? What have you tried so far?


#3

Sure. I’m using Raspberry Pi 4 B Computer and Pixhawk 2.4.8.

  1. Hardware connection was done as in https://ardupilot.org/dev/docs/raspberry-pi-via-mavlink.html

  2. Then I connected Pixhawk to computer via micro USB cable. I connected via telemetry modules to write the following parameters:
    On Mission Planner / Config / Full Parameter Tree:

  • [SERIAL2_PROTOCOL] = 2 (the default) to enable MAVLink 2 on the serial port.
  • [SERIAL2_BAUD] = 921 so the flight controller can communicate with the RPi at 921600 baud.
  1. I SSHed into RPi and enabled UART port in RPi:
  • sudo raspi-config
  • Interface options change
  1. Run the following commands in RPi terminal to set up MAVProxy:
  • sudo apt-get install python-pip.
  • sudo apt-get install libxml2-dev.
  • sudo apt-get install libxslt-dev.
  • pip install dronekit.
  • pip install dronekit-sitl.
  • pip install MAVProxy.
  • PATH=sPATH:/home/pi/.local/bin
  1. Enter the command to establish communication:
    mavproxy.py --master=/dev/serial0 --baudrate 921600 --aircraft MyCopter

This is the output.
Connect /dev/serial0 source_system=255
Failed to load module: No module named terrain. Use ‘set moddebug 3’ in the MAVProxy console to enable traceback
no script MyCopter/mavinit.scr
Log Directory: MyCopter/logs/2021-03-10/flight2
Telemetry log: MyCopter/logs/2021-03-10/flight2/flight.tlog
Waiting for heartbeat from /dev/serial0
MAV> link 1 down

I am stuck on this step. Any help would be appreciated. Thank you.


#4

Hi there Elis!

I was just in the process of replying to your first email, but after reading your second email I think I know the issue.

It appears some versions of MAVProxy will not work without opencv being installed- weird I know.

Try the following from the raspberry pi:

“sudo apt-get install python-opencv”

Then try connecting via Mavproxy again.

If that doesn’t work we can go through a check list of potential causes.


#5

Hi Caleb!

First, I did the following just to make sure RPi was updated:

  • sudo apt-get install update
  • sudo apt-get install upgrade

Then: sudo apt-get install python-opencv

Setting up python-opencv (3.2.0+dfsg-6) …
Processing triggers for libgdk-pixbuf2.0-0:armhf (2.38.1+dfsg-1) …
Processing triggers for libc-bin (2.28-10+rpi1) …

I tried again the main command and I get the following:

pi@raspberrypi:~ $ mavproxy.py --master=/dev/serial0 --baudrate 921600 --aircraft MyCopter
Connect /dev/serial0 source_system=255
no script MyCopter/mavinit.scr
Log Directory: MyCopter/logs/2021-03-10/flight3
Telemetry log: MyCopter/logs/2021-03-10/flight3/flight.tlog
Waiting for heartbeat from /dev/serial0
MAV> link 1 down

It is still giving the same output. I don’t get any parameters from the drone.


101 odd behaviours - maybe interrelated
#6

Hi there Elis!

The steps you’ve outlined may work, but it appears they diverge a bit in places (either different routes to achieve the same means, or missing some steps (like disabling bluetooth)).

I would check out this video starting at around minute 10.

This is a freemium video I posted to youtube, but contains all the steps required to establish a connection between RPI and Pixhawk.

Hope this helps


#7

Hi Caleb!

I followed all the steps (upt to minute 27) and checked everything for a second time but I keep getting the same output.

pi@raspberrypi:~ $ mavproxy.py --master=/dev/ttyAMA0
Connect /dev/ttyAMA0 source_system=255
Log Directory:
Telemetry log: mav.tlog
Waiting for heartbeat from /dev/ttyAMA0
MAV> link 1 down


#8

Hey Elis

It may be a simple thing, but did you confirm wiring is Rx>Tx and Tx>Rx ?


#9

Hey Jack,

Please look at the following pictures:
https://drive.google.com/file/d/1KaxEiTlYbQB23Rj4QmPckbT_2p6E9tA-/view?usp=sharing, https://drive.google.com/file/d/1R2UvZ6OtwSnaCbBMU08Mu9m8UjUWeLE5/view?usp=sharing, https://drive.google.com/file/d/1Xa4IUJZxZqjbNAHCitIJxn4PBfrwU0Ia/view?usp=sharing

I even tried exchanging the blue and white wire spots but I still get the annoying “link 1 down” message on RPi terminal. I’m not sure what’s going wrong.


#11

Hmm, odd.

  1. New versions of software introducing issues?
    What version of ArduCopter are you using?
    What version of MAVProxy and pymavlink are you using?

You can check the latter by typing

sudo pip freeze | grep -i mav

May be worth it to try downgrading to older versions, say ArduCopter 4.0.3 and MAVproxy 1.8.16 or 17

  1. Did you deactivate bluetooth in /boot/config.txt?
  2. Did you enable serial over the hardware port via rasp-config (outlined as a step in the video, if you likely did if you followed the steps).
  3. Can you connect the drone to your computer via telemetry? If not, this could be a firmware issue with ArduPilot and not a GroundControlStation problem with MAVProxy.
  4. Is the Pixhawk receiving power when the drone is powered on? (flashing lights on pixhawk)
  5. Can you confirm the presence of /dev/ttyAMA0 by typing “ls /dev | grep ttyAMA0”? Wondering if the device is present or under a different name.
  6. Specify different baud rates, try 57600 and 115200. Could be that the chosen baud rate of 921600 is won’t work.

Hard to say what the issue is with so many variables, but my bet is on either 1 or 2 or 7. I think I have experienced issues in the past where newer versions and incorrect baud rate corrupted connectivity.


#12

Elis your wiring looks correct.

I experimented with different baud rates, and found I could reproduce this issue (ie, link 1 down) at baud=921600.

So this worked for me: mavproxy.py --master=/dev/ttyAMA0 --baud 115200


#13

Hey guys, after 3 days of desperate results I finally got it working!

Caleb, I formatted the SD cards and followed your steps from the YouTube video in detail (meaning same software versions you used: 4.0.5 Ardupilot firmware, 2020 RPi OS Lite version).

Jack, thank you for pointing out the baudrate. I think this was the issue. I tried multiple buadrates starting from 1200 and unexpectedly it worked with 921600 this time.

This was a critical step in my project so thank you again for your directions.


#14

Sometimes you gotta reboot. ; )


#15

Hi…the flight regulator will react to MAVLink orders got through Telemetry 1 and Telemetry 2 ports (see picture at top of this page) implying that both the RPi and the normal ground station (for example Mission organizer, and so forth) can be associated. Likewise it is feasible to associate the Mission Planner to the MAVProxy application running on the RPi like how it is accomplished for SITL.

pcb online


#16

@jax200 10 points
@caleberg 5 points


closed #17