← Swipe for prev/next tutorial →
intermediate Level

Altimeter Decryption

Read barometer data, calculate real altitude, and implement more precise altitude hold functionality.

⏱️ 1.5 hours 📋 Complete Project 02

Overview

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.

What You’ll Learn

  • Barometer working principles
  • Altitude calculation methods
  • Data filtering techniques
  • Dead zone control

Materials Needed

ItemQuantityNotes
ESP32 Drone1Fully assembled
BMP280 Barometer Module1Measures pressure and altitude
Serial Debug Assistant1serial_debug.exe

Step 1: Hardware Wiring

Connect BMP280 to ESP32:

BMP280ESP32
VCC3.3V
GNDGND
SCLGPIO 22
SDAGPIO 21

Step 2: Open the Project

Extract barometer.zip and open with VS Code.

Step 3: Modify Pressure Calibration

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

Step 4: Compile and Flash

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

Step 5: Optimize Altitude Hold

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;
}

Step 6: Test

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

Troubleshooting

Large altitude data fluctuations

  • Add low-pass filter
  • Check sensor connections

Inaccurate altitude calculation

  • Calibrate local pressure value
  • Check temperature compensation

Achievement

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

Next Steps

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

Continue to Project 04: Attitude Magician →

← Tutorials