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