Simple test

Ensure your device works with this simple test.

examples/bno055_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5
 6import board
 7
 8import adafruit_bno055
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12sensor = adafruit_bno055.BNO055_I2C(i2c)
13
14# If you are going to use UART uncomment these lines
15# uart = board.UART()
16# sensor = adafruit_bno055.BNO055_UART(uart)
17
18last_val = 0xFFFF
19
20
21def temperature():
22    global last_val  # noqa: PLW0603
23    result = sensor.temperature
24    if abs(result - last_val) == 128:
25        result = sensor.temperature
26        if abs(result - last_val) == 128:
27            return 0b00111111 & result
28    last_val = result
29    return result
30
31
32while True:
33    print(f"Temperature: {sensor.temperature} degrees C")
34    """
35    print(
36        "Temperature: {} degrees C".format(temperature())
37    )  # Uncomment if using a Raspberry Pi
38    """
39    print(f"Accelerometer (m/s^2): {sensor.acceleration}")
40    print(f"Magnetometer (microteslas): {sensor.magnetic}")
41    print(f"Gyroscope (rad/sec): {sensor.gyro}")
42    print(f"Euler angle: {sensor.euler}")
43    print(f"Quaternion: {sensor.quaternion}")
44    print(f"Linear acceleration (m/s^2): {sensor.linear_acceleration}")
45    print(f"Gravity (m/s^2): {sensor.gravity}")
46    print()
47
48    time.sleep(1)

Raspberry PI I2C GPIO Simpletest

This example demonstrates how to instantiate the Adafruit BNO055 Sensor using this library and just the I2C bus number.

examples/bno055_i2c-gpio_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example demonstrates how to instantiate the
 6Adafruit BNO055 Sensor using this library and just
 7the I2C bus number.
 8This example will only work on a Raspberry Pi
 9and does require the i2c-gpio kernel module to be
10installed and enabled. Most Raspberry Pis will
11already have it installed, however most do not
12have it enabled. You will have to manually enable it
13"""
14
15import time
16
17from adafruit_extended_bus import ExtendedI2C as I2C
18
19import adafruit_bno055
20
21# To enable i2c-gpio, add the line `dtoverlay=i2c-gpio` to /boot/config.txt
22# Then reboot the pi
23
24# Create library object using our Extended Bus I2C port
25# Use `ls /dev/i2c*` to find out what i2c devices are connected
26i2c = I2C(1)  # Device is /dev/i2c-1
27sensor = adafruit_bno055.BNO055_I2C(i2c)
28
29last_val = 0xFFFF
30
31
32def temperature():
33    global last_val  # noqa: PLW0603
34    result = sensor.temperature
35    if abs(result - last_val) == 128:
36        result = sensor.temperature
37        if abs(result - last_val) == 128:
38            return 0b00111111 & result
39    last_val = result
40    return result
41
42
43while True:
44    print(f"Temperature: {temperature()} degrees C")
45    print(f"Accelerometer (m/s^2): {sensor.acceleration}")
46    print(f"Magnetometer (microteslas): {sensor.magnetic}")
47    print(f"Gyroscope (rad/sec): {sensor.gyro}")
48    print(f"Euler angle: {sensor.euler}")
49    print(f"Quaternion: {sensor.quaternion}")
50    print(f"Linear acceleration (m/s^2): {sensor.linear_acceleration}")
51    print(f"Gravity (m/s^2): {sensor.gravity}")
52    print()
53
54    time.sleep(1)