Overview
Sensor data is the foundation of drone control. In this project, you will learn how to read the drone’s sensor data and perform simple analysis.
What You’ll Learn
- Sensor data reading
- I2C communication protocol
- Data logging functionality
- Data analysis methods
Materials Needed
| Item | Quantity | Notes |
|---|---|---|
| Fully Assembled Drone | 1 | - |
| Computer | 1 | With VS Code + ESP-IDF environment |
| USB Cable | 1 | For programming |
| Smartphone | 1 | With Drone Control APP installed |
Step 1: Understand Sensors
| Sensor | Function |
|---|---|
| MPU6050 | 6-axis sensor, measures acceleration and angular velocity |
| BMP280 | Pressure sensor, measures pressure and altitude |
Step 2: Read Sensor Data
Open the following files to understand data reading logic:
components/drivers/i2c_devices/mpu6050/mpu6050.ccomponents/core/crazyflie/modules/src/estimator_complementary.c
Step 3: Add Data Logging
Open components/core/crazyflie/modules/src/log.c and add new log variables (e.g., acc_x, gyro_y, height).
Register these variables in the logInit() function.
Step 4: Compile, Flash and Test
- Compile and flash the code
- Power on, connect to smartphone APP
- Enter the “Log” page, select the data variables to view
- Click “Start Log”
- Move the drone and observe changes in sensor data
Step 5: Data Analysis
- Export log data to computer
- Use Excel or Python for analysis
- Plot curves of acceleration, angular velocity, and altitude over time
- Analyze the drone’s motion state
Troubleshooting
Cannot read sensor data
- Check I2C connections
- Confirm sensor address is correct
Data log not displaying
- Check Wi-Fi connection
- Confirm log variables are registered
Achievement
Congratulations! You have mastered the methods of reading and analyzing sensor data, which is an important skill for drone development!
Next Steps
In the next project, you will learn how to use ultrasonic sensors for obstacle avoidance.