User Manual
This example is similar to the 1 servo example, but instead of accessing the crickit.servo_1 object directly, we'll make a
list called servos that contains 4 servo objects with
servos = (crickit.servo_1, crickit.servo_2, crickit.servo_3, crickit.servo_4)
Then we can access the individual using servo[0].angle = 90 or iterate through them as we do in the loop. You don't
have
to do it this way, but its very compact and doesn't take a lot of code lines to create all 4 servos at once!
Min/Max Pulse control
Originally servos were defined to use 1.0 millisecond to 2.0 millisecond pulses, at 50 Hz to set the 0 and 180 degree
locations. However, as more companies started making servos they changed the pulse ranges to 0.5ms to 2.5ms or
even bigger ranges. So, not all servos have their full range at thoe 'standard' pulse widths. You can easily tweak your
code to change the min and max pulse widths, which will let your servo turn more left and right. But don't set the
widths too small/large or you can hit the hard stops of the servo which could damage it, so try tweaking the numbers
slowly until you get a sense of what the limits are for your motor.
All you need to do is add a line at the top of your code like this
crickit.servo_1.set_pulse_width_range(min_pulse=500, max_pulse=2500)
The above is for Crickit Servo #1, you'll need to duplicate and adjust for all other servos, but that way you can
customize the range uniquely per servo!
Here we've change the minimum pulse from the default ~750 microseconds to 500, and the default maximum pulse
from 2250 microseconds to 2500. Again, each servo differs. Some experimentation may be required!
import time
from adafruit_crickit import crickit
print("4 Servo demo!")
# make a list of all the servos
servos = (crickit.servo_1, crickit.servo_2, crickit.servo_3, crickit.servo_4)
while True:
# Repeat for all 4 servos
for my_servo in servos:
# Do the wave!
print("Moving servo #", servos.index(my_servo)+1)
my_servo.angle = 0 # right
time.sleep(0.25)
my_servo.angle = 90 # middle
time.sleep(0.25)
my_servo.angle = 180 # left
time.sleep(0.25)
my_servo.angle = 90 # middle
time.sleep(0.25)
my_servo.angle = 0 # right
One thing to watch for is that if you use a list like this, servo[0] is the name of the Servo #1 and servo[3] is
Servo #4!
© Adafruit Industries
https://learn.adafruit.com/adafruit-crickit-creative-robotic-interactive-
construction-kit
Page 91 of 201










