/ examples / pca9685_servo.py
pca9685_servo.py
 1  # This example moves a servo its full range (180 degrees by default) and then back.
 2  
 3  from board import SCL, SDA
 4  import busio
 5  
 6  # Import the PCA9685 module.
 7  from adafruit_pca9685 import PCA9685
 8  
 9  # This example also relies on the Adafruit motor library available here:
10  # https://github.com/adafruit/Adafruit_CircuitPython_Motor
11  from adafruit_motor import servo
12  
13  i2c = busio.I2C(SCL, SDA)
14  
15  # Create a simple PCA9685 class instance.
16  pca = PCA9685(i2c)
17  pca.frequency = 50
18  
19  # To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to
20  # match the stall points of the servo.
21  # This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201
22  # servo7 = servo.Servo(pca.channels[7], min_pulse=580, max_pulse=2480)
23  # This is an example for the Micro Servo - High Powered, High Torque Metal Gear:
24  #   https://www.adafruit.com/product/2307
25  # servo7 = servo.Servo(pca.channels[7], min_pulse=600, max_pulse=2400)
26  # This is an example for the Standard servo - TowerPro SG-5010 - 5010:
27  #   https://www.adafruit.com/product/155
28  # servo7 = servo.Servo(pca.channels[7], min_pulse=600, max_pulse=2500)
29  # This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/1404
30  # servo7 = servo.Servo(pca.channels[7], min_pulse=600, max_pulse=2600)
31  
32  # The pulse range is 1000 - 2000 by default.
33  servo7 = servo.Servo(pca.channels[7])
34  
35  for i in range(180):
36      servo7.angle = i
37  for i in range(180):
38      servo7.angle = 180 - i
39  pca.deinit()