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
 5import board
 6import adafruit_bno055
 7
 8
 9i2c = board.I2C()  # uses board.SCL and board.SDA
10# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
11sensor = adafruit_bno055.BNO055_I2C(i2c)
12
13# If you are going to use UART uncomment these lines
14# uart = board.UART()
15# sensor = adafruit_bno055.BNO055_UART(uart)
16
17last_val = 0xFFFF
18
19
20def temperature():
21    global last_val  # pylint: disable=global-statement
22    result = sensor.temperature
23    if abs(result - last_val) == 128:
24        result = sensor.temperature
25        if abs(result - last_val) == 128:
26            return 0b00111111 & result
27    last_val = result
28    return result
29
30
31while True:
32    print("Temperature: {} degrees C".format(sensor.temperature))
33    """
34    print(
35        "Temperature: {} degrees C".format(temperature())
36    )  # Uncomment if using a Raspberry Pi
37    """
38    print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
39    print("Magnetometer (microteslas): {}".format(sensor.magnetic))
40    print("Gyroscope (rad/sec): {}".format(sensor.gyro))
41    print("Euler angle: {}".format(sensor.euler))
42    print("Quaternion: {}".format(sensor.quaternion))
43    print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
44    print("Gravity (m/s^2): {}".format(sensor.gravity))
45    print()
46
47    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
16from adafruit_extended_bus import ExtendedI2C as I2C
17import adafruit_bno055
18
19# To enable i2c-gpio, add the line `dtoverlay=i2c-gpio` to /boot/config.txt
20# Then reboot the pi
21
22# Create library object using our Extended Bus I2C port
23# Use `ls /dev/i2c*` to find out what i2c devices are connected
24i2c = I2C(1)  # Device is /dev/i2c-1
25sensor = adafruit_bno055.BNO055_I2C(i2c)
26
27last_val = 0xFFFF
28
29
30def temperature():
31    global last_val  # pylint: disable=global-statement
32    result = sensor.temperature
33    if abs(result - last_val) == 128:
34        result = sensor.temperature
35        if abs(result - last_val) == 128:
36            return 0b00111111 & result
37    last_val = result
38    return result
39
40
41while True:
42    print("Temperature: {} degrees C".format(temperature()))
43    print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
44    print("Magnetometer (microteslas): {}".format(sensor.magnetic))
45    print("Gyroscope (rad/sec): {}".format(sensor.gyro))
46    print("Euler angle: {}".format(sensor.euler))
47    print("Quaternion: {}".format(sensor.quaternion))
48    print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
49    print("Gravity (m/s^2): {}".format(sensor.gravity))
50    print()
51
52    time.sleep(1)