Servers by jDrones

Establishing Mavlink-connection between Arduino and Pixhawk


I try to explain it to you as meanwhile, I managed to communicate with my Pixhawk from Arduino.

At first, visit and follow the instructions below. You need python to generate the header-files. It may seems a little bit tricky, but if you follow every step you should manage to launch the GUI.

Seccond, generate the headerfile you need in the language you use. In my case it was C, as I’m using the Arduino.
Next, it should have generated the header-files you need.

In my case I set up a new Arduino - Codefile and included:

Arduino\libraries\mavlink\mavlink_types.h and Arduino\libraries\mavlink\common\mavlink.h
(I don’t know if both are required, but it works for me)

I connected my Pixhawk TELEM2 Port with my Arduino Serial Port (RX/TX). In addition, I’ve used a common ground, so I connected the TELME2 - GND with Arduino GND.

Pixhawk continiously sends a heartbeat so this is how you can check the connection.
To simply receive this message, you have to implement the code like this:

mavlink_message_t msg;
mavlink_status_t status;
while(Serial.available() > 0){
uint8_t c =;
//Do something with the received message

msg now contains your received message. With msg.imsgid you can read out the mavlink-ID of the message for example.

You now should receive some messages from your Pixhawk and can extend your program to send or receive as you need.

Thanks for the reply. There is a difference here I want to have mavlink connection between arduino and pixhawk over Telemetry radio. In my project I want to send mocap data to pixhawk over mavlink. my connection is following .

  1. ski telemetry radio(Air) connected on pixhawk – TELEM1
  2. ski telemetry radio(Ground) is connected to laptop — COM8
  3. Qgroundcontrol is connected to pixhawk using ski radio.
  4. Arduino is connected to laptop – COM3
  5. Serial connection between qgroundcontrol and COM3.

I use Nexonar infrared mocap system which gives me coordinates of my drone in my laptop. I want to send this mocap data to pixhawk. I am new to the drone community, I am not sure whether it is feasible to do with Arduino or not.

I don’t know if its possible to let QGroundControl bypass/forward a MAVLink message. But why do you need QGC at all? You can attach the SKI telemetry directly to your Arduino and build your MAVLink messages there.

If you need these information as well on your laptop then you can also connect the Arduino to your laptop.

What is the Nexonar providing? Is there already a MAVLink message for these information that ArduCopter can handle? If not, then you have to implement one at first. But I suggest you start with the heartbeat. And regarding my answer: there’s no difference weather you connect your Arduino via wire or wireless to the Pixhawk.

Hey im also working on that Project ( together with b-rohit)

Nexonar is providing the Position Information from the drone ( its a Motion Capture System) .
We want to use the internal GPS Mode from Pixhawk to fill in our Position Data manually . ( Pixhawk already has a System with a different Motion Capture System) (

We were always thinking that we need that connection between QGround and Drone to get Mavlink working , but if thats not necessary than we will try your solution .

We will post more information later on .

edit: Why do we even need an arduino Device? Couldnt we just get acces to the drone directly via our Laptop?

Thanks for you help.


We are using those Telemtry radios (3dr) . We dont have much experience with souldering so can we just put it on a deivce like that .

or maybe directly with a UART to Female USB converter? (


atx80 Did you get your arduino to read data from the pixhawk. I have been trying to do a similar thing but with no luck

Hi David,

sorry for the late response.

Yeah, I managed to read out the heartbeat-message and decode it (Autopilot-Type, Frame-Type etc). But I only was able to read it out with the new build Mavlink-libraries. You can create them if you follow the steps on the github-page ( or in my post a little higher on this page.

With other libraries I wasn’t able to decode a valid message, even though my Pixhawk was sending something.


I discovered this with the libraries I was using as the Arduino was running out of memory. I did see this GitHub link but I had no clue how to make the library. Would you be willing to share a library and a bit of sample code to get me started.


Hi David,

I hope this doesn’t cause any trouble providing the generated code but I guess as its free to use for everyone, it should work. (388.9 KB)

I provided some example code some posts above here. Another example to lean on is posted here:

@atx80 Thanks for the file I will give it a try over the next few days. My ultimate goal is to get this working on a nano to extract flight mode and hopefully gps lat and long

Very happy got it working can now receive Mavlink Messages. Has anyone any tips on reducing the amount of memory used 83% will make a nano unstable


David Ardis

You can restrict the maximum package size with this parameter in mavlink_types.h:

// it is possible to override this, but be careful! Defa_
#define **MAVLINK_MAX_PAYLOAD_LEN 255 ///< Maximum payload length_

Thanks for your help I have managed to decode most of the messages I need and still have memory left.

@atx80 I have setup the connection and able to receive packets from pixhawk. I am not using Arduino instead I used Processing sketch to read and write on COM port.
further I want to send external position mocap data to pixhwak.
after some research on internet I found that ATT_POS_MOCAP command can be used send mocap data to pixhawk. I have following question regarding it >

  1. Do I need to convert the coordinates to NED before sending it to pixhawk.
  2. here this article mentions to set ATT_EXT_HDG_M parameter in QGroundcontrol, but I don’t find this in QGC.
  3. what should be the value of time_usec in ATT_POS_MOCAP packet.
  4. I am not sure whether I am using the correct framework. all the places I find mavros plugin, vicon_position_estimate or vision_position_estimate.I am using mavlink java library, my function to send mocap data is
  5. I am checking local_position_ned packet to check x,y,z, after sending ATT_POS_MOCAP packet, which always gives zeros for x,y,z. how can I know that my att_pos_mocap packet is received or rejected

I need help with my project- the aim is to develop an obstacle avoidance controller on Arduino (on-board) and communicate with the Pixhawk through MAVlink on TELEM2 port to send high-level commands to roll/pitch/yaw/thrust. I do not understand how the Pixhawk can read the arduino MAVlink commands through TELEM2 while it’s is simultaneously receiving commands from ground station on TELEM1.
How can I proceed with this project?


1 Like

Hi @atx80,
I have trouble the samet
If you fixed it, please help me.
I using Esp8266 ( for telemetry) and wiring to Telem 1. It working.
And using Arduino Nano ( with 5 Ultrasonic ) wiring to Telem 2. ( the both : baud rate 57600)
The 1st time connect with Mission planner, It working. So the 2nd and more it notice error when counting the second 28s, 27s, …
After , notice : “only one headbeat receive”.

And my config here :
I’m newbie and know a litte of code.
I just follow instruction of Mr. Shao fu hu wu
Drone Collision Avoidance System
Please help me with many thanks.
Arduino Nano code attached. (3.4 KB)

Some body know it, Please help

Bro I also have the same problem . Can you help me with it

Bro even I’m having the same problem. If u found a solution could you pls pls pls pls pls help me. Pls contact me in WhatsApp bro. My number- 7204739166. Thanks in advance.

It seems that is now a dead link.
Is there an other way to access this tutorial ?

hi, you should use the guide written by Juan Pedro López at this link:
(MAVLink and Arduino: step by step)

i used it and it works perfectly to connect arduino and mavlink.

Servers by jDrones