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. 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 |
|---|---|---|---|---|---|
|
|
|
|
face-up, 90° CCW from P1 |
|
|
|
|
|
face-up, datasheet default |
|
|
|
|
|
face-up, rotated 180° |
|
|
|
|
|
face-up, 90° CW from P1 |
|
|
|
|
|
face-down, flipped about X (constructor default) |
|
|
|
|
|
face-down, rotated 90° CCW from P4 |
|
|
|
|
|
face-down, rotated 180° from P4 |
|
|
|
|
|
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 theBNO055constructor when noaxisargument is supplied.
- bno055.AXIS_P5: bytes¶
Chip face down, rotated 90° CCW from
AXIS_P4. Output axes:X = +Yc,Y = +Xc,Z = -Zc.