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:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Adafruit’s Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
Adafruit’s PCA9685 library: https://github.com/adafruit/Adafruit_CircuitPython_PCA9685
Adafruit’s Motor library: https://github.com/adafruit/Adafruit_CircuitPython_Motor
- class adafruit_servokit.ServoKit(*, channels: int, i2c: I2C | None = None, address: int = 64, reference_clock_speed: int = 25000000, frequency: int = 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 thecalibration.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.
i2c (~I2C) – The I2C bus to use. If not provided, the default I2C
board.I2C()
will be used.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
.
- property continuous_servo: _ContinuousServo¶
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
- property servo: _Servo¶
Servo
controls for standard servos.This FeatherWing example rotates a servo on channel
0
to180
degrees for one second, and then returns it to0
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