element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum MAVLink on Arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 3 replies
  • Subscribers 391 subscribers
  • Views 1063 views
  • Users 0 members are here
  • mavlink
  • arduino
Related

MAVLink on Arduino

Former Member
Former Member over 12 years ago

Hi all,

Having a bit of trouble getting MAVLink working on my Arduino Mega.

I can get the code from the example on qgroundcontrol to compile, upload and run, but it never manages to parse a message.

Any ideas?


Regards,

Si


Documentation: http://www.qgroundcontrol.org/dev/mavlink_onboard_integration_tutorial

My code:

#ifndef PI

# define PI 3.141592653589793f

#endif


#ifndef M_PI_2

# define M_PI_2 1.570796326794897f

#endif


#ifndef atanf

# define atanf atan

#endif


#ifndef atan2f

# define atan2f atan2

#endif


#include "C:/Users/Simon/Documents/GitHub/failsafe/libraries/mavlink/include/include/mavlink/v1.0/ardupilotmega/mavlink.h"


void communication_receive();

int packet_drops = 0;


void setup(){

  Serial.begin(57600);

  Serial1.begin(57600);

}


void loop(){

  communication_receive();

}



void communication_receive()

{

  mavlink_message_t msg;

  mavlink_status_t status;


  if(Serial1.available()) {

    Serial.print("\t\tReading some bytes: ");

    Serial.println(Serial1.available());

  }


  // COMMUNICATION THROUGH UART

  while(Serial1.available() > 0)

  {

    uint8_t c = Serial1.read();

    //Serial.print(char(c));


    // Try to get a new message

    if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {

      Serial.print("\t\t***Message received! id:");

      Serial.println(msg.msgid);


      // Handle message

      //decode(msg);

    }


    // And get the next one

  }

  // Update global packet drops counter

  packet_drops += status.packet_rx_drop_count;

}

 

Result:

Reading some bytes: 19

Reading some bytes: 7

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 2

Reading some bytes: 17

Reading some bytes: 2

Reading some bytes: 1

Reading some bytes: 2

Reading some bytes: 18


  • Sign in to reply
  • Cancel
  • shabaz
    0 shabaz over 12 years ago

    Hi Simon,

     

    I'm not familiar with this, but it looks like maybe the code is trying to read variable length messages? And it is seeing them, because it is printing the length (19, 7, 2, etc).

    You could try to print the message, to confirm it is what you expect, i.e. uncomment this line temporarily:

    //Serial.print(char(c));


    I don't know what the serial1 line is connected to, but if it is (say) a radio, then you may have some reception issues, so printing the content would help eliminate it.

     

    If the output agrees with what you expect (i.e. message content and format look correct to you), then mavlink_parse_char would need to be investigated.

    As mentioned I'm not knowledgeable on this (but it sounds interesting), so sorry if this is only helpful in a very limited manner!

     

    EDIT:

    Also, Simon, does this function exit and get called repeatedly or something? If so, then these possibly need to be defined as globals, outside the function rather than where they are currently.

    The symptom would be that the beginning of some messages may be chopped off:

    mavlink_message_t msg;

      mavlink_status_t status;

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to shabaz

    Hi shabaz,

     

    Thanks for taking the time to reply!

    Yes uncommenting the Serial.print(c) displays the message correctly, it is coming straight from an ArduPilot board (an autopilot for small UAVs) and is definitely correct as it connects to the PC through their software and an FTDI cable.

    I think the issue is with the mavlink_parse_char function too, however this is in a pre-written (and very complex) library for the communications protocol used by the autopilot so I don't want to edit it, and shouldn't need to. I thought the function saved the received bits of the message internally, however I will try puting msg & status as globals, good idea.

    Cheers,

    Si

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Hello guys, i'm facing the same problem as stated in this conversation ( i'm unable to parse the message with the code provided by mavlink generator). I was looking for a solution and then i found your conversation. So , did you guys resolve the problem and if so how did you manage to do it.

     

    Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube