Simple test

Ensure your device works with this simple test.

examples/bno08x_simpletest.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4import time
 5
 6import board
 7import busio
 8
 9from adafruit_bno08x import (
10    BNO_REPORT_ACCELEROMETER,
11    BNO_REPORT_GYROSCOPE,
12    BNO_REPORT_MAGNETOMETER,
13    BNO_REPORT_ROTATION_VECTOR,
14)
15from adafruit_bno08x.i2c import BNO08X_I2C
16
17i2c = busio.I2C(board.SCL, board.SDA, frequency=400000)
18bno = BNO08X_I2C(i2c)
19
20bno.enable_feature(BNO_REPORT_ACCELEROMETER)
21bno.enable_feature(BNO_REPORT_GYROSCOPE)
22bno.enable_feature(BNO_REPORT_MAGNETOMETER)
23bno.enable_feature(BNO_REPORT_ROTATION_VECTOR)
24
25while True:
26    time.sleep(0.5)
27    print("Acceleration:")
28    accel_x, accel_y, accel_z = bno.acceleration
29    print("X: %0.6f  Y: %0.6f Z: %0.6f  m/s^2" % (accel_x, accel_y, accel_z))
30    print("")
31
32    print("Gyro:")
33    gyro_x, gyro_y, gyro_z = bno.gyro
34    print("X: %0.6f  Y: %0.6f Z: %0.6f rads/s" % (gyro_x, gyro_y, gyro_z))
35    print("")
36
37    print("Magnetometer:")
38    mag_x, mag_y, mag_z = bno.magnetic
39    print("X: %0.6f  Y: %0.6f Z: %0.6f uT" % (mag_x, mag_y, mag_z))
40    print("")
41
42    print("Rotation Vector Quaternion:")
43    quat_i, quat_j, quat_k, quat_real = bno.quaternion
44    print("I: %0.6f  J: %0.6f K: %0.6f  Real: %0.6f" % (quat_i, quat_j, quat_k, quat_real))
45    print("")