Minimal MAVLink Example Code

QGroundControl is an open-source "ground control station" for uncrewed aerial vehicles. It's an all-in-one center for display of live-streaming inbound UDP video, attractive display of vehicle telemetry, and manual joystick remote control. It communicates with the vehicle controller using the open MAVLink protocol.

I <3 quaternions

I find MAVLink attractive for simple embedded systems since libraries for C are readily avaiable and easy to use on the microcontroller end. Though it's specialized for autonomous aerial vehicle control, QGroundControl has been adapted to a lot of other contexts, and seemed like a good option for a project I'm working on.

I got it working, but had a hard time finding clear documentation or a minimal example of the specific messages exchanged during a MAVLink "connection" between a vehicle and QGroundControl to connect if you aren't using a complicated autopilot framework. For many applications, one of the off-the-shelf autopilot solutions like Ardupilot or PX4 is an appropriate choice.

If you've already got significant firmware and software developed for your project, though, it can make a lot more sense to incorporate MAVLink into your system. So I decided to develop a simple standalone example of an Arduino sketch that will connect to QGroundControl:

Once the connection is made, if virtual joysticks are enabled in QGroundControl or a physical game controller is connected, the embedded code will loop back the control messages. I wanted to provide an example that does not require any external hardware besides the target microcontroller, and the built-in virtual joysticks in QGC enable this. See the GitHub page for more detailed instructions about how to use the code.

Site generator

Manual control message loopback demonstration