Skip to content

Commit 9bc2e8b

Browse files
authored
Merge pull request #128 from FoamyGuy/compass_mode_example
compass mode example
2 parents 27a28af + 5df1734 commit 9bc2e8b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/bno055_compass_mode.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
import math
4+
import time
5+
import board
6+
7+
import adafruit_bno055
8+
9+
i2c = board.I2C()
10+
11+
sensor = adafruit_bno055.BNO055_I2C(i2c)
12+
13+
# Set the sensor to compass mode
14+
sensor.mode = adafruit_bno055.COMPASS_MODE
15+
16+
while True:
17+
values = sensor.magnetic
18+
print("Heading: " + str(180 + math.atan2(values[1], values[0]) * 180 / math.pi))
19+
time.sleep(1)

0 commit comments

Comments
 (0)