Hello guys...

I'm in a project where we put Arduino working together, and they gave me a job... Use Arduino Mega to read the Ardupilot's telemetry pins. 
I know that these pins use the MAVlink protocol and I found some tutorials talking about the use of MAVlink in Arduinos, but they are all the same code:
----------------------------------------------------------------------------------------------------------------------

#include <FastSerial.h>
#include "../mavlink/include/mavlink.h" // Mavlink interface

FastSerialPort0(Serial);

void setup() {
Serial.begin(57600);

}

void loop() {
/* The default UART header for your MCU */
    int sysid = 20; ///< ID 20 for this airplane
    int compid = MAV_COMP_ID_IMU; ///< The component sending the message is the IMU, it could be also a Linux process
    int type = MAV_TYPE_QUADROTOR; ///< This system is an airplane / fixed wing

// Define the system type, in this case an airplane
    uint8_t system_type = MAV_TYPE_FIXED_WING;
    uint8_t autopilot_type = MAV_AUTOPILOT_GENERIC;

    uint8_t system_mode = MAV_MODE_PREFLIGHT; ///< Booting up
    uint32_t custom_mode = 0; ///< Custom mode, can be defined by user/adopter
    uint8_t system_state = MAV_STATE_STANDBY; ///< System ready for flight
// Initialize the required buffers
     mavlink_message_t msg; 
     uint8_t buf[MAVLINK_MAX_PACKET_LEN];

// Pack the message
     mavlink_msg_heartbeat_pack(sysid,compid, &msg, type, autopilot_type, system_mode, custom_mode, system_state);

// Copy the message to the send buffer
     uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);

// Send the message with the standard UART send function
// uart0_send might be named differently depending on
// the individual microcontroller / library in use.
    delay(1000);
    Serial.write(buf, len);
    comm_receive();
}

void comm_receive() {

    mavlink_message_t msg;
    mavlink_status_t status;

// COMMUNICATION THROUGH EXTERNAL UART PORT (XBee serial)

    while(Serial.available() > 0 )
    {
        uint8_t c = Serial.read();
// Try to get a new message
        if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
// Handle message

        switch(msg.msgid)
        {
           case MAVLINK_MSG_ID_HEARTBEAT:
           {
// E.g. read GCS heartbeat and go into
// comm lost mode if timer times out
            }
           break;
           case MAVLINK_MSG_ID_COMMAND_LONG:
// EXECUTE ACTION
           break;
          default:
//Do nothing
           break;
        }
    }

// And get the next one
    }
}

----------------------------------------------------------------------------------------------------------
And I got the problem like the others... An error that says that I need to declare the Fastserail.h before the Arduino's serial driver... I tried using the 1.6.8 IDE, so I went to the Ardupilot's 1.0.5 IDE... So I got a lot of other problems, talking about files missing like the "Betterstream.h" but are all they there.

Did I forget something else? 

I used the Arduino.h before the Fastserial, what solved my fist problem, but created others, involving overriding virtual functions.

Have other way to use MAVlink on Arduino Mega?

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Activity