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
Connecting the Flight controller and RPi Hardware
Connect 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
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.
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.
Setup the RPi (Manual)
This section shows how to configure the RPi as a minimal server to read
and route telemetry from the autopilot. It does not install the full
Install the required packages on the Raspberry Pi
After the internet connection is confirmed to be working install these
sudo apt-get update #Update the list of packages in the software center
sudo apt-get install python3-dev python3-opencv python3-wxgtk3.0 libxml2-dev python3-pip python3-matplotlib python3-lxml
sudo pip3 install future
sudo pip3 install pymavlink
sudo pip3 install mavproxy
Configure the serial port (UART)
Use the Raspberry Pi configuration utility for this.
And in the utility, select “Interfacing Options”:
And then “Serial”:
When prompted, select
no to “Would you like a login shell to be accessible over serial?”.
When prompted, select
yes to “Would you like the serial port hardware to be enabled?”.
Reboot the Raspberry Pi when you are done.
The Raspberry Pi’s serial port will now be usable on
Testing the connection
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
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
ARMING_CHECK parameters value
param show ARMING_CHECK
param set ARMING_CHECK 0
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
Entering the following at the Linux command line will ensure that all
files belong to the standard Pi login account:
sudo chown -R pi /home/pi
Mavlink-router is used to route telemetry between the RPi’s serial port
and any network endpoints. See the documentation
for install and running instructions.
After installing, edit the mavlink-router config file’s (
UART section to:
Device = /dev/serial0
Baud = 921600
Configuring the Pi as a Wifi Access Point
To configure the RPi to stream telemetry over it’s own
Wifi network, see the official RPi documention
If not already present, you will also need to add an additional
UDP endpoint to the mavlink-router config file (
Mode = eavesdropping
Address = 0.0.0.0
Port = 14550
PortLock = 0
Installing DroneKit on RPi
The most up-to-date instructions for Installing DroneKit on Linux are in the DroneKit-Python documentation.
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
--out <ipaddress>:14550 to the
MAVProxy startup command with the being the address of the PC running
the mission planner. On windows the
ipconfig can be used to
determine that IP address. On the computer used to write this wiki page
the MAVProxy command became:
mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --out 192.168.137.1:14550 --aircraft MyCopter
Connecting with the mission planner is shown below: