motor_pca9685_continuous_servo.py
1 import time 2 3 from board import SCL, SDA 4 import busio 5 6 # Import the PCA9685 module. Available in the bundle and here: 7 # https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 8 from adafruit_pca9685 import PCA9685 9 10 from adafruit_motor import servo 11 12 i2c = busio.I2C(SCL, SDA) 13 14 # Create a simple PCA9685 class instance. 15 pca = PCA9685(i2c) 16 # You can optionally provide a finer tuned reference clock speed to improve the accuracy of the 17 # timing pulses. This calibration will be specific to each board and its environment. See the 18 # calibration.py example in the PCA9685 driver. 19 # pca = PCA9685(i2c, reference_clock_speed=25630710) 20 pca.frequency = 50 21 22 # The pulse range is 750 - 2250 by default. 23 servo7 = servo.ContinuousServo(pca.channels[7]) 24 # If your servo doesn't stop once the script is finished you may need to tune the 25 # reference_clock_speed above or the min_pulse and max_pulse timings below. 26 # servo7 = servo.ContinuousServo(pca.channels[7], min_pulse=750, max_pulse=2250) 27 28 print("Forwards") 29 servo7.throttle = 1 30 time.sleep(1) 31 32 print("Backwards") 33 servo7.throttle = -1 34 time.sleep(1) 35 36 print("Stop") 37 servo7.throttle = 0 38 39 pca.deinit()