Skip to content

Commit c0685a9

Browse files
committed
Added demo for MagPi Article
1 parent 4eb716a commit c0685a9

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 time
9+
import board
10+
import busio
11+
from adafruit_servokit import ServoKit
12+
import adafruit_bno055
13+
14+
# Set channels to the number of servo channels on your kit.
15+
kit = ServoKit(channels=16)
16+
17+
# Setup the BNO055 to read data
18+
i2c = busio.I2C(board.SCL, board.SDA)
19+
sensor = adafruit_bno055.BNO055(i2c)
20+
21+
while True:
22+
# Get the Euler angles from the BNO055
23+
(x, y, z) = sensor.euler
24+
25+
# Euler angles are between -180 and 180
26+
# We want to translate them to the Servo angles between 0-180
27+
try:
28+
kit.servo[0].angle = (y + 180) / 2
29+
kit.servo[1].angle = (z + 180) / 2
30+
except ValueError:
31+
# Pass on any values that are out of range
32+
pass

0 commit comments

Comments
 (0)