Send RPM Data from the Arduino to QGroundcontrol using Pixhawk 6x

Hi Guys,

I’m trying so send RPM data measured by an Arduino Mega to the Groundcontrolstation via the Mavlink protocol.
Unfortunately I have problems with compiling the code in the Arduino IDE.
The errors I get are:
Compilation error: ‘Mavlink’ was not declared in this scope
error: ‘mavlink_msg_efi_status_pack’ was not declared in this scope
mavlink_msg_efi_status_pack(1, 200, &msg, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
note: suggested alternative: ‘mavlink_msg_gps_status_pack’
mavlink_msg_efi_status_pack(1, 200, &msg, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~~

this is my code:

#include <mavlink.h>

// RPM Sensor
const int signalPin = 2; // Der Pin, an dem das Signal angeschlossen ist
volatile unsigned long startMicros = 0;
volatile bool firstEdgeDetected = false;

void setup() {
  Serial.begin(57600); // Initialisierung der seriellen Kommunikation
  pinMode(signalPin, INPUT); // Setzen Sie den Pin als Eingang
  attachInterrupt(digitalPinToInterrupt(signalPin), handleInterrupt, RISING); // Interrupt für steigende Flanken aktivieren
  Mavlink.begin(Serial); // Initialisieren Sie die Mavlink-Kommunikation
}

void loop() {
  // Hier können Sie andere Aufgaben ausführen, wenn nötig
  delay(2000); // Warten Sie 2 Sekunden zwischen den Mavlink-Nachrichten
  sendRPMFrequency(); // Senden Sie die RPM-Frequenz per Mavlink
}

void handleInterrupt() {
  if (!firstEdgeDetected) {
    startMicros = micros(); // Zeitpunkt der ersten steigenden Flanke speichern
    firstEdgeDetected = true;
  } else {
    unsigned long endMicros = micros(); // Zeitpunkt der zweiten steigenden Flanke speichern
    firstEdgeDetected = false;

    unsigned long timeBetweenEdges = endMicros - startMicros; // Zeit zwischen den Flanken in Mikrosekunden
    float frequency = 1000000.0 / timeBetweenEdges; // Frequenzberechnung (in Hertz)
    Serial.print("Frequenz: ");
    Serial.print(frequency);
    Serial.println(" Hz");
  }
}

void sendRPMFrequency() {
  // Erstellen Sie eine EFI_STATUS Mavlink-Nachricht
  mavlink_message_t msg;
  mavlink_msg_efi_status_pack(1, 200, &msg, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

  // Senden Sie die Mavlink-Nachricht
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];
  uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
  Serial.write(buf, len);
}

Could you help me please?

Check your mavlink include and whether the EFI_STATUS message is actually in there.

1 Like

Sorry but I did not get your point, the mavlink.h library is included and in the right folder
what else can I do?

I think I have found the problem:

  1. my library mavlink.h wasn’t installed right
  2. my library doesn’t include the efi message library in the common folder

But how to solve this issue?

Where do you get the mavlink library from?

Maybe you need to regenerate the header files as explained in Generate MAVLink Libraries · MAVLink Developer Guide and then replace the existing header files with the new ones.

1 Like

Update: I downloaded a more updated library version mavlink/c_library_v2: Official reference C / C++ library for the v2 protocol (github.com)

There is the wanted file mavlink_msg_efi_status.h which was missing in the previous library that I used