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.
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.
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:
- Press the A button to turn motor ON
- 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.
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!
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.
Page last edited March 08, 2024
Text editor powered by tinymce.