Hello guys,
I need some help with my current project.
The plan ist to read out sensor data with an Arduino (PWM converted to RPM on the Arduino, Temperature) which is connected to a Pixhawk Flightcontroller.
The Pixhawk then sends the sensor data to the Mission Planner goundcontrolstation.
The used protocol is Mavlink and this is my code:
#include <checksum.h>
#include <mavlink_conversions.h>
#include <mavlink_get_info.h>
#include <mavlink_helpers.h>
#include <mavlink_sha256.h>
#include <mavlink_types.h>
#include <protocol.h>
const int signalPin = 2; // Pin where the signal is connected
volatile unsigned long startMicros = 0;
volatile bool firstEdgeDetected = false;
// Create a MAVLink message structure for EFI_STATUS
mavlink_efi_status_t efiStatus;
mavlink_message_t msg;
void setup() {
Serial.begin(57600); // Initialize serial communication (for debugging)
pinMode(signalPin, INPUT);
attachInterrupt(digitalPinToInterrupt(signalPin), handleInterrupt, RISING);
// Initialize the MAVLink library and the Serial1 port for Pixhawk communication
Serial1.begin(57600); // Set the UART baud rate to match your Pixhawk configuration
MAVLink.begin(Serial1, 57600);
// Set your system ID and component ID (these should match your Pixhawk setup)
MAVLink.systemID = 1; // Your Arduino's system ID
MAVLink.componentID = 200; // Your component ID (e.g., 200 for IMU)
}
void loop() {
// Send the EFI_STATUS message
sendEFIStatusMessage();
}
void handleInterrupt() {
if (!firstEdgeDetected) {
startMicros = micros();
firstEdgeDetected = true;
} else {
unsigned long endMicros = micros();
firstEdgeDetected = false;
unsigned long timeBetweenEdges = endMicros - startMicros;
float frequency = 1000000.0 / timeBetweenEdges;
// Populate the EFI status data structure with the RPM data
efiStatus.ecu_index = 1.0; // Set ECU index (adjust as needed)
efiStatus.rpm = frequency; // RPM value based on frequency
efiStatus.health = 0; // Set EFI health status (adjust as needed)
// Send the EFI_STATUS message here if needed (in the loop function)
}
}
void sendEFIStatusMessage() {
// Encode and send the EFI_STATUS message to the Pixhawk
mavlink_msg_efi_status_encode(MAVLink.systemID, MAVLink.componentID, &msg, &efiStatus);
MAVLink.send(msg);
}
Unfortunately I can’t compile the code with an arduino uno