Establishing Mavlink-connection between Arduino and Pixhawk

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.

Hi, thanks for the simple explanation, how do I implement that code you have provided to see if I get a heartbeat?

Hello , I am working on a project that consists of sending a vehicle( with Pixhawk 4 mini) position data via telemetry to another vehicle (with another pixhawk on board) , without having a Ground Control Station (GCS) in the loop and using the ardupilot software. I have read through the mavlink developer guide , generated the header files in C++ . The main issue i am facing is that I do not understand how to read data from a serial port in ardupilot. I have tried using the AP_HAL library UART sketches to read data from the port but i have not succeeded yet. Any advice regarding how to proceed is appreciated. Also I have two other questions:

  1. Is it possible to send and receive (including decoding) mavlink messages between two pixhawks without using any GCS software?
    2.If so, in order to do so , are the pixhawks enough or is a companion computer mandatory?
    Thank you for your time !