#accelerometer #gyroscope #imu #embedded-hal-driver #inertial

no-std bmi160

Platform-agnostic Rust driver for the BMI160 inertial measurement unit (IMU)

1 unstable release

0.1.0 Feb 8, 2020

#567 in Embedded development

Download history 87/week @ 2021-02-24 20/week @ 2021-03-03 10/week @ 2021-03-10 19/week @ 2021-03-17 56/week @ 2021-03-24 23/week @ 2021-03-31 26/week @ 2021-04-07 34/week @ 2021-04-14 47/week @ 2021-04-21 26/week @ 2021-04-28 57/week @ 2021-05-05 1200/week @ 2021-05-12 35/week @ 2021-05-19 723/week @ 2021-05-26 923/week @ 2021-06-02 274/week @ 2021-06-09

180 downloads per month

MIT/Apache

31KB
595 lines

Rust BMI160 Inertial Measurement Unit Driver

crates.io Docs Build Status Coverage Status

This is a platform agnostic Rust driver for the BMI160 small, low-power inertial measurement unit using the embedded-hal traits.

This driver allows you to:

  • Get the latest sensor data. See: data().
  • Set the accelerometer, gyroscope and magnetometer power mode. See: set_accel_power_mode().
  • Get the sensor status. See: status().
  • Get power mode. See: power_mode().
  • Get chip ID. See: chip_id().

The BMI160 is an inertial measurement unit (IMU) consisting of a state-of-the-art 3-axis, low-g accelerometer and a low power 3-axis gyroscope. It has been designed for low power, high precision 6-axis and 9-axis applications in mobile phones, tablets, wearable devices, remote controls, game controllers, head-mounted devices and toys.

The BMI160 is available in a compact 14-pin 2.5 × 3.0 × 0.83 mm3 LGA package. When accelerometer and gyroscope are in full operation mode, power consumption is typically 925 μA, enabling always-on applications in battery driven devices.

Further Bosch Sensortec sensors, e.g. geomagnetic (BMM150) can be connected as slave via a secondary I2C interface. In this configuration, the BMI160 controls the data acquisition of the external sensor and the synchronized data of all sensors is stored the register data and can be additionally stored in the built-in FIFO.

Besides the flexible primary interface (I2C or SPI) that is used to connect to the host, BMI160 provides an additional secondary interface. This secondary interface can be used in SPI mode for OIS (optical image stabilization) applications in conjunction with camera modules, or in advanced gaming use cases.

Datasheet

Usage

To use this driver, import this crate and an embedded_hal implementation, then instantiate the device.

Please find additional examples using hardware in this repository: driver-examples

extern crate linux_embedded_hal as hal;
use bmi160::{AccelerometerPowerMode, Bmi160, GyroscopePowerMode, SensorSelector, SlaveAddr};

fn main() {
    let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
    let address = SlaveAddr::default();
    let mut imu = Bmi160::new_with_i2c(dev, address);
    imu.set_accel_power_mode(AccelerometerPowerMode::Normal)
        .unwrap();
    imu.set_gyro_power_mode(GyroscopePowerMode::Normal).unwrap();
    loop {
        let data = imu.data(SensorSelector::new().accel().gyro()).unwrap();
        let accel = data.accel.unwrap();
        let gyro = data.gyro.unwrap();
        println!(
            "Accelerometer: x {:5} y {:5} z {:5}, \
             Gyroscope: x {:5} y {:5} z {:5}",
            accel.x, accel.y, accel.z, gyro.x, gyro.y, gyro.z
        );
    }
}

Support

For questions, issues, feature requests, and other changes, please file an issue in the github project.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~82KB