#embedded-hal-driver #bno055

no-std bno055

Bosch Sensortec BNO055 9-axis IMU driver

6 releases

✓ Uses Rust 2018 edition

0.1.5 Feb 10, 2019
0.1.4 Feb 9, 2019

#74 in Embedded development

45 downloads per month

Custom license

663 lines

Bosch Sensortec BNO055 embedded-hal driver

What is this?

This is a embedded-hal driver for Bosch's Absolute Orientation Sensor BNO055.

It is device-agnostic and uses embedded-hal's Write/WriteRead (for I2C) and Delay traits for its operation.

Uses and re-exports nalgebra's Quaternion for quaternion reading and Rotation3 for Euler angles.


  1. Add dependency to Cargo.toml:

    cargo add bno055
  2. Instantiate and init the device:

    // ... declare and configure your I2c and Delay implementations ...
    // Init BNO055 IMU
    let imu = bno055::Bno055::new(i2c, delay);
    // Enable 9-degrees-of-freedom sensor fusion mode with fast magnetometer calibration
  3. Read orientation data, quaternion or euler angles (roll, pitch, yaw/heading):

    let quat: nalgebra::Quaternion<f32> = imu.quaternion()?;
    // or:
    let euler: nalgebra::Rotation3<f32> = imu.euler_angles()?;

    Due to the BNO055 firmware bugs, the Euler angles reading shouldn't be relied on. I recommend to stick with quaternion readings and convert it to the Euler angles later and if needed.

Details and examples

Device calibration

To calibrate device's sensors for first time:

use bno055::{BNO055Calibration, BNO055OperationMode, BNO055_CALIB_SIZE};

let bno055 = ...;

// Enter NDOF (ansolute orientation) sensor fusion mode which is also performing
// a regular sensors calibration

// Wait for device to auto-calibrate
while !bno055.is_fully_calibrated() {}

let calib = bno055.calibration_profile()?;

// Save calibration profile in NVRAM
mcu.nvram_write(BNO055_CALIB_ADDR, calib.as_bytes(), BNO055_CALIB_SIZE)?;

To load previously saved calibration profile:

use bno055::{BNO055Calibration, BNO055OperationMode, BNO055_CALIB_SIZE};

let bno055 = ...;

// Read saved calibration profile from MCUs NVRAM
let mut buf = [0u8; BNO055_CALIB_SIZE];
mcu.nvram_read(BNO055_CALIB_ADDR, &mut buf, BNO055_CALIB_SIZE)?;

// Apply calibration profile
let calib = BNO055Calibration::from_buf(buf);

Remapping axes to correspond your mounting

BNO055 allows to change default axes to meet chip orientation with actual physical device orientation, thus providing possibility to place BNO055 chip on PCB as suitable for designer and to match chip's axes to physical axes in software later.

use bno055::{AxisRemap, BNO055AxisConfig};
// ...

// Build remap configuration example with X and Y axes swapped:
let remap = AxisRemap::builder()
    .expect("Failed to build axis remap config");

Please note that AxisRemap (and the chip itself) builder doesn't allow invalid state to be constructed, that is, when one axis is swapped with multiple of others. For example, swapping axis X with both Y and Z at the same time is not allowed:

    .unwrap(); // <- panics, .build() returned Err

Changing axes sign

It is also possible to flip sign of either axis of the chip.

Example of flipping X and Y axes:

    .set_axis_sign(BNO055AxisSign::X_NEGATIVE | bno055::BNO055AxisSign::Y_NEGATIVE)
    .expect("Unable to communicate");

Using external 32k crystal

For better performance, it is advised to connect and use external 32k quartz crystal.

User could enable or disable it by calling set_external_crystal:

    .expect("Failed to set to external crystal");

Using alternative I2C address

BNO055 allows to change its I2C address from default 0x29 to alternative 0x28 by setting COM3 pin LOW.

To connect to device with alternative address, enable its use by calling with_alternative_address():

// use default 0x29 address
let mut bno = bno055::Bno055::new(i2c, delay);

// use 0x28 address
let mut bno = bno055::Bno055::new(i2c, delay).with_alternative_address();

Change BNO055 power mode

use bno055::{Bno055, BNO055PowerMode};
// Normal mode

// Low-power mode (only accelerometer being awake)

// Suspend mode (all sensors and controller are sleeping)

Read chip temperature

Temperature is specified in degrees Celsius by default.

let temp: i8 = bno055.temperature()?;


What is done and tested and what is not yet:

  • Sensor initialization
  • Device mode setup
  • Device status readout
  • Calibration status readout
  • External crystal selection
  • Axis remap
  • Axis sign setup
  • Calibration data readout
  • Calibration data setup
  • Alternative I2C address
  • Take register pages into account
  • Orientation data readout
    • Quaternions
    • Euler angles
  • Raw sensor data readout
    • Raw accelerometer data readout
    • Raw gyroscope data readout
    • Raw magnetometer data readout
  • Linear acceleration data readout
  • Gravity vector data readout
  • Per-sensor configuration (when not in fusion mode)
  • Temperature readout
  • Unit selection
  • Interrupts


~53K SLoC