MavLink problem with certain Arduino boards

I am having trouble with using MavLink over USB serial on SOME Arduino boards.

It works on: Uno, Due (Programming port) It does NOT work on: Leonardo, Due (USB native port)

When it works, I pack MavLink messages and send them with write(buf,len) on the appropriate port. I run QGroundControl, and use its MavLink Inspector to watch incoming heartbeats from the Arduino. :grin:

When it doesn't work, I run the same code (with Serial or SerialUSB as appropriate), but either no messages get through to QGroundControl, or only one. :fearful:

I have repeatedly verified this, and also checked using MissionPlanner as an alternative to QGroundControl.

I don't know why there is this difference in behaviour... could it be that the on-chip serial port of the Leonardo is somehow different when writing blocks of data? A buffer issue? Any suggestions or ideas?

Has anyone used MavLink with a Leonardo successfully? (Or Due SerialUSB)

I can send plain text without problem over all the ports. So perhaps its binary data that causes the problem? Could the on-chip ports (e.g. Leonardo Serial) be reacting to certain non ASCII bytes in the data stream? E.g. XON, XOFF?

I eventually worked out what is happening here, and in case its helpful...

The Due programming port has DTR connected to reset, so whenever a connection is made (programming or serial monitor), the SerialUSB port disappears, and then after a few seconds reappears. (This is normal and expected).

QGroundControl therefore needs to be reconnected after every reset. If not, it 'holds' on to the previous COM port, which no longer exists. Reconnecting to the 'new' COM port (with the same name) works fine.

However, using the Programming port for MAV and QGoundControl means that this port is always open, and the board can be reset while QGroundControl is connected, which is much more convenient.

So there is no problem with the serial ports, it was just the sequence of connecting that I was doing incorrectly.

I’m facing the exact same problem, it I’m unable to solve it. Didn’t understand well what you’ve done to fix the problem... Can you give me some hints?