Motor Pump Examples - Adafruit Crickit with CPB

The following short Python programs demonstrate operation of DC motor driven air pumps using the Adafruit Crickit. The Adafruit Crickit for Circuit Playground Bluefruit is a baseboard providing motor drivers and other useful I/O for a Adafruit Circuit Playground Bluefruit. It communicates with the Bluefruit using the I2C bus. For more detailed notes on the software support, please see Quick Reference Guide - Adafruit Crickit with CPB.

Each example can be run by copying the program into code.py on the CIRCUITPY drive offered by the board. The text can be pasted directly from this page, or each file can be downloaded from the CircuitPython sample code folder on this site.

Related Pages

Pump Sequence

This sketch sequences through pumps attached to the motor and drive outputs.

Direct download: sequence_motor.py.

 1# crickit/sequence_motor.py
 2
 3# Demonstrate timed activation of several DC motors connected to the Crickit motor driver.
 4
 5# The Crickit has two motor outputs labeled 1 and 2.  Each has two screw
 6# terminals for the motor wires.
 7
 8# The Crickit has four drive outputs labeled 1 through 4.  Each has only two
 9# screw terminal, so each motor should be connected to the driver terminal and
10# also to +5V (located on the same terminal strip).
11
12# Related documentation:
13# http://docs.circuitpython.org/projects/crickit/en/latest/
14# http://docs.circuitpython.org/projects/seesaw/en/latest/
15# https://learn.adafruit.com/adafruit-crickit-creative-robotic-interactive-construction-kit
16
17# Course documentation:
18#   https://courses.ideate.cmu.edu/16-376/s2023/ref/text/code/crickit-intro.html
19#   https://courses.ideate.cmu.edu/16-376/s2023/ref/text/code/crickit-quickref.html
20#   https://courses.ideate.cmu.edu/16-376/s2023/ref/text/code/cpb-quickref.html
21
22
23# ----------------------------------------------------------------
24# Import standard Python modules.
25import time, math
26
27# Import the Bluefruit interface library.
28from adafruit_circuitplayground import cp
29
30# Import the Crickit interface library.
31from adafruit_crickit import crickit
32
33# ----------------------------------------------------------------
34# Enter the main event loop.
35
36while True:
37    print("motor 1 forward...")
38    crickit.dc_motor_1.throttle = 1   # full speed forward
39    cp.pixels[0] = (0, 127, 0)        # medium green
40    time.sleep(2)
41
42    print("motor 1 stop...")
43    crickit.dc_motor_1.throttle = 0   # stop
44    cp.pixels[0] = (32, 0, 0)         # dim red
45    time.sleep(1)
46
47    print("motor 2 forward...")
48    crickit.dc_motor_2.throttle = 1    # full speed forward
49    cp.pixels[1] = (0, 127, 0)         # medium green
50    time.sleep(2)
51
52    print("motor 2 stop...")
53    crickit.dc_motor_2.throttle = 0    # stop
54    cp.pixels[1] = (32, 0, 0)          # dim red
55    time.sleep(1)
56
57    # Please note that the drive output uses 'fraction' instead of 'throttle'.
58    print("drive 1 forward...")
59    crickit.drive_1.fraction = 1       # full speed forward
60    cp.pixels[2] = (0, 127, 0)         # medium green
61    time.sleep(2)
62
63    print("drive 1 stop...")
64    crickit.drive_1.fraction = 0       # stop
65    cp.pixels[2] = (32, 0, 0)          # dim red
66    time.sleep(2)
67
68    # this could continue with drive_2, drive_3, and drive_4 if needed
69    
70    # end of the sequence, it will now loop back from the start
71