File tree Expand file tree Collapse file tree
Tilt_Controlled_Servo_Driver Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments