MAVLink and Arduino: step by step

Hi @LeiroJuan:

What library have you loaded? If you are using a nano, probably you are using v1.0 of the protocol. I have tried loading v2 of MAVLink to the nano, but there is not enough flash memory as v2 has longer messages and needs more space.

To use v2 of MAVLink you will need a Mega…

Or a Teensy that offer more memory and power on a smaller footprint

Now Im thinking that this is not the best thread probably for make this cuestion.

Anyway Im trying to send this commando from a computer to an arduino Uno. Im using QGC on the labtop and it tells me that MAV_CMD_USER_1 its not supported, its strange because QGC its working with the mavlink 2.0, so i dont know how to fix it. Im studying the code of QGC now.

Thanks for your time

Hi again dear Juan
after hard trying for two days I don’t think that I’m now even one step ahead! The reason is obvious: I’m new here … Are you sure that it is so simple to compose a MAVLink message by just changing the destination address in the step 4? If it is not so difficult for you could you please indicate me the basic commands to send the message including the characters: "41.139234,24.912345,67.25;” to a buffer of Pixhawk and those to access the content of the buffer in MP?
Thanks again for your time
Also please explain the “int compid = 158;” to which component is referred?
The controlled system is a QUADROTOR or is an airplane / fixed wing?
Thanking you again

Ioannis

Why does the mavlink library not include the 3dr radio packet?

Hi, Tim. Sorry, but I do not understand your remark. MAVLink is the protocol, 3dr is the physical radio link. They are at a different OSI level.

The library is missing this file.

Where did you get the library from?

Ah! Now I get the point to your question. As you indicate, the zip file is not the complete library, it was the version of the library that worked for me at the very begining and it is enough for basic tasks and to gain selfconfidence.

I am planning to rewrite the full article to correct some errors, include some other topics and include the full v1 library. I expect I will have some time for this around August (this year)…


So in my project i want to send information from 2 sonar sensors (one in front and another at the back of UAV) to the autopilot. the schematic shows how i have connected my setup. im having the sonar sensors give its values into the arduino(A2 for front A3 for back) after which i want to use MAVLink commands (sent from the arduino Tx to the pixhawk Rx in telemetry 2 port) to either move the drone or stop it from moving. even just displaying the values at this stage would be enough. I wanted to know how to proceed. I seem to have issues trying to get anything to work together. the mavlink libraries cant be included since it doesnt exist even though i have it in the main arduino folder (C:\Program Files (x86)\Arduino\libraries) as well as the project directory (C:\Users\Dewov\Desktop\ArduMavlink\libraries). the arduino keeps showing that there is no file or directory with that name. i have tried using #include <mavlink.h> as well as #include <C:\Users\Dewov\Desktop\ArduMavlink\libraries/mavlink.h>.
I need to know how else do you get Mavlink Libraries into the arduino IDE. (importing ZIP and manually dint seem to work)
Also how do i send a MAVLink Message to the Pixhawk to make it stop? hold position or height hold.
Any help would be greatly appreciated. even if its just pointing me to other sources to read up on. (most of what ive been looking for seem to be old and outdated giving me the 404 page.)

Dear LeiroJuan,
thank you for PM to me your code! It was really useful for me.
Thanks
Ioannis

Hi, @trovesmurf:

It looks that your main problem is installing the library in the IDE. Check this link, the third section and revert in case you continue having problems.

1 Like

Hi @jplopezll,
Thanks for the suggestion! that was the issue and after a bit of trial and error. i got the libraries installed. i would like to follow up however with regards to what messages you can send through MAVLink in order to get the sensor inputs displayed on the screen constantly. at the moment i use Proximity from the Ctrl+F menu on mission planner to view the sensor inputs. example is shown below. i would like to know if there was a way of making it appear automatically or through as message i can send as a MAVLink message from the Arduino to refresh it every time it takes a sensor reading. Thank you once again.
workexample

Hi @jplopezll
I want to say thank you for this. Its the best I have seen. I have been struggling with reading mavlink messages on the Arduino. Was basically making it more complicated.

I am actually going in the opposite direction. Basically going from the Teensy 3.5 as a controller with mavlink going to a GCS (APM Planner in my guess) over 3dr clones. Sending messages from the Arduino to the GCS is working like a charm but having some challenges going from the GCS to the controller is giving me headaches.

Just by way of letting you know where I am. I updated my code to your comm receive method and that helped. Thank you for that. I am able to send waypoints from the GCS to the controller but having a two problems that maybe you can help me with:

  1. I am using a joystick as a controller as opposed to RC. I was able to disable all RC inputs and the GCS is saying its transmitting a manual control message. But I am not seeing it on the controller side. Is there some other trick to get this to work?
  2. I can’t seem to set param values from the GCS to controller? How would you do that?

Any help would be appreciated it.

Thanks
Mike

Just by way of an update got manual_control messages to work by updating the mavlink library to the latest v1. Still can not figure out how to set_param from the ground planner to the teensy.

Hi,
do you have any experience with tiva?

Hi, @iqra_imtiaz. Sorry, no experience with that…

Hello.
ı use arduplot 2.8. ı want to communicate with ardunio mega .
my schematic is here


And ı want to see this data on ardunio mega serial port.veri%20g%C3%B6r%C3%BCntleri

how can ı make this application.
please help me :slight_smile:

Hi, Selim:

As you can read in the Arduino reference, the Mega has three additional serial ports: see here. Leave Serial for the USB monitor and use any of the extra seral ports of the Mega for MAVLink communications.

Regarding what streams to request what data, please re-read the post:

Hope this helps. Kind regards.

Thank you for answer
Could you write a simple code for read only altitude . I have to hurry :frowning: .
Please help me.

@Selim this is not a simple code that you are asking here. Code needs to include MAVLink libraries and use them.

Best and fasttest way to understand what all is needed would be to take a look old MinimOSD or jD-IOBoard mavlink-frsky bridge code. On IOBoard code you can find examples how to extract mavlink messages. After you extract wanted messages, printing them additional serial port is easy.

Old code repository is here:

Not sure if that old code compiles anymore with latest MAVLink libraries but it wont be that hard to make it work again.