[][src]Crate bmi160

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

This driver allows you to:

The devices

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 examples (see also examples folder)

To use this driver, import this crate and an embedded_hal implementation, then create an instance of the driver either in I2C or SPI mode.

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

Create an instance of the driver in I2C mode and print the chip id

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

let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut imu = Bmi160::new_with_i2c(dev, address);
let id = imu.chip_id().unwrap_or(0);
println!("Chip ID: {}", id);

Create an instance of the driver in SPI mode and print the chip id

extern crate linux_embedded_hal as hal;
use bmi160::Bmi160;

let spi = hal::Spidev::open("/dev/spidev0.0").unwrap();
let chip_select = hal::Pin::new(25);
let mut imu = Bmi160::new_with_spi(spi, chip_select);
let id = imu.chip_id().unwrap_or(0);
println!("Chip ID: {}", id);

Enable accelerometer and gyroscope and read data

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

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);
}

Re-exports

pub use crate::interface::SlaveAddr;

Modules

interface

I2C/SPI interfaces

Structs

Bmi160

BMI160 device driver

Data

Sensor data read

MagnetometerData

Magnetometer data

Sensor3DData

Sensor data read selector

SensorPowerMode

Sensor power mode

SensorSelector

Sensor data read selector

Status

Sensor status flags

Enums

AccelerometerPowerMode

Accelerometer power mode

Error

All possible errors in this crate

GyroscopePowerMode

Gyroscope power mode

MagnetometerPowerMode

Magnetometer power mode