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?