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:
Which pin number of ESP you connected to which pin_number on cube?
Did you checked what the ESP sends?
Do you have the possibilty to connect the ESP via a TTL UART 2 USB Converter directly to our PC?
Hi thanks for answering, according to my code, I have been connecting pin 16 to tx in serial 4 and pin 17 to rx and common GND. We should see something like POT_VOLT: 1.87. Regarding your last question, I need the connection between the orange cube and the esp without any intermediary PC.
Is the ESP32 connected via the onboard USB port to your PC or via the Serial2. To check if it is working correct on Serial2 you have to monitor this directly with your PC.
As I understood your problem is that you don’t know if the ESP is sending the correct information to the FC. So you have to look directly to this interface. Also I think you don’t have a complete electronic lab with a storage oszilloscope or a protocoll analyzer. So a simple way is to test the two components FC and ESP seperate with the use of the PC. But therefore a TTL UART to USB converter is necessary.
Hi, I dont need communication of my ESP32 with my computer, with the computer I am programming with arduino IDE I will send you a draw with the actual connections
#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() {
Serial.begin(115200); // ADD THIS
// 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() {
while (CubeSerial.available() > 0) Serial.write(CubeSerial.write); // ADD THIS
// 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)
}
Let’s check one by one. Replace your code with this code and compile again. Then check the serial monitor with 115200 baudrate to see if any data is being received from the FC.
if “Nothing” then something is wrong with phisycal connection cable
You wrote this ID, but you didn’t attach your parameter ID here. What does SYSID_THISMAV contain? make sure that values is the same with 42
if “ALL” seems okay then please change GPIO to other numbers because some Esp32 have a different GPIO purpose and i’m afraid you use GPIO which is not suppose tobe use
and just set
HardwareSerial CubeSerial(2);
to
HardwareSerial CubeSerial(1);
Hello, thank you very much for your reply. Unfortunately, after following your advice, I still cannot see anything in the messages section of Mission Planner. I would also like to point out that the code does not have the option to display data in the Arduino IDE serial port, but in previous tests I was able to see the analog reading from the Arduino IDE serial port.
if you paste the source from my (above) you must see the data flow on that monitor, if not as i mention above then something is wrong with the phisycal connections