Bosch Sensortec BNO055 embedded-hal driver
What is this?
This is a embedded-hal driver for Bosch's inertial measurement unit (IMU) BNO055.
It is device-agnostic and uses Write
/WriteRead
(I2C) and Delay
embedded-hal traits for its operation.
Uses and re-exports nalgebra's Quaternion for quaternion reading and Rotation3 for Euler angles.
Usage
-
Add dependency to
Cargo.toml
: -
Instantiate and init the device:
// ... declare and configure your I2c and Delay implementations ... // Init BNO055 IMU let imu = new; imu.init?; // Enable 9-degrees-of-freedom sensor fusion mode with fast magnetometer calibration imu.set_mode?; Ok
-
Read orientation data: quaternion or euler angles (roll, pitch, yaw/heading)
let quat: Quaternion = imu.quaternion?; // or: let euler: Rotation3 = imu.euler_angles?;
Details and examples
Device calibration
To calibrate device's sensors for first time:
use ;
let bno055 = ...;
// Enter NDOF sensor fusion mode whic is also performing
// a calibration
bno055.set_mode?;
// Wait for device to auto-calibrate
while !bno055.is_fully_calibrated
let calib = bno055.calibration_profile?;
// Save calibration profile in NVRAM
mcu.nvram_write?;
To load previously saved calibration profile:
use ;
let bno055 = ...;
// Read saved calibration profile from MCUs NVRAM
let mut buf = ;
mcu.nvram_read?;
// Apply calibration profile
let calib = from_buf;
bno055.set_calibration_profile?;
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 ;
// ...
// Build remap configuration example with X and Y axes swapped:
let remap = builder
.swap_x_with
.build
.expect;
bno055.set_axis_remap?;
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:
.swap_x_with
.swap_x_with
.build
.unwrap; // <- panics, .build() returned Err
builder
Changing axes sign
It is also possible to flip sign of either axis of the chip.
Example of flipping X and Y axes:
bno055
.set_axis_sign
.expect;
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
:
bno055
.set_external_crystal
.expect;
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 = new;
// use 0x28 address
let mut bno = new.with_alternative_address;
Change BNO055 power mode
use ;
// Normal mode
bno055.set_power_mode?;
// Low-power mode (only accelerometer being awake)
bno055.set_power_mode?;
// Suspend mode (all sensors and controller are sleeping)
bno055.set_power_mode?;
Status
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
- Interrupts