MAVLink and Arduino: step by step

Dear @jplopezll,
What is the relation between the number i got i.e. 23133199 and the sensors you mentioned above?

How do you decode the number 23133199 to the sensors name you mentioned above?

Dear @habib:

The number encodes in binary the list of sensors. You have to pass the decimal format 23133199 to binary format: 1011000001111110000001111. Now you have the list of sensors: 1 means sensor present, 0 means no sensor available. The list starts from the right side: gyro, yes; accel, yes; magentometer, yes; abs. pressure, yes; diff. pressure, no; etc.

Hope you can now follow the list by yourself :wink:

Cheers.

2 Likes

Hi @jplopezll

Your way of explanation is really cool and easily understandable. I have read this thread entirely and having some doubts, need help from everyone.

I am using your simplified code and the output on Arduino Serial Monitor is displayed as shown in the picture. My questions are,

  1. Debug msgid : 0 and 33 alone are printing, why not other numbers printing? (I know it is a dumb question, do excuse me as I am new to this Arduino & Mavlink concept)

  2. Only in Arduino, I am able to see the output on Serial Monitor, how can I check the output on Pixhawk
    [ Mission Planner ]? How to transmit data from Arduino and receive in Mission Planner?

Could someone give me some help compiling a new MAVLink library for the Arduino…I have been using the included library to decode messages and would like to compile a new library. I haven’t been able to get instructions i can understand as i am new to python

David Ardis

Hi @jplopezll

Congratulations! Amaizing thread.

I was testing several ultrasonic sensors connected to a Nano in order to stop a mission if any of the sensors detected something closer to a certain distance.

I have tested this code on Arduino UNO and the serial monitor shows this:

MAVLink starting.
Streams requested!
Streams requested!
Streams requested!

But if I restart Pixhawk I start to get this:

DEBUG msgid:33
DEBUG msgid:33
DEBUG msgid:0
DEBUG msgid:33
DEBUG msgid:33
DEBUG msgid:0
DEBUG msgid:33
DEBUG msgid:33
DEBUG msgid:0
DEBUG msgid:22
DEBUG msgid:22
DEBUG msgid:33
DEBUG msgid:33
DEBUG msgid:0

So it looks like I get messages from the Pixhawk Thanks!

The question is that using a Nano I will have a similar memory and obviously I can not, nor do I want to, implement the complete MAVLink protocol. I am only interested in sending a command, for example: MAV_CMD_NAV_LOITER_UNLIM (if this command invokes an indefinite Loiter). How could I do it without having to restart Pixhawk?

Regards

Hola, @danielhellin:

Restarting the Pixhawk should not be needed after requesting streams, looks like a strange behaviour. Please send PM (en español, si lo prefieres) and explain a bit more about your setup to try to guess what could be happening.

Saludos.

Hi, @Rajakumar:

Sorry for the delay in answering, busy days here!

  1. You are getting only messages 0 and 33 probably because you have not requested the streams you need. What is the info you are looking for? You will have to request for that specific stream in your code for the Pixhawk to start streaming it back to you.

  2. You will not see the info in Mission Planner because MAVLink is a point-to-point protocol. This means that every device has its own address. As it is the Arduino board the one asking (and indicating its address), your Pixhawk will answer to that address.

For further explanations I would need to know more about your setup and configurations.

Regards.

Hi @jplopezll,

No issues. Thanks for the reply.

We are able to decode the data in MavProxy which Pixhawk was sending to Arduino.

In ArduCopter coding, we have a command such as gcs().send_text(MAV_SEVERITY_INFO, “Hello World”); in order to print the custom message (eg. Hello World) in Mission Planner. Likewise, do we have any command or syntax to be given to Arduino to send the custom messages from Arduino to Pixhawk?

Thank you.

excuse me sir,is it possible if i use APM?

You can send statustext messages directed to the vehicles system id - it
will log them to the onboard dataflash logs but nothing more.

Peter

Hi Peter,

Thanks for your reply. Appreciated.

As I am new to this mavlink arduino interface :roll_eyes: can you please elaborate more on how to send statustext message and how it is directed to system id?

Also, I want to know how can I create a sysid & compid for Arduino.

Thank you

Hi, @fawwazichsanul98:

I think APM has good support of MAVLink. I have never worked with it, but I would say that it is perfectly possible.

Dear @Rajakumar:

Please re-read carefully the steps 4 and 5 of the post. You must write your code to implement the message you want. In your case, as you want to send information to the Pixhawk, you must first pack the message and then send it.

The functions needed are detailed in step 4 for the mav_request_data, you must adapt it to the mavlink_msg_statustext. First use:
static inline uint16_t mavlink_msg_statustext_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint8_t severity, const char *text)

And then:
static inline void mavlink_msg_statustext_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t severity, const char *text)

You can see in step 4 how to define the variables for the buffer to finaly use Serial.write(buf, len) to start the actual comms.

Hope it is clearer now.

I am having difficulty getting heartbeats from Pixhawk (Arduplane 3.9.6). I am using a modified set of minimal.xml header files from ones used to compile Arduplane 3.9.6 and a slightly modified version of the c/c++ file you posted in #94. Code can be seen at TunaLobster/ArduinoMAVLink. I am compiling for an Arduino Nano using 90% of the dynamic memory (I have a mega 2560 on the way so I will be able to use the full data output.) Serial2 is set to baud 57600 and MAVLinkv2 output. I have swapped RX and TX pins to check my sanity. I am powering from a powerbrick to a Pixhawk 2.1. I have tried 3 different Pixhawk 2.1 boards. I am not sure what else to try at this point.

Hi @TunaLobster:

Try to set your Serial2 to use v1. V2 was not working for me.

I can try to help with troubleshooting, better PM me. I will be probably needing more info on schematics and wiring.

Kind regards.

I got it working for the Mega 2560 on MAVLinkV1. Arduino code is here. Hopefully this helps others out. The Nano might just be quirky enough for it to not like it anymore. SAMD21 might be a better microcontroller for this workload.

I did not have to power the pixhawk 2.1 from a powerbrick. Just USB power.

Hi @jplopezll,

Thanks for the post to help me to set up the mavlink and Arduino.

I ended up transmitting data from pixhawk to Arduino and able to see the data output at the serial monitor. That’s a good sign for me. However, I am wondering if there is any chance for me to send command from Arduino to Pixhawk. For example, I obtain a pitch rate from my own control system and would like to send that pitch rate to the pixhawk so pixhawk can help me to fly the drone with the pitch rate I obtained from my control system.

Is that possible to do it by some ways? I would appreciate if you give me an answer on this question.

Hi @zimin:

Thanks for your kind words!

I am not fully sure, but if you read this article on mission command messages, I would dare to say that it is not possible modifying the pitch rate via MAVLink.

In my opinion, the pitch rate is something you calibrate, send to your flight controller, and then never touch again unless you modify the layout of your drone. But I do not know about your setup and maybe you need to do so.

Kind regards.

1 Like

Hi @jplopezll

Thanks for your reply. I would definitely read through the article.Also, basically, my project team is working on a gnc system which would calculate the control (rotation rate) needed for the drone to fly to a specific location. We use the pixhawk to fly the drone and hope the pixhawk would act like the manual mode whenever they receive the command generated from our gnc system. So, try to think that the taranis transmitter is our gnc system and the pixhawk will fly the drone with the input from the taranis transmitter. Same concept for our gnc system.

If you do have any recommendation, please feel free to give me your opinion. I am also thinking what if my command input change to attitude instead of attitude rate.