High-frequency IMU data logger for ESP32. Reads accelerometer and gyroscope data from an MPU6050 at 50 Hz and writes binary samples to an SD card using a FreeRTOS producer-consumer architecture.
The firmware constantly samples 6-axis motion data and stores it to a binary file on an SD card. A producer task handles sensor reads every 20 ms, while a consumer task drains full data blocks from a queue and writes them to the filesystem. Data is periodically flushed to prevent loss on unexpected power cuts.
| Component | Interface | Pins |
|---|---|---|
| ESP32-S3 | ||
| MPU6050 | I2C | SDA = 8, SCL = 9 |
| SD card module | SPI | MOSI = 11, MISO = 13, CLK = 12, CS = 10 |
The firmware uses a double-buffering pattern built on two FreeRTOS queues:
q_empty_buffersholds pre-allocated blocks waiting to be filledq_full_buffersholds completed blocks waiting to be written
Producer task runs at a fixed 50 Hz rate. It reads 14 bytes from the MPU6050 over I2C, parses accelerometer and gyroscope values from Big-Endian format, and stores each sample with a timestamp. Once a block reaches 100 samples, it is pushed to q_full_buffers.
Consumer task waits for full blocks and writes them to the SD card in a single fwrite call. Every 10 blocks, fflush and fsync are called to force a physical write to flash memory.
Data is written to /sdcard/imu_data.bin as a raw binary stream of imu_sample_t records.
typedef struct {
uint32_t timestamp_ms;
int16_t accel_x;
int16_t accel_y;
int16_t accel_z;
int16_t gyro_x;
int16_t gyro_y;
int16_t gyro_z;
} imu_sample_t; // 16 bytes per recordThis project is built with **ESP-IDF v5.5.2.
idf.py build
idf.py flash
idf.py monitor