Communicating with Raspberry Pi via MAVLink

Communicating with Raspberry Pi via MAVLink Main - Communicating with Raspberry Pi via MAVLink

Communicating with Raspberry Pi via MAVLink

Communicating with Raspberry Pi via MAVLink

This page explains how to connect and configure a Raspberry Pi (RPi) so that it is able to communicate with a flight controller using the MAVLink protocol over a serial connection. This can be used to perform additional tasks such as image recognition which simply cannot be done by the flight controller due to the memory requirements for storing images.For other drone accessories, please go here.

Connecting the Flight controller and RPi Hardware

RaspberryPi Pixhawk wiring1 - Communicating with Raspberry Pi via MAVLinkConnect the flight controller’s TELEM2 port to the RPi’s Ground, TX and RX pins as shown in the image above. More details on the individual RPi’s pin functions can be found here. The RPi can be powered by connecting +5V source to the +5V pin or from USB in. Addon boards such as the Pi-Connect can simplify the connection of the RPi by providing a power supply and telemetry port.

Tip:Depending on the model of RPi used and internal/external peripherals used, +5V power requirements can vary from 80mA to close to 2.5A. The power budget for the particular system configuration should be assessed to determine the requirements for the +5V supply current. It is usually not recommended that +5v be supplied via the flight controller’s TELEM port connector.

 

Setting up the flight controller

Connect to the flight controller with a ground station (i.e. Mission Planner) and set the following parameters:
  • 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.
  • LOG_BACKEND_TYPE = 3 if you are using APSync to stream the dataflash log files to the RPi

Configure the serial port (UART)

If not already configured, the Raspberry Pi’s serial port (UART) will need to be enabled. Use the Raspberry Pi configuration utility for this. Type:
sudo raspi-config
And in the utility, select “Interfacing Options”:

RaspberryPi Serial1 - Communicating with Raspberry Pi via MAVLinkRasPiConfiguration Utility

And then “Serial”:
RaspberryPi Serial2 - Communicating with Raspberry Pi via MAVLink
When prompted, select to “Would you like a login shell to be accessible over serial?”.no When prompted, select to “Would you like the serial port hardware to be enabled?”.yes Reboot the Raspberry Pi when you are done. The Raspberry Pi’s serial port will now be usable on ./dev/serial0

Configure the Wifi

If desired, the Raspberry Pi’s Wifi can be configured to create a Wifi access point. This will allow other clients to connect to the RPi and stream telemetry. See the official RPi documentation for details.

Tip:The built-in Wifi on the Raspberry Pi does not have a large range. If range is an issue, consider a USB Wifi adapter with external antenna.

Setup the RPi Software

There are a few different software options for communicating with the flight controller. All use the MAVLink protocol for communication.

APSync

The easiest way to setup the RPi is to flash one of the existing APSync images:
  • Purchase a formatted 8GB or 16GB SD card (16GB is better because some 8GB cards will not be quite large enough to fit the image) and insert into your laptop/desktop computer’s SD card slot

  • Download the latest image from firmware.ardupilot.org. Look for the file starting with “apsync-rpi”.

  • Use the Etcher software to load the image onto the micro SD card.

  • Insert the micro SD card into into the Pi’s micro SD card slot

    Note:There is a more recent APSync build for the RPi in the forums.

The APSync image will have the serial port (UART) already enabled.

MAVProxy

MAVProxy can be used to send commands to the flight controller from the Pi. It can also be used to route telemetry to other network endpoints. This assumes you have a SSH connection to the Pi. If not, see see the the RPi Documentation. See the MAVProxy Documentation for install instructions To test the RPi and flight controller are able to communicate with each other first ensure the RPi and flight controller are powered, then in a console on the RPi type:
python3 mavproxy.py --master=/dev/serial0 --baudrate 921600 --aircraft MyCopter
Once MAVProxy has started you should be able to type in the following command to display the parameters valueARMING_CHECK
param show ARMING_CHECK
param set ARMING_CHECK 0
arm throttle
RaspberryPi ArmTestThroughPutty - Communicating with Raspberry Pi via MAVLink

Note:If you get an error about not being able to find log files or if this example otherwise doesn’t run properly, make sure that you haven’t accidentally assigned these files to another username, such as Root.

DroneKit

The most up-to-date instructions for Installing DroneKit on Linux are in the DroneKit-Python documentation.

Rpanion-server

Rpanion-server is a web-based GUI for configuring flight controller telemetry, logging, video streaming and network configuration. Installation is via a disk image:
  • Purchase a formatted 8GB (or larger) micro SD card and insert into your laptop/desktop computer’s SD card slot
  • Download the latest image.
  • Use the Etcher software to load the image onto the micro SD card.
  • Insert the micro SD card into into the Pi’s micro SD card slot
The Rpanion-server image will have the serial port (UART) already enabled.
 

Connecting with the Mission Planner

The flight controller will respond to MAVLink commands received through Telemetry 1 and Telemetry 2 ports (see image at top of this page) meaning that both the RPi and the regular ground station (i.e. Mission planner, etc) can be connected. In addition it is possible to connect the Mission Planner to the MAVProxy application running on the RPi similar to how it is done for SITL. Primarily this means adding an to the MAVProxy startup command with the being the address of the PC running the mission planner. On windows the can be used to determine that IP address. On the computer used to write this wiki page the MAVProxy command became:--out <ipaddress>:14550ipconfig
mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --out 192.168.137.1:14550 --aircraft MyCopter
Connecting with the mission planner is shown below: RaspberryPi MissionPlanner - Communicating with Raspberry Pi via MAVLinkThis tutorial is selected from Ardupilot.

Comments

0 Comments Add comment

Leave a comment