General example code for using the different hardware components on Adafruit's Circuit Playground Express (CPX).
Some of these examples require a CircuitPython package from Adafruit's github site. Check the comments of each sample for specific package locations.
To use these examples you must be running CircuitPython on your board. Download the latest CP release from Adafruit. Once you have CP running, copy the example code to your CPX and rename the file main.py.
-
accelerometer.py
Demonstrates the use of the lis3dh with a simple "level" program. -
accelerometer_magnitude.py Demonstrates the use of the lis3dh to generate the general overall magnitude of acceleration via squareroot of the sum of x, y, & z's squares.
-
buttons.py
Demonstrates the use of buttons to drive conditional statements. -
max_light_reading.py
Demonstrates the use of the photoresistor to read light values. -
neopixel_scan.py
Demonstrates the use of neopixels with a simple Cylon / KITT animation -
speaker_play_wav.py
Demonstrates using the speaker to play a sound file. -
switch.py
Demonstrates the use of the slide switch in conditional statements. -
thermistor.py
Demonstrates the use of thermistor with a simple temperature gauge. -
USAscan.py Demonstrates the use of the neopixels on Adafruit's Circuit Python. Simulates Cylon scanning with USA twist.
The REPL (Read-Eval-Print-Loop) that comes as part of the CircuitPython installation can be thought of as an interactive shell for CircuitPython. It's useful for seeing board output (e.g. print statements) and for issuing commands directly to the board.
These instructions are for Mac users though the connection should be similar for other platforms.
- Start Terminal
- Connect your CPX to USB on your computer
- Enter the following command. ls /dev/tty.usb*
- Identify the USB port the CPX is connected to
- Enter the following command. screen /dev/ 115200 (e.g. screen /dev/tty.usbmodem1431 115200)
- You should see the command prompt >>> (if not, try pressing ctrl-c)
- Connect to the REPL (above)
- Press ctrl-d to enter console mode and restart the program on your CPX
- Your program should run from the beginning and any output (print() statements) should print here.
- Connect to the REPL (above)
- Press ctrl-c to break out of any running programs and enter interactive mode.
- At the prompt '>>>' enter the CircuitPython commands. Note: functions, loops, and conditional statements can be entered on multiple lines. To enter the multiline edit mode just starting typing your multi-line command ending with ':'. Once you've completed the code block move cursor to start of blank line and hit enter twice. Loops and conditional statements will execute immediately. functions are defined and can be called using their names.