Getting Familiar

This project uses CircuitPython, which works best if using the Mu Editor. If you haven't previously used Mu, this guide will get you started.

If you haven't used Circuit Playground Express with CRICKIT before, make sure you've updated it with the latest special 'seesaw' version of the CPX firmware. This guide will show you how.

Once you have completed this step you're ready to move on.

Let's upload some code! 

The sample code for this project is taken from the Make it Move with CRICKIT master guide, which demonstrates all the ways that CRICKIT can be used.

This guide is an excellent resource for exploring CRICKIT further. Prefer to use a continuous rotation servo instead of a DC motor? No problem, the Make it Move with CRICKIT guide can show you how. 

Sample Code

Make sure you've connected the Circuit Playground Express to your computer and have Mu open.

Copy and paste this code into your Mu editor window.

Download: file
    from digitalio import DigitalInOut, Pull, Direction
from adafruit_crickit import crickit
import board
 
# Two onboard CPX buttons for input (low level saves memory)
button_a = DigitalInOut(board.BUTTON_A)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN

button_b = DigitalInOut(board.BUTTON_B)
button_b.direction = Direction.INPUT
button_b.pull = Pull.DOWN 

# Create one motor on seesaw motor port #1
motor = crickit.dc_motor_1

while True:
    if button_a.value:
        print("Button A pressed, go!")
        motor.throttle = 1.0  # full speed!

    if button_b.value:
        print("Button B pressed, stop!")
        motor.throttle = 0    # stop!
  

This snippet of code gives Circuit Playground Express two simple instructions:

  1. Press the A button to turn motor ON
  2. Press B button to turn motor OFF

Once this code is copied into Mu, press the Save button - your code should be saved to the CIRCUITPY disk drive (which appears when the Circuit Playground Express is plugged into your computer) as code.py.

It's important to name your file code.py! If you name your program something else, like zoetrope.py, the Circuit Playground Express won't know to automatically run it.

Making Changes

You will likely notice that by default this sample code spins your motor very fast. Almost too fast to see the animation clearly.

Adabot's sautering stride becomes much more visible at a slower rotational speed. We can adjust this by changing the motor.throttle value in the code from = 1.0 (full speed) to something like 0.5 (half speed), then clicking "Save" again.

You may have to adjust it several times down, up, and down. This is where Mu makes it super easy to "dial-in" on the perfect value for the speed. 

Experiment!

Have fun making changes to the code and observing what effect it has. For example, you aren't stuck to only using positive numbers. A negative motor.throttle value will make Adabot moonwalk backwards rather than walking forwards!

If you'd like to change the direction permanently without changing the code, unscrew the terminals where the motor connects to Crickit and switch the position of the red and black wires.

Try dropping in each of the strips and watching them animate. If can be fun to adjust the motor.throttle for each to find the optimal viewing speed for each.

This guide was first published on Jul 12, 2018. It was last updated on Jul 12, 2018.

This page (Coding with CircuitPython) was last updated on Oct 30, 2020.

Text editor powered by tinymce.