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
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
25 time.sleep(0.5)
26 print("Acceleration:")
27 accel_x, accel_y, accel_z = bno.acceleration # pylint:disable=no-member
28 print("X: %0.6f Y: %0.6f Z: %0.6f m/s^2" % (accel_x, accel_y, accel_z))
29 print("")
30
31 print("Gyro:")
32 gyro_x, gyro_y, gyro_z = bno.gyro # pylint:disable=no-member
33 print("X: %0.6f Y: %0.6f Z: %0.6f rads/s" % (gyro_x, gyro_y, gyro_z))
34 print("")
35
36 print("Magnetometer:")
37 mag_x, mag_y, mag_z = bno.magnetic # pylint:disable=no-member
38 print("X: %0.6f Y: %0.6f Z: %0.6f uT" % (mag_x, mag_y, mag_z))
39 print("")
40
41 print("Rotation Vector Quaternion:")
42 quat_i, quat_j, quat_k, quat_real = bno.quaternion # pylint:disable=no-member
43 print(
44 "I: %0.6f J: %0.6f K: %0.6f Real: %0.6f" % (quat_i, quat_j, quat_k, quat_real)
45 )
46 print("")