No responses anymore from latest build Mavlink in Arduino

Hi all!

I had followed this tutorial on how to connect ardupilot and arduino, which worked great. I got heartbeats and I could send messages to my pixhawk 2.4.8. However, I wanted to use the GPS_INPUT command, which was not included in the old build from that tutorial of mavlink.

So I followed the mavlink instructions and downloaded the latest c mavlink build. My code compiles fine, but I no longer get any messages back from my pixhawk. Have their been changes that I’m not aware of? I can’t seem to find any the culprit myself.

Thanks!

Hi @H_Smeitink:

I cannot tell you what is the problem. What Arduino board are you using? I had memory issues with the full version of the MAVLink library, both v1 and v2. I had to reduce variables length to allow the program size to fit in the board.

Even if the library compiles fine and the program uploads, there could be overflows once in execution. Try to use a second serial interface (interface, not port, using software serial library) to echo intermediate debugging messages to the serial monitor.

Tell me more about your layout (boards, models, wiring) and your programm and I can try to find some time to help you debug.

Kind regards,
JP

Hi @jplopezll

Thanks for responding! I’m using a teensy 4.0 board, so I would think that memory isn’t an issue.
The teensy’s default serial port is connected (trough its usb) to a terminal on my computer, which both prints statements for received manlink messages and some debug statements of my own (so I now that the microcontroller is indeed running, only no manlink messages are coming trough).

My pixhawk is connected to serial port 2 of the teensy (pin 7 & 8), I’m using telem2 on the pixhawk side.

This is my code now:

// set this to the hardware serial port you wish to use
#define PIXHAWK   Serial2
#include <mavlink.h>

// to ask pixhawk again for the datastreams every once in a while
int resendDataRequistTimerStart = 0; 
int resendDataRequistInterval = 3000;

void setup() {
   Serial.begin(250000);
   PIXHAWK.begin(57600);
}

void comm_receive() {
  mavlink_message_t msg;
  mavlink_status_t status;

  while(PIXHAWK.available()>0) {
    uint8_t c = PIXHAWK.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:  // #0: Heartbeat
          {
            // E.g. read GCS heartbeat and go into
            // comm lost mode if timer times out
            mavlink_heartbeat_t hb;
            mavlink_msg_heartbeat_decode(&msg,&hb);
            Serial.println("Received: HEARTBEAT");
            Serial.println(hb.mavlink_version);
            Serial.println("");
          }
          break;
                 
       default:
          Serial.println("Received: message of unhandled type");
          break;
      }
    }
  }
}


void Mav_Request_Data()
{
  mavlink_message_t msg;
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];

  // To be setup according to the needed information to be requested from the Pixhawk
  const int  maxStreams = 2;
  const uint8_t MAVStreams[maxStreams] = {MAV_DATA_STREAM_ALL, MAV_DATA_STREAM_EXTRA1};
  const uint16_t MAVRates[maxStreams] = {0x02,0x05};
    
  for (int i=0; i < maxStreams; i++) {
    mavlink_msg_request_data_stream_pack(2, 200, &msg, 1, 0, MAVStreams[i], MAVRates[i], 1);
    uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
    PIXHAWK.write(buf, len);
  }
}

void loop() {
  comm_receive();

  // ask again for the datastreams every once in a while
  if(millis() - resendDataRequistTimerStart > resendDataRequistInterval)
  {
    Mav_Request_Data();
    resendDataRequistTimerStart = millis();
  }
}


void Command_long_DISARM(){
  mavlink_message_t msg; 
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];

  mavlink_msg_command_long_pack(1, 1, &msg, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0);
  uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
  PIXHAWK.write(buf, len);
}

Hi, @H_Smeitink:

I am sure you have double or triple checked connections (comms, in particular)…

I would suggest to insert a debug messages to be printed to Serial at the beginning of the comm_receive() and sencond one at the beginning of Mav_Request_Data() functions, to check if they are called. Also a third debug message inside Mav_Request_Data() right after uint8_t c = PIXHAWK.read(). Just to guess if messages are sent and if there is any reply from the Pixhawk.

KR,
JP

Hi again,

I got it working now. I downloaded the latest version again, recompiled everything and all of sudden it works. Still not really sure what the fault was though.

Thank you for your help!

Hi, @H_Smeitink:

Good job!

And thanks a lot for reverting. It’s conforting watching that I could help!

KR,
JP