Ardupilot and Arduino Communication

Hello everyone.

I have a project using Arduino and an Ardupilot and I need help with the communication between them.

My Arduino should receive, among other data from sensors, the compass and distance to way-point from Ardupilot. From these, it should return to the Ardupilot each motor percentage activation. I already have programmed everything in Arduino, I just can’t get it to send or receive any data from Ardupilot.

I’ve been told about i2C and UART but didn’t even knew where to start. My knowledge is mostly of mechanical engineering and software development.

Any help is appreciated.

I would ignore I2C to start with and use USART to begin with. It is simpler.

I would start by getting the ArduPilot to get some basic output to your PC via its serial port ( or USB cable which acts like a serial port) Try running one of the example sketches on your ArduPilot hardware.

You may also need to read up on Serial port protocols to set the Baud rate, parity and stop bits correctly ( Note this is done automatically by USB, but you will need to get this right for your non-usb ArduPilot to Arduino serial link)

When you have the example working then you should read up on MAVLink, the protocol that ArduPilot uses to communicate with external devices. The flavour of MAVLink that ardupilot uses can be used to get the information that you need and to send commands too:

The final part is to get your your physical link right. You need to make sure that the Serial parameters are correct as discussed above. Firstly The Physical link is not RS232. It uses either 3V or 5V logic levels. You need to check voltage levels you are using. Some hardware uses a 3 V USART logic levels, but some uses 5 V USART logic levels. The two voltage levels may work together but it is not guaranteed. For simplicity and certainty check that the Arduino hardware and ArduPilot hardware run at the same voltage either 3 V or 5 V.

For example the older APM uses 5V and the Pixhawk uses 3 V
Similarly Arduino Pro Mini are specified either as 3V or 5V parts.

EDIT. Actually the older APM boards are not officially supported any more. They can be made to work but it is more complexity. For simplicity to work with the above instructions you will need a Pixhawk or similar and then you should use a 3 V Arduino board.

Hello and thanks for the reply.

Let me see if I get this straight:
Send data through the Ardupilot’s OUTPUT ports to a PC USB port. (Is there an ideal software to read this?)
Set baud rate, parity and stop bit to work with Arduino Mega 2560 (in Mavlink?)
Receive data through Ardupilot’s INPUT ports from an Arduino 2560 using Mavlink protocol.
Send data through Ardupilot’s OUTPUT ports to an Arduino 2560 using Mavlink protocol.

Thank you again.

Hi again,
Which ArduPilot hardware do you have?

And which PC operating system do you use?

If I’m not mistaken, it’s the APM 2.6.
I have at my disposal Windows 7, windows 10 and Debian 8.
The Arduino I use is Arduino Mega 2560.

OK. Well. You presumably have Arduino IDE which has a Serial monitor in it in the Tools stab.
The APM2.6 has a USB connector. As a first step you could simply connect the APM to your PC USB port and try to get a connection. The Windows Ports are labelled COMx I think. You need to look in device manager. Plug and unplug the APM and see if what appears. In Linux try the lsusb command. It should be /dev/ttyUSB0 if you have no other usbs devices connected. If the APM has some firmware on it, when you plug in the usb cable, it should dump some random junk to your PC, but which has a few recognisable bits of text in it. That is basically sensing MAVLink interspersed with diganostic messages. I think the Baud rate is 115200 No parity 8 data bits 1 stop bit. You need to set your Arduino IDE Serial monitor to that and see if you can get some data

Awesome. I’ll try that tomorrow as soon as I get to my laboratory.
I’m used to Arduino’s Serial Monitor, so that shouldn’t be much of a hassle.
As soon as I get that from Ardupilot’s Serial I should then be able to understand how Arduino should manage that in its code.
I’ll keep you informed of my progress because the next step is the other way around: getting motor activation data to Ardupilot.


I hope you enjoyed the holidays.
I finally connected the Ardupilot to a Windows 7 PC via an USB cable.
I got the following data through the Serial port:

Init ArduRover v2.50 (3da78052)

Free RAM: 2821
load_all took 7844us
0 0 0?? ?3?Calibrating barometer?3?Warming up ADC…?3?<startup_ground> GROUND START?3 ?Beginning INS calibration; do not move vehicle?
Init Gyro*?3?Initialising APM…*?

Ready to drive.??e?!?&??(e,r?5??8?M??O’ ?R? ?Ve?R??c!?!?f2"?iJ?sJ?{?#?}9$??J??J!?%??J? ???J???’??!H(??J??J???)??P*? ???$W6????+??J??>??!?-???-??J??J??a0?J?J?$I??2?!J?+J

It goes on and on without any changes and the last characters seems garbage to me.
The baud rate was 115200bps.
Any hints on the next steps?
Thanks again in advance!

That output looks about right.

The output is being sent using mavlink protocol, which is the junk you see.

In order to understand it, you will need to read up on mavlink. There are examples about, but unfortunately not so much for Windows. Here is an example for Unix

Alternatively look at this old Arduino code that reads mavlink

Actually the example below may be simpler. Again it is unix, but it doesnt involve getting to know about git , since the mavlink files are there in the download

No problem with git, I’ve been using it for more than a year with my project.
I must honest though, I have no idea how to receive the two information I need (compass angle and distance to waypoint) from the Ardupilot and send the left and right motor activation values to it.
Could you shed me some light?

Oh, I almost forgot. I dual boot Windows and Debian, so I can run terminal commands with ease.