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. They correspond to the eight standard placement orientations listed in the BNO055 datasheet.

bno055.AXIS_P0: bytes
bno055.AXIS_P1: bytes
bno055.AXIS_P2: bytes
bno055.AXIS_P3: bytes
bno055.AXIS_P4: bytes

Default axis placement used by the constructor.

bno055.AXIS_P5: bytes
bno055.AXIS_P6: bytes
bno055.AXIS_P7: bytes