bno055 — BNO055 IMU Driver#

This module provides a driver for the Bosch BNO055 9-axis absolute orientation sensor over I2C. The BNO055 fuses accelerometer, magnetometer, and gyroscope data on-chip and exposes quaternion, Euler-angle, linear-acceleration, and gravity outputs in addition to the raw sensor channels.

Example usage:

import time
from machine import I2C
import bno055

bus = I2C(1)
imu = bno055.BNO055(bus)

while True:
    print(imu.euler())
    time.sleep_ms(100)

Classes#

class bno055.BNO055(bus: machine.I2C, address: int = 0x28, mode: int = NDOF_MODE, axis: bytes = AXIS_P4)#

Construct a BNO055 driver instance.

  • bus is a configured machine.I2C bus object used to communicate with the sensor.

  • address is the 7-bit I2C address of the device. Defaults to 0x28.

  • mode is the operation mode the device is placed into after reset. See the operation-mode constants below. Defaults to NDOF_MODE.

  • axis is a 2-byte axis-remap configuration value. See the axis placement constants below. Defaults to AXIS_P4.

The constructor verifies the chip ID, performs a soft reset, switches to normal power, applies the axis configuration, and enters the requested operation mode using the external oscillator. Raises RuntimeError if the expected ID register values are not read back.

read_registers(register: int, size: int = 1) bytes#

Read size bytes from the given device register and return them as a bytes object.

write_registers(register: int, data: bytes) None#

Write the given data bytes to the device starting at register.

operation_mode(mode: int = None) int#

Get or set the operation mode register. With no argument, returns the current mode as an int. With a mode argument, writes the new mode to the device. See the operation-mode constants below.

system_trigger(data: int) None#

Write data to the system trigger register (0x3F). This is used internally to issue a soft reset (0x20) and to select the external oscillator (0x80).

power_mode(mode: int = None) bytes#

Get or set the power mode register. With no argument, returns the current power-mode register contents. With a mode argument, writes the new power mode to the device.

page(num: int = None) None#

Get or set the register page. With no argument, reads the current page register. With a num argument, selects the page.

temperature() int#

Return the chip temperature register value as an unsigned byte.

read_id() bytes#

Return the 4-byte ID block read from register 0x00. The expected value is b'\xA0\xFB\x32\x0F'.

axis(placement: bytes = None) bytes#

Get or set the axis remap configuration. With no argument, returns the current 2-byte axis configuration. With a placement argument, writes the supplied 2-byte axis configuration. Use one of the AXIS_P0..``AXIS_P7`` constants below.

quaternion() list#

Return the fused orientation as a 4-element list [w, x, y, z] of floats scaled to the unit quaternion range.

euler() list#

Return the fused orientation as a 3-element list [yaw, roll, pitch] of floats in degrees.

accelerometer() list#

Return the accelerometer reading as a 3-element list [x, y, z] of floats in m/s^2.

magnetometer() list#

Return the magnetometer reading as a 3-element list [x, y, z] of floats in micro-Tesla.

gyroscope() list#

Return the gyroscope reading as a 3-element list [x, y, z] of floats in degrees per second.

linear_acceleration() list#

Return the gravity-compensated linear acceleration as a 3-element list [x, y, z] of floats in m/s^2.

gravity() list#

Return the gravity vector as a 3-element list [x, y, z] of floats in m/s^2.

Constants#

Operation modes#

bno055.CONFIG_MODE: int#

Configuration mode (0x00). The device must be in this mode to change configuration registers.

bno055.ACCONLY_MODE: int#

Accelerometer-only non-fusion mode (0x01).

bno055.MAGONLY_MODE: int#

Magnetometer-only non-fusion mode (0x02).

bno055.GYRONLY_MODE: int#

Gyroscope-only non-fusion mode (0x03).

bno055.ACCMAG_MODE: int#

Accelerometer + magnetometer non-fusion mode (0x04).

bno055.ACCGYRO_MODE: int#

