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.
busis a configuredmachine.I2Cbus object used to communicate with the sensor.addressis the 7-bit I2C address of the device. Defaults to0x28.modeis the operation mode the device is placed into after reset. See the operation-mode constants below. Defaults toNDOF_MODE.axisis a 2-byte axis-remap configuration value. See the axis placement constants below. Defaults toAXIS_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
RuntimeErrorif the expected ID register values are not read back.- read_registers(register: int, size: int = 1) bytes
Read
sizebytes from the given device register and return them as abytesobject.
- write_registers(register: int, data: bytes) None
Write the given
databytes to the device starting atregister.
- operation_mode(mode: int = None) int
Get or set the operation mode register. With no argument, returns the current mode as an
int. With amodeargument, writes the new mode to the device. See the operation-mode constants below.
- system_trigger(data: int) None
Write
datato 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
modeargument, 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
numargument, selects the page.
- read_id() bytes
Return the 4-byte ID block read from register
0x00. The expected value isb'\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
placementargument, writes the supplied 2-byte axis configuration. Use one of theAXIS_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.
Constants
Operation modes
- bno055.CONFIG_MODE: int
Configuration mode (
0x00). The device must be in this mode to change configuration registers.
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.