I was looking for an easy to implement solution to control my RC Airplane (that is using a ESP32 micro controller) with the help of a Mobile Application. I decided to use QGroundControl which is based on Mavlink.

My project provides the following features:

  • It is available as Arduino Library (which should work on any architecture)
  • you can easily overwrite any method if you desire a different behavoir
  • A simple extendable parameter store is provided, so that you can access the parameter values
  • There are examples for Bluetooth, TCP/IP and UDP (for the ESP32)

My code is heavily relying on Dan Zimmermans Barebones_MAVLink work. So many thinks to him!

Bluetooth Example

Here is a simple demo that shows how to use it on a ESP32 with Bluetooth:

#include "SimpleMavlinkDrone.h" #include "BluetoothSerial.h" BluetoothSerial SerialBT; SimpleMavlinkDrone Drone(&SerialBT); void setup() { // setup log Serial.begin(115200); SerialBT.begin("Airplane"); //Bluetooth device name // provide some initial optional values Drone.setValue(GPS_LATITUDE, 46.211236); Drone.setValue(GPS_LONGITUDE, 7.259520); Drone.setValue(GPS_ALTITUDE, 503); Drone.setValue(VOLTAGE_BATTERY_MV, 5000.0); // report 5V } void loop() { Drone.setValue(RECEIVER_RSSI, WiFi.RSSI()); Drone.loop(); }

This is pretty easy!

Reading Parameters

Currently the following parameter definitions are available

#define THROTTLE 0 // from 0 to 1.0
#define YAW 1 // from -100.0 to 100.0 // Rudder
#define PITCH 2 // from -100.0 to 100.0 // Elevator
#define ROLL 3 // from -100.0 to 100.0 // Aileron
#define VOLTAGE_BATTERY 4 // in milli volts
#define GPS_LATITUDE 5
#define GPS_ALTITUDE 7
#define HEADING 8 // 0 - 360 deg

You can also easily get the available parameter values by calling the getValue() method.

Serial.print(drone.isArmed()?"[Armed] ":"[Not armed] ");
Serial.print(", ");
Serial.print(", ");
Serial.print(", ");

In the documentation on Github you can find an example implementation of a simple filight controller which is updating the Servos and Motor via PWM.

Setting Up QGroundControl

  • Define the Communication Link: e.g. UDP. The IP address is displayed when you start the sketch
  • In General (Settings) in the Fly Vue Section activate the Visual Joystick
  • If you click on the ‘Airplane’ icon you can see and use the joysticks
  • Click on Arm and confirm

and now you are ready to fly!


You can download this project as ZIP and in the Arduino IDE use -> Sketch -> Include Library -> Add ZIP Library.

The recommended way howerver is to clone the project to your libraries directory. E.g. with

cd ~/Documents/Arduino/libraries
git clone https://github.com/pschatzmann/ArduinoMavlinkDrone.git

1 Comment

Allen · 15. November 2020 at 18:03

Excellent Work! Thank you very mcuh!

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *