adafruit_servokit

CircuitPython helper library for the PWM/Servo FeatherWing, Shield and Pi HAT and Bonnet kits.

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_servokit.ServoKit(*, channels, i2c=None, address=64, reference_clock_speed=25000000, frequency=50)

Class representing an Adafruit PWM/Servo FeatherWing, Shield or Pi HAT and Bonnet kits.

Automatically uses the I2C bus on a Feather, Metro or Raspberry Pi.

Initialise the PCA9685 chip at address.

The internal reference clock is 25MHz but may vary slightly with environmental conditions and manufacturing variances. Providing a more precise reference_clock_speed can improve the accuracy of the frequency and duty_cycle computations. See the calibration.py example in the PCA9685 GitHub repo for how to derive this value by measuring the resulting pulse widths.

Parameters:
  • channels (int) – The number of servo channels available. Must be 8 or 16. The FeatherWing has 8 channels. The Shield, HAT, and Bonnet have 16 channels.
  • address (int) – The I2C address of the PCA9685. Default address is 0x40.
  • reference_clock_speed (int) – The frequency of the internal reference clock in Hertz. Default reference clock speed is 25000000.
  • frequency (int) – The overall PWM frequency of the PCA9685 in Hertz. Default frequency is 50.
continuous_servo

ContinuousServo controls for continuous rotation servos.

This FeatherWing example rotates a continuous rotation servo on channel 0 forward for one second, then backward for one second, and then stops the rotation.

import time
from adafruit_servokit import ServoKit

kit = ServoKit(channels=8)

kit.continuous_servo[0].throttle = 1
time.sleep(1)
kit.continuous_servo[0].throttle = -1
time.sleep(1)
kit.continuous_servo[0].throttle = 0
servo

Servo controls for standard servos.

This FeatherWing example rotates a servo on channel 0 to 180 degrees for one second, and then returns it to 0 degrees.

import time
from adafruit_servokit import ServoKit

kit = ServoKit(channels=8)

kit.servo[0].angle = 180
time.sleep(1)
kit.servo[0].angle = 0