Accelerometer + gyroscope non-fusion mode (0x05).

bno055.MAGGYRO_MODE: int#

Magnetometer + gyroscope non-fusion mode (0x06).

bno055.AMG_MODE: int#

Accelerometer + magnetometer + gyroscope non-fusion mode (0x07).

bno055.IMUPLUS_MODE: int#

IMU fusion mode using accelerometer + gyroscope (0x08).

bno055.COMPASS_MODE: int#

Compass fusion mode using accelerometer + magnetometer (0x09).

bno055.M4G_MODE: int#

Magnet-for-gyroscope fusion mode (0x0A).

bno055.NDOF_FMC_OFF_MODE: int#

9-DOF fusion mode with fast magnetometer calibration disabled (0x0B).

bno055.NDOF_MODE: int#

9-DOF fusion mode with fast magnetometer calibration enabled (0x0C). This is the default mode used by the constructor.

Axis placements#

The following 2-byte values are passed to BNO055.axis() to remap the device coordinate system. Each constant is the (AXIS_MAP_CONFIG, AXIS_MAP_SIGN) register pair from the BNO055 datasheet (Section 3.4, Axis remap), pre-encoded for one of the eight standard placement orientations.

Choose the constant whose output axes match how the chip is physically mounted on the host PCB:

Constant

Output X

Output Y

Output Z

Bytes

Mounting

AXIS_P0

-Yc

+Xc

+Zc

21 04

face-up, 90° CCW from P1

AXIS_P1

+Xc

+Yc

+Zc

24 00

face-up, datasheet default

AXIS_P2

-Xc

-Yc

+Zc

24 06

face-up, rotated 180°

AXIS_P3

+Yc

-Xc

+Zc

21 02

face-up, 90° CW from P1

AXIS_P4

+Xc

-Yc

-Zc

24 03

face-down, flipped about X (constructor default)

AXIS_P5

+Yc

+Xc

-Zc

21 01

face-down, rotated 90° CCW from P4

AXIS_P6

-Yc

-Xc

-Zc

21 07

face-down, rotated 180° from P4

AXIS_P7

-Xc

+Yc

-Zc

24 05

face-down, rotated 90° CW from P4

Xc / Yc / Zc denote the chip’s intrinsic axes (as printed in the BNO055 datasheet). The “Output” columns are the axes the device delivers via BNO055.euler(), BNO055.gyro(), etc. P0 through P3 are the four 90° rotations of the chip in the component-side-up orientation; P4 through P7 are the same four rotations after flipping the chip onto its back.

bno055.AXIS_P0: bytes#

Chip face up, rotated 90° CCW from AXIS_P1. Output axes: X = -Yc, Y = +Xc, Z = +Zc.

bno055.AXIS_P1: bytes#

Chip face up in the BNO055 datasheet’s default orientation. No remap is applied: X = +Xc, Y = +Yc, Z = +Zc.

bno055.AXIS_P2: bytes#

Chip face up, rotated 180° from AXIS_P1. Output axes: X = -Xc, Y = -Yc, Z = +Zc.

bno055.AXIS_P3: bytes#

Chip face up, rotated 90° CW from AXIS_P1. Output axes: X = +Yc, Y = -Xc, Z = +Zc.

bno055.AXIS_P4: bytes#

Chip flipped onto its back (component side down) relative to AXIS_P1. Output axes: X = +Xc, Y = -Yc, Z = -Zc. This is the placement used by the BNO055 constructor when no axis argument is supplied.

bno055.AXIS_P5: bytes#

Chip face down, rotated 90° CCW from AXIS_P4. Output axes: X = +Yc, Y = +Xc, Z = -Zc.

bno055.AXIS_P6: bytes#

Chip face down, rotated 180° from AXIS_P4. Output axes: X = -Yc, Y = -Xc, Z = -Zc.

bno055.AXIS_P7: bytes#

Chip face down, rotated 90° CW from AXIS_P4. Output axes: X = -Xc, Y = +Yc, Z = -Zc.