Let's look at some specific examples using the BNO055 and BNO085.

NOTE: These example assume the i2c-gpio overlay has been enabled and configured with the following line added to /boot/config.txt:

dtoverlay=i2c-gpio,i2c_gpio_sda=16,i2c_gpio_scl=20,bus=8

Software I2C with BNO055

Let's try using the software I2C port with the BNO055.

Wiring used for BNO055 example. Note the pins used for SCL and SDA.

We again use the example from the BNO055 library. However, we make the following modifications to use the software I2C port:

import time
import board
import adafruit_bno055
from adafruit_extended_bus import ExtendedI2C as I2C

i2c=I2C(8)
sensor = adafruit_bno055.BNO055_I2C(i2c)

Only the top part of the code listing is shown above. The remainder of the example code is unchanged.

Now running the updated example:

pi@raspberrypi:~ $ python3 bno055_simpletest.py 
Temperature: 23 degrees C
Accelerometer (m/s^2): (0.0, 0.0, 0.0)
Magnetometer (microteslas): (38.5, -27.6875, -67.0625)
Gyroscope (rad/sec): (-0.002181661564992912, -0.001090830782496456, 0.00545415391248228)
Euler angle: (0.0, 0.0, 0.0)
Quaternion: (0.0, 0.0, 0.0, 0.0)
Linear acceleration (m/s^2): (0.0, 0.0, 0.0)
Gravity (m/s^2): (0.0, 0.0, 0.0)

Temperature: 23 degrees C
Accelerometer (m/s^2): (0.15, -0.34, 10.0)
Magnetometer (microteslas): (39.1875, -26.25, -65.0625)
Gyroscope (rad/sec): (-0.001090830782496456, 0.0, 0.0)
Euler angle: (0.0, 0.8125, 2.0625)
Quaternion: (0.99981689453125, -0.018310546875, -0.0072021484375, 0.0)
Linear acceleration (m/s^2): (-0.01, 0.01, 0.14)
Gravity (m/s^2): (0.14, -0.35000000000000003, 9.790000000000001)

Temperature: 23 degrees C
Accelerometer (m/s^2): (0.15, -0.33, 9.92)
Magnetometer (microteslas): (39.5625, -26.5625, -64.375)
Gyroscope (rad/sec): (-0.001090830782496456, -0.001090830782496456, 0.0)
Euler angle: (0.0, 0.8125, 2.0625)
Quaternion: (0.99981689453125, -0.018310546875, -0.0072021484375, 0.0)
Linear acceleration (m/s^2): (0.01, 0.02, 0.17)
Gravity (m/s^2): (0.14, -0.35000000000000003, 9.790000000000001)

The readings look good.

Software I2C with BNO085

Now to try using the software I2C port with the BNO085.

Wiring used for BNO085 example. Note the pins used for SCL and SDA.

Again to use the example from the BNO085 library. However, make the following modifications to use the software I2C port:

import time
import board
import busio
from adafruit_bno08x import (
    BNO_REPORT_ACCELEROMETER,
    BNO_REPORT_GYROSCOPE,
    BNO_REPORT_MAGNETOMETER,
    BNO_REPORT_ROTATION_VECTOR,
)
from adafruit_bno08x.i2c import BNO08X_I2C
from adafruit_extended_bus import ExtendedI2C as I2C

i2c=I2C(8)
bno = BNO08X_I2C(i2c)

Only the top part of the code listing is shown above. The remainder of the example code is unchanged.

Now running the updated example:

pi@raspberrypi:~ $ python3 bno08x_simpletest.py
Acceleration:
X: 0.078125  Y: 0.078125 Z: 9.542969  m/s^2

Gyro:
X: -0.001953  Y: 0.000000 Z: 0.000000 rads/s

Magnetometer:
X: 18.250000  Y: 31.312500 Z: -51.437500 uT

Rotation Vector Quaternion:
I: 0.005066  J: -0.002808 K: 0.271362  Real: 0.962463

Acceleration:
X: 0.078125  Y: 0.078125 Z: 9.582031  m/s^2

Gyro:
X: 0.000000  Y: 0.000000 Z: -0.003906 rads/s

Magnetometer:
X: 18.687500  Y: 32.000000 Z: -51.500000 uT

Rotation Vector Quaternion:
I: 0.005554  J: -0.002014 K: 0.267334  Real: 0.963623

Readings look good and (hopefully) it should continue running without hitting any errors.

This guide was first published on Oct 26, 2022. It was last updated on Mar 26, 2024.

This page (Example Fixes) was last updated on Mar 08, 2024.

Text editor powered by tinymce.