Rather than using MakeCode, it is also possible to switch your Circuit Playground Express into CircuitPython mode with one single press of the reset button in the middle of the board.
In this example, we'll learn how to use CircuitPython to control each monster.
Getting Familiar
CircuitPython is a programming language based on Python, one of the fastest growing programming languages in the world. It is specifically designed to simplify experimenting and learning to code on low-cost microcontroller boards.
CircuitPython is easiest to use within 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.
import time from adafruit_crickit import crickit from adafruit_circuitplayground.express import cpx # Create three servos on Crickit def dance_monster1(): crickit.servo_1.angle = 80 time.sleep(0.100) crickit.servo_1.angle = 100 def dance_monster2(): crickit.servo_2.angle = 80 time.sleep(0.100) crickit.servo_2.angle = 100 def dance_monster3(): crickit.servo_3.angle = 80 time.sleep(0.100) crickit.servo_3.angle = 100 def dance_monster4(): crickit.servo_4.angle = 80 time.sleep(0.100) crickit.servo_4.angle = 100 while True: if cpx.light < 1000: dance_monster1() if cpx.light < 1000: dance_monster2() if cpx.shake: dance_monster3() time.sleep(1.5)
Uploading
Make sure you've connected the Circuit Playground Express to your computer and have Mu open and connected to your board.
Once the 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
.
Troubleshooting
Problem: My Circuit Playground Express isn't recognized by Mu!
Solution: Make sure your board is set up with CircuitPython, which has the Circuit Playground Express show up as a flash drive named CIRCUITPY when you connect the CPX to your computer. If it is showing up as CPLAYBOOT on your computer, you can follow the steps in this guide to ensure CircuitPython is loaded and you see the CIRCUITPY drive.
Problem: My servo isn't moving!
Solution: Check that the switch on CRICKIT is set to "ON".
Problem: My servo still isn't moving!
Solution: Make sure you've updated your Circuit Playground Express with the latest special 'seesaw' version of the CPX firmware. This guide will show you how.
Page last edited March 08, 2024
Text editor powered by tinymce.