To control the servo from CircuitPython we'll use its built in PWM, or pulse-width modulation, signal generation capabilities. Be sure to read the CircuitPython analog I/O guide for more details on PWM signals!
Before you get started it will help to read these guide pages for more background information on servo motors too:
Be sure your hardware is wired up as shown on the previous page, and your servo power supply is turned on (you might notice the servos jerk or move slightly when the power is turned on--that's normal!).
Next make sure you are running the latest version of Adafruit CircuitPython for your board, then connect to the board's serial REPL so you are at the CircuitPython >>> prompt.
Pick Your Programming Method - High or Low Level
There's two ways to control servos, one is lower-level - where you will control the PWM pin directly. And one is higher-level using the Motor Library
For typical non-continuous servo motors, control is best done with the high level adafruit_motor
library. The servo
module provides an excellent interface and is easy to understand.
You can read more about using that library in the guide CircuitPython Essentials on the CircuitPython Servo page.
Low level control involves working with the Pulse Width Modulation (PWM) directly which is rarely required.
The following pages discuss high and low level control of servos in CircuitPython.
Text editor powered by tinymce.