Hello, I am trying to send data from an ESP32 to an Orange Cube+ with ArduPilot. To simulate a sensor connected to the ESP32, I am using a potentiometer and the c_library_v2 library with the following code:
#include <Arduino.h>
#include <stdint.h>
extern "C" {
#include "mavlink/common/mavlink.h"
}
// UART2 del ESP32 hacia Cube Orange
HardwareSerial CubeSerial(2);
// IDs MAVLink
static uint8_t system_id = 42; // ESP32
static uint8_t component_id = 200; // Sensor externo
// Pin ADC
const int POT_PIN = 34;
// Parámetros ADC ESP32
const float ADC_MAX = 4095.0;
const float VREF = 3.3;
void setup() {
// UART hacia Cube Orange
CubeSerial.begin(115200, SERIAL_8N1, 16, 17);
// Configurar ADC
analogReadResolution(12); // 0–4095
analogSetAttenuation(ADC_11db); // rango ~0–3.3V
delay(1000); // tiempo para que el Cube arranque
}
void loop() {
// Leer potenciómetro
uint16_t adc_raw = analogRead(POT_PIN);
// Convertir a voltaje
float voltage = (adc_raw / ADC_MAX) * VREF;
// Preparar MAVLink
mavlink_message_t msg;
uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
mavlink_msg_named_value_float_pack(
system_id,
component_id,
&msg,
millis(),
"POT_VOLT",
voltage
);
uint16_t len = mavlink_msg_to_send_buffer(buffer, &msg);
CubeSerial.write(buffer, len);
delay(200); // 5 Hz (ideal para sensores)
}
SERIAL2_PROTOCOL = 2
SERIAL2_BAUD = 115
BRD_SER2_RTSCTS = 0
LOG_DISARMED = 1
LOG_BACKEND_TYPE = 1
I am using those parameters in mission planner, but I don’t get any communication, can you help me please?
I connected tx rx and gnd between esp32 an cube orange+
