Skip to content

Commit 271e4a4

Browse files
authored
Merge pull request #741 from makermelissa/master
Adding Tilt Demo using BNO055 and PCA9685 for MagPi
2 parents 4eb716a + 0f7cfc1 commit 271e4a4

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
In this Demo we will drive two servos based on the Tilt along the Y and Z axis
3+
of the BNO055 9-Degrees of Freedom IMU Sensor. This could easily be extended
4+
to drive servos on all three axis as well as use a host of other information
5+
including lateral acceleration.
6+
"""
7+
8+
import board
9+
import busio
10+
from adafruit_servokit import ServoKit
11+
import adafruit_bno055
12+
13+
# Set channels to the number of servo channels on your kit.
14+
kit = ServoKit(channels=16)
15+
16+
# Setup the BNO055 to read data
17+
i2c = busio.I2C(board.SCL, board.SDA)
18+
sensor = adafruit_bno055.BNO055(i2c)
19+
20+
while True:
21+
# Get the Euler angles from the BNO055
22+
(x, y, z) = sensor.euler
23+
24+
# Euler angles are between -180 and 180
25+
# We want to translate them to the Servo angles between 0-180
26+
try:
27+
kit.servo[0].angle = (y + 180) / 2
28+
kit.servo[1].angle = (z + 180) / 2
29+
except ValueError:
30+
# Pass on any values that are out of range
31+
pass

0 commit comments

Comments
 (0)