From 5df17344d9c8679f5a0530fa1a8b5dc42f56607d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 26 Nov 2024 12:57:02 -0600 Subject: [PATCH] compass mode example --- examples/bno055_compass_mode.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/bno055_compass_mode.py diff --git a/examples/bno055_compass_mode.py b/examples/bno055_compass_mode.py new file mode 100644 index 0000000..1791e89 --- /dev/null +++ b/examples/bno055_compass_mode.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT +import math +import time +import board + +import adafruit_bno055 + +i2c = board.I2C() + +sensor = adafruit_bno055.BNO055_I2C(i2c) + +# Set the sensor to compass mode +sensor.mode = adafruit_bno055.COMPASS_MODE + +while True: + values = sensor.magnetic + print("Heading: " + str(180 + math.atan2(values[1], values[0]) * 180 / math.pi)) + time.sleep(1)