import bno085
The bno085 module talks to BNO080/BNO085-compatible IMUs over I2C using SHTP packets. It can enable sensor reports and read fused quaternion orientation, acceleration, gyroscope, magnetic field, linear acceleration, and gravity vectors.
Quick example
import bno085
imu = bno085.BNO085(21, 22)
imu.enable("rotation", interval_ms=100)
q = imu.quaternion()
print(q["i"], q["j"], q["k"], q["real"])
importbno085
BNO085 9-axis sensor-fusion IMU module.
The bno085 module talks to BNO080/BNO085-compatible IMUs over I2C using SHTP packets. It can enable sensor reports and read fused quaternion orientation, acceleration, gyroscope, magnetic field, linear acceleration, and gravity vectors.
bno085.BNO085(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bno085_sensor
bno085.BNO085(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bno085_sensorCreate a BNO085 sensor-fusion IMU object.
The returned object owns the active BNO085 reader. If a newer BNO085 object is created, older objects fail clearly instead of reading from the wrong sensor configuration.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Defaults to 0x4A. Some boards use 0x4B. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 400000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
bno085_sensor bno085_sensor object.
bno085.BNO085().enable(report="rotation", interval_ms=100) -> bool
bno085.BNO085().enable(report="rotation", interval_ms=100) -> boolEnable a sensor report stream.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
report |
any |
positional or keyword | No | Optional value. Defaults to "rotation". |
interval_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().read(report=None, timeout_ms=100) -> dict
bno085.BNO085().read(report=None, timeout_ms=100) -> dictRead the next matching report.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
report |
any |
positional or keyword | No | Optional value. Defaults to None. |
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().quaternion(timeout_ms=100) -> dict
bno085.BNO085().quaternion(timeout_ms=100) -> dictRead fused orientation as quaternion fields.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().accel(timeout_ms=100) -> dict
bno085.BNO085().accel(timeout_ms=100) -> dictRead accelerometer values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().gyro(timeout_ms=100) -> dict
bno085.BNO085().gyro(timeout_ms=100) -> dictRead gyroscope values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().magnetic(timeout_ms=100) -> dict
bno085.BNO085().magnetic(timeout_ms=100) -> dictRead magnetic-field values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().linear_accel(timeout_ms=100) -> dict
bno085.BNO085().linear_accel(timeout_ms=100) -> dictRead acceleration with gravity removed.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().gravity(timeout_ms=100) -> dict
bno085.BNO085().gravity(timeout_ms=100) -> dictRead gravity vector values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to 100. |
bno085.BNO085().reset() -> bool
bno085.BNO085().reset() -> boolSend a soft-reset command to the sensor hub.
bno085.BNO085().info() -> dict
bno085.BNO085().info() -> dictReturn I2C and transport state.
bno085.BNO085().close() -> bool
bno085.BNO085().close() -> boolRelease the active I2C device and close this object.
bno085.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bool
bno085.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> boolInitialize a BNO085 sensor on I2C.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Defaults to 0x4A. Some boards use 0x4B. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 400000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
bool True when the I2C transport is initialized and a soft reset command is sent to the sensor hub.
bno085.enable(report: str = None, interval_ms: int = None) -> bool
bno085.enable(report: str = None, interval_ms: int = None) -> boolEnable a BNO085 sensor report.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
report |
str |
positional or keyword | No | Optional report name. Use "rotation", "game_rotation", "geomagnetic", "accel", "gyro", "magnetic", "linear_accel", or "gravity". Defaults to "rotation". |
interval_ms |
int |
positional or keyword | No | Optional report interval in milliseconds. Defaults to 100. |
bool True when the Set Feature command is accepted by the I2C transport.
bno085.read(report: str = None, timeout_ms: int = None) -> dict
bno085.read(report: str = None, timeout_ms: int = None) -> dictRead the next matching BNO085 report.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
report |
str |
positional or keyword | No | Optional report name to wait for. When omitted, returns the next supported report. |
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to 100. |
dict Dict with ``ok``, ``report``, ``report_id``, ``status``, and report values. Quaternion reports include ``i``, ``j``, ``k``, ``real``/``w``. Vector reports include ``x``, ``y``, and ``z`` with unit-specific keys. On timeout, returns ``ok=False`` and ``timeout=True``.
bno085.quaternion(timeout_ms: int = None) -> dict
bno085.quaternion(timeout_ms: int = None) -> dictRead a rotation-vector quaternion report.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to 100. |
dict Dict with quaternion fields ``i``, ``j``, ``k``, ``real``, ``w``, and status metadata.
bno085.accel(timeout_ms: int = None) -> dict
bno085.accel(timeout_ms: int = None) -> dictRead an accelerometer report.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to 100. |
dict Dict with ``x``, ``y``, ``z`` and ``x_mps2``, ``y_mps2``, ``z_mps2``.
bno085.gyro(timeout_ms: int = None) -> dict
bno085.gyro(timeout_ms: int = None) -> dictRead a calibrated gyroscope report.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to 100. |
dict Dict with ``x``, ``y``, ``z`` and ``x_rad_s``, ``y_rad_s``, ``z_rad_s``.
bno085.magnetic(timeout_ms: int = None) -> dict
bno085.magnetic(timeout_ms: int = None) -> dictRead a calibrated magnetic-field report.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to 100. |
dict Dict with ``x``, ``y``, ``z`` and ``x_uT``, ``y_uT``, ``z_uT``.
bno085.linear_accel(timeout_ms: int = None) -> dict
bno085.linear_accel(timeout_ms: int = None) -> dictRead linear acceleration with gravity removed.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to 100. |
dict Dict with ``x``, ``y``, ``z`` and meter-per-second-squared fields.
bno085.gravity(timeout_ms: int = None) -> dict
bno085.gravity(timeout_ms: int = None) -> dictRead the gravity vector.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to 100. |
dict Dict with ``x``, ``y``, ``z`` and meter-per-second-squared fields.
bno085.reset() -> bool
bno085.reset() -> boolSend a soft-reset command to the BNO085 sensor hub.
bool True when the reset packet is written.
bno085.info() -> dict
bno085.info() -> dictReturn BNO085 module state.
dict Dict with initialization state, I2C settings, reset state, and transport type.