Hi,
I had a RPi Pico connected to the Copter and I can read the datastreams. But I need to write and read back some specific parameters.
I start trying to read back SYSID_THISMAV but not luck.
This is my current code in arduino:
#include <MAVLink.h>
unsigned long previousMillis = 0;
const long interval = 10000; // Interval for delay in milliseconds (e.g., 1000 ms = 1 second)
void setup() {
// Start hardware serial for debugging
Serial.begin(9600);
Serial1.setTX(0);
Serial1.setRX(1);
Serial1.begin(57600); // Baud rate for MAVLink
pinMode(LED_BUILTIN, OUTPUT);
delay(5000);
Serial.println(“request data”);
//Mav_Request_Data();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
//digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
// MAVLink config
/* The default UART header for your MCU */
int sysid = 1; ///< ID 20 for this airplane. 1 PX, 255 ground station
int compid = 158; ///< The component sending the message
int type = MAV_TYPE_QUADROTOR; ///< This system is an airplane / fixed wing
// Define the system type, in this case an airplane → on-board controller
uint8_t system_type = MAV_TYPE_GENERIC;
uint8_t autopilot_type = MAV_AUTOPILOT_INVALID;
uint8_t system_mode = MAV_MODE_PREFLIGHT; ///< Booting up
uint32_t custom_mode = 0; ///< Custom mode, can be defined by user/adopter
uint8_t system_state = MAV_STATE_STANDBY; ///< System ready for flight
// Initialize the required buffers
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
// Pack the message
mavlink_msg_heartbeat_pack(10,0, &msg, type, autopilot_type, system_mode, custom_mode, system_state);
// Copy the message to the send buffer
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
// Send the message with the standard UART send function
// uart0_send might be named differently depending on
// the individual microcontroller / library in use.
Serial1.write(buf, len);
}
// Check reception buffer
request();
comm_receive();
}
void request()
{
/mavlink_msg_param_request_read(
int16_t param_index; < Parameter index. Send -1 to use the param ID field as identifier (else the param id will be ignored)
uint8_t target_system; < System ID
uint8_t target_component;< Component ID
char param_id[16]/
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
mavlink_msg_param_request_read_pack(10,1,&msg,1,0,“SYSID_THISMAV”,15);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
Serial1.write(buf, len);
}