GitHunt
ME

meh/rust-bmi2-async

A Rust embedded-hal-async driver for the BMI270/260 IMU

bmi2

stability-wip

This is an embedded-hal driver for the Bosch BMI260/270 inertial measurement unit.

Quick start

// ...
use bmi2_async::Bmi2;
use bmi2_async::config;
use bmi2_async::{types::Burst, I2cAddr, types::PwrCtrl};
use embedded_hal_async::delay::DelayNs;

// Specify your delay type, for example:
let delay = MyDelay::new(); // Replace with your actual delay implementation

// Choose a buffer size (e.g., 512 bytes), needs to be >= max data burst
const BUFFER_SIZE: usize = 512;

/// Create a new Bmi2 device using I2C with its alternative address (0x69).
/// Configure the max data burst to 255 bytes:
/// - used for the upload of the configuration during initialization.
/// - This is a limitation from your device or its HAL.
let mut bmi = Bmi2::<_, _, BUFFER_SIZE>::new_i2c(
    i2c, 
    delay,
    I2cAddr::Alternative, 
    Burst::new(255),
);

/// Get the chip id. Should be 0x24 or 36 in decimal
let chip_id = bmi.get_chip_id().await.unwrap();
/// Initialize the senor.
/// During this process a configuration of > 8kB is uploaded to the sensor.
/// Alternatively, for the BMI260 call its dedicated config:
/// bmi.init(&config::BMI260_CONFIG_FILE).unwrap();
bmi.init(&config::BMI270_CONFIG_FILE).await.unwrap();
/// Enable power for the accelerometer and the gyroscope.
let pwr_ctrl = PwrCtrl { aux_en: false, gyr_en: true, acc_en: true, temp_en: false };
bmi.set_pwr_ctrl(pwr_ctrl).await.unwrap();
/// Read the raw data
let data = bmi.get_data().await.unwrap();
// ...

Languages

Rust100.0%

Contributors

MIT License
Created January 20, 2026
Updated January 20, 2026
meh/rust-bmi2-async | GitHunt