# BMI270 Six-Axis Raw Data Example [中文说明](README_cn.md) This example demonstrates how to connect a BMI270 (Base firmware) to a native I2C master bus via `bmi270_sensor_create_from_master_bus()`, sample six-axis accelerometer and gyroscope data, and output raw ADC counts along with converted physical units (m/s² and °/s) in CSV format. ## Hardware Connection - Compatible with any ESP32 development board connected to a BMI270 in I2C mode. - Ensure correct power and common ground connections, with suitable SDA/SCL pull-up resistors (400 kHz bus speed). - SDO is tied low by default (corresponding to I2C slave address **0x68**). If SDO is driven by an MCU GPIO, configure the pin in menuconfig. | Signal | Default GPIO (ESP32-S3) | Description | | --- | --- | --- | | SDA | GPIO2 | Main I2C data line | | SCL | GPIO1 | Main I2C clock line | | SDO | Optional (default external low) | Optional GPIO driven low by software to select 0x68 address | ## Build and Run 1. Set the target chip and build the project: ```sh idf.py set-target esp32s3 idf.py menuconfig idf.py build ``` 2. Flash and monitor: ```sh ESPBAUD=921600 idf.py -p PORT flash monitor ``` Under **Raw Data Example Configuration** in `menuconfig`, you can configure: * **SDA / SCL GPIO**: Adjust according to your hardware wiring. * **ODR (Output Data Rate)**: Supports 25 Hz, 50 Hz, 100 Hz, 200 Hz (default 100 Hz). * **Accelerometer Range**: Supports ±2 g, ±4 g, ±8 g, ±16 g (default ±2 g). * **Gyroscope Range**: Supports ±125, ±250, ±500, ±1000, ±2000 °/s (default ±2000 °/s). * **Polling Interval**: Interval between reads (default 100 ms). * **Sample Count**: Set to `0` for continuous output, or a positive integer to automatically exit and release resources after collecting the specified number of samples. ## Output Format and Conversion The example outputs a CSV header followed by periodic sample data: ```text timestamp_us,acc_x_raw,acc_y_raw,acc_z_raw,gyr_x_raw,gyr_y_raw,gyr_z_raw,acc_x_m_s2,acc_y_m_s2,acc_z_m_s2,gyr_x_dps,gyr_y_dps,gyr_z_dps ``` | CSV Field | Description | | --- | --- | | `timestamp_us` | Host microsecond timestamp when data was read | | `acc_x_raw`, `acc_y_raw`, `acc_z_raw` | Signed 16-bit raw ADC counts for accelerometer | | `gyr_x_raw`, `gyr_y_raw`, `gyr_z_raw` | Signed 16-bit raw ADC counts for gyroscope | | `acc_x_m_s2`, `acc_y_m_s2`, `acc_z_m_s2` | Converted acceleration in m/s² | | `gyr_x_dps`, `gyr_y_dps`, `gyr_z_dps` | Converted angular velocity in °/s | ### Unit Conversion Formulas * **Acceleration (m/s²)** = `Raw Count × Accel Range (g) × 9.80665 ÷ 32768` * **Angular Velocity (°/s)** = `Raw Count × Gyro Range (°/s) ÷ 32768` > When stationary, the magnitude of acceleration reflects gravity (~9.8 m/s²), while gyroscope readings remain near zero. Application-level calibration and sensor fusion algorithms can be applied for higher precision.
To create a project from this example, run:
idf.py create-project-from-example "espressif/bmi270_sensor=0.4.0:raw_data"