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()
10sensor = adafruit_bno055.BNO055_I2C(i2c)
11
12# If you are going to use UART uncomment these lines
13# uart = board.UART()
14# sensor = adafruit_bno055.BNO055_UART(uart)
15
16last_val = 0xFFFF
17
18
19def temperature():
20    global last_val  # pylint: disable=global-statement
21    result = sensor.temperature
22    if abs(result - last_val) == 128:
23        result = sensor.temperature
24        if abs(result - last_val) == 128:
25            return 0b00111111 & result
26    last_val = result
27    return result
28
29
30while True:
31    print("Temperature: {} degrees C".format(sensor.temperature))
32    """
33    print(
34        "Temperature: {} degrees C".format(temperature())
35    )  # Uncomment if using a Raspberry Pi
36    """
37    print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
38    print("Magnetometer (microteslas): {}".format(sensor.magnetic))
39    print("Gyroscope (rad/sec): {}".format(sensor.gyro))
40    print("Euler angle: {}".format(sensor.euler))
41    print("Quaternion: {}".format(sensor.quaternion))
42    print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
43    print("Gravity (m/s^2): {}".format(sensor.gravity))
44    print()
45
46    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)