CircuitPython for Continuous Servo Motors

You can learn the basics of CircuitPython with Circuit Playground Express here.

With the special Crickit support in CircuitPython, it saves you tons of code and makes it really fast to get started. 

For in-depth information on using servo motors with CircuitPython, see this page

Only the Feather Crickit, Crickit HAT and the Crickit for Circuit Playground Express support CircuitPython, the micro:bit does not support CircuitPython at present. There is no Crickit support in programming the micro:bit in MicroPython which is different than CircuitPython.

Running the Continuous Servo Like a Continuous DC Motor

Here is a simple CircuitPython program that will run one servo connected to Servo 1 (as shown at the top right of this page) at full speed (100%):

Download: file
import time
from adafruit_crickit import crickit

# Create one continuous servo on crickit servo port #1
servo = crickit.continuous_servo_1

servo.throttle = 1.0

while True:
    time.sleep(0.1)  # do nothing!

Running Two Continuous Servos on a Chassis

For two continuous servos back to back on a robot chassis, run them forward at full speed by running Servo 1 at 100% and Servo 2 at -100% for 2 seconds then stop:

Download: file
import time
from adafruit_crickit import crickit

# Create one continuous servo on crickit servo port #1
left_wheel = crickit.continuous_servo_1
# Create one continuous servo on crickit servo port #2
right_wheel = crickit.continuous_servo_2


while True:
    # Since the wheels are back-to-back
    # they have to have opposite rotation direections!
    left_wheel.throttle = 1.0
    right_wheel.throttle = -1.0

    time.sleep(2)  # move for 2 seconds...
    
    # Then stop both wheels
    left_wheel.throttle = 0
    right_wheel.throttle = 0

    time.sleep(2)  # stop for two seconds...
    # and repeat!

Mismatched Wheel Speeds

Even continuous servos from the same manufacturer and the same type may rotate at slightly different speeds when set to the exact same speed.

There is a small screw setting in the servo body, unlike standard servos (see picture below). Using a small screwdriver, carefully adjust a servo, say one set to throttle equals zero, to have the motor stopped at that speed.

makecode_cont-servo.jpg
A small continuous rotation servo bot with back to back servos. See the motor adjustment screws next to the wires for speed adjustment.
This guide was first published on Jul 04, 2018. It was last updated on Jul 04, 2018.
This page (CircuitPython) was last updated on May 26, 2020.