Skip to content

Altimeter Decryption

The barometer is the core sensor for drone altitude hold functionality. In this project, you will learn how to read barometer data, calculate real altitude, and implement more precise altitude hold.

  • Barometer working principles
  • Altitude calculation methods
  • Data filtering techniques
  • Dead zone control
ItemQuantityNotes
ESP32 Drone1Fully assembled
BMP280 Barometer Module1Measures pressure and altitude
Serial Debug Assistant1serial_debug.exe

Connect BMP280 to ESP32:

BMP280ESP32
VCC3.3V
GNDGND
SCLGPIO 22
SDAGPIO 21

Extract barometer.zip and open with VS Code.

Open sensors_bmp280.c and find the bmp280_init function:

void bmp280_init(void) {
// ... initialization code ...
p0 = 101325; // Sea level pressure (Pa)
}

Check local current pressure using a weather app (e.g., 100800 Pa) and modify p0:

p0 = 100800; // Local current pressure

Compile and flash the code, open the serial debug assistant, and observe the data:

  • When stationary, pressure values should be stable
  • When moving the drone up and down, altitude values should change accordingly

Open altitude_hold.c and add “altitude hold dead zone”:

if (fabs(current_altitude - target_altitude) < 0.1) {
// Altitude difference less than 0.1 meters, no adjustment
return;
}

Set target altitude to 1 meter and observe if the drone can maintain stable altitude.

  • Add low-pass filter
  • Check sensor connections
  • Calibrate local pressure value
  • Check temperature compensation

Congratulations! You have mastered the use of the barometer and implemented precise altitude hold functionality!

In the next project, you will learn how to read IMU data and calculate drone attitude using complementary filtering algorithm.