[][src]Crate bma2xx

Driver for the Bosch BMA222E and family

Currently this only support I2C configuration as I can't remove the itty bitty package from its home on a populated PCB. If you want to play with one, you can find them in Xfinity XR11 remote controls. 😊

The register maps in this family are very similar and so it should be possible to support the following chips with minimal changes to the code here:

  • BMA222 - 8bit resolution
  • BMA250 - 10bit resolution
  • BMA253 - 12bit resolution
  • BMA255 - 12bit resolution
  • BMA280 - 14bit resolution

Specifically, these chips should work with the library now, but you wouldn't benefit from the enhanced resolution.

More info on the product line from Bosch's website: https://www.bosch-sensortec.com/bst/products/all_products/bma222e

What's currently supported

  1. Accessing the chip via I2C
  2. Reading X, Y, Z axis and whether they've updated since last poll
  3. Reading the event FIFO for X, Y, Z axis (32 element deep queue version of #1)
  4. Changing FIFO mode (stream, fifo, bypass) and reading how full the FIFO is
  5. Checking what data is in the EEPROM and how many writes it has left
  6. Software reset
  7. Reading temperature

What's not currently supported

If anything here seems meaningful to you, feel free to reach out and help implement these features. I just didn't need any of them personally.

  1. Any chip other than the BMA222E
  2. Accessing the chip via SPI
  3. Changing which axis are thrown on the FIFO
  4. Enabling interrupts for slope, tap, FIFO full, orientation, etc
  5. Tap detection
  6. Acceleration data filters
  7. Power modes (normal, deep sleep, low power, suspend)
  8. Lower power sleep duration
  9. Whether to shadow acceleration data or not
  10. Configuration of the INT1 and INT2 pins nor their sources
  11. Interrupt thresholds for acceleration, slope, etc
  12. FIFO watermark interrupt level
  13. Self-test
  14. Actually programming the EEPROM or setting the values
  15. Setting the offset compensation
  16. Offset compensation
  17. And many more!

Example usage:

fn main() {
    // Get an instance of an i2c struct here with one of the [device crates](https://github.com/rust-embedded/awesome-embedded-rust#device-crates).

    let mut accel = Bma222e::new(i2c);



fn examples(accel: Bma222e) -> Result<(), ()> {
    let chip_id = accel.who_am_i()?;
    println!("About to Begin. ID is {} and should be {}", chip_id, bma222e::IDENTIFIER)?;

    let temp = accel.temperature()?;
    println!("Temperature: {}", temp)?;

    let writes_remaining = accel.eeprom_writes_remaining()?;
    println!("EEPROM Writes Remaining: {}", writes_remaining)?;

    let nvm_data = accel.eeprom_data()?;
    hprint!("EEPROM Data: ")?;
    for byte in &nvm_data {
        hprint!("{:02X} ", byte)?;

    // FIFO-related goodness!
    // TODO: Find out why the output data wasn't consistent
    let fifo_size = accel.fifo_size()?;
    println!("Events in the FIFO: {}", fifo_size)?;
    let mut events = [AxisData {value: 0, changed: false}; 3];
    accel.fifo_get(&mut events)?;

    let x = accel.axis_x()?;
    let y = accel.axis_y()?;
    let z = accel.axis_z()?;
    println!("X:{0:03} Y:{1:03} Z:{2:03}",




Holds accelerometer data


Create an instance of the accelerometer



Various FIFO operating modes



The address on the bus. TODO: Support alt addresses


This identifier changes based on the product in the range.