MojoScale Studio Docs
API Reference

bno085

BNO085 9-axis sensor-fusion IMU module.

Studio Docs Sensors & I/O

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.

API 23 available

bno085.BNO085(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bno085_sensor

Create 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.

Parameters
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.
Returns

bno085_sensor bno085_sensor object.

bno085.BNO085().enable(report="rotation", interval_ms=100) -> bool

Enable a sensor report stream.

Parameters
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

Read the next matching report.

Parameters
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

Read fused orientation as quaternion fields.

Parameters
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

Read accelerometer values.

Parameters
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

Read gyroscope values.

Parameters
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

Read magnetic-field values.

Parameters
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

Read acceleration with gravity removed.

Parameters
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

Read gravity vector values.

Parameters
Name Type Pass as Required Description
timeout_ms int positional or keyword No Optional value. Defaults to 100.

bno085.BNO085().reset() -> bool

Send a soft-reset command to the sensor hub.

bno085.BNO085().info() -> dict

Return I2C and transport state.

bno085.BNO085().close() -> bool

Release the active I2C device and close this object.

bno085.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bool

Initialize a BNO085 sensor on I2C.

Parameters
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.
Returns

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

Enable a BNO085 sensor report.

Parameters
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.
Returns

bool True when the Set Feature command is accepted by the I2C transport.

bno085.read(report: str = None, timeout_ms: int = None) -> dict

Read the next matching BNO085 report.

Parameters
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.
Returns

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

Read a rotation-vector quaternion report.

Parameters
Name Type Pass as Required Description
timeout_ms int positional or keyword No Optional timeout in milliseconds. Defaults to 100.
Returns

dict Dict with quaternion fields ``i``, ``j``, ``k``, ``real``, ``w``, and status metadata.

bno085.accel(timeout_ms: int = None) -> dict

Read an accelerometer report.

Parameters
Name Type Pass as Required Description
timeout_ms int positional or keyword No Optional timeout in milliseconds. Defaults to 100.
Returns

dict Dict with ``x``, ``y``, ``z`` and ``x_mps2``, ``y_mps2``, ``z_mps2``.

bno085.gyro(timeout_ms: int = None) -> dict

Read a calibrated gyroscope report.

Parameters
Name Type Pass as Required Description
timeout_ms int positional or keyword No Optional timeout in milliseconds. Defaults to 100.
Returns

dict Dict with ``x``, ``y``, ``z`` and ``x_rad_s``, ``y_rad_s``, ``z_rad_s``.

bno085.magnetic(timeout_ms: int = None) -> dict

Read a calibrated magnetic-field report.

Parameters
Name Type Pass as Required Description
timeout_ms int positional or keyword No Optional timeout in milliseconds. Defaults to 100.
Returns

dict Dict with ``x``, ``y``, ``z`` and ``x_uT``, ``y_uT``, ``z_uT``.

bno085.linear_accel(timeout_ms: int = None) -> dict

Read linear acceleration with gravity removed.

Parameters
Name Type Pass as Required Description
timeout_ms int positional or keyword No Optional timeout in milliseconds. Defaults to 100.
Returns

dict Dict with ``x``, ``y``, ``z`` and meter-per-second-squared fields.

bno085.gravity(timeout_ms: int = None) -> dict

Read the gravity vector.

Parameters
Name Type Pass as Required Description
timeout_ms int positional or keyword No Optional timeout in milliseconds. Defaults to 100.
Returns

dict Dict with ``x``, ``y``, ``z`` and meter-per-second-squared fields.

bno085.reset() -> bool

Send a soft-reset command to the BNO085 sensor hub.

Returns

bool True when the reset packet is written.

bno085.info() -> dict

Return BNO085 module state.

Returns

dict Dict with initialization state, I2C settings, reset state, and transport type.