Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compass mode example #128

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/bno055_compass_mode.py
Original file line number Diff line number Diff line change
@@ -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)