CircuitPython is a derivative of MicroPython designed for a particular set of Adafruit microcontroller boards, including the Circuit Playground Express. It's a new language and is currently in development, so there will be changes to it in the future, including many things to make programming your CPX even more incredibly easy!
CircuitPython looks for a file called
code.py, and runs the code within automatically. It makes getting started quite straightforward. CircuitPython also allows you to connect to a serial REPL which provides you with a way to see your code working live as you save your files. It also provides you with a prompt where you can enter lines of code and execute them immediately.
In this part of the guide, we're going to cover how to get CircuitPython installed on your Circuit Playground Express and you'll write a little CircuitPython yourself!
Installing CircuitPython is simple. Basically, you download the latest release of CircuitPython, double-tap the reset button to enter the bootloader on the CPX, drop the .uf2 file onto the board, and CircuitPython is installed. If this is the first time you've installed CircuitPython on your CPX, you only need to press the reset button once to ready the board for the installer.
For a thorough explanation, the Introduction to Circuit Playground Express guide offers a CircuitPython quick install walkthrough and, if desired, a CircuitPython detailed install walkthrough. Check them out if you need further information. They're really helpful!
Congratulations on installing CircuitPython onto your Circuit Playground Express! Way to go!
Once you've installed CircuitPython, you need to load the library. First, you'll want the latest release of the library bundle. Scroll down to "Downloads" and download the file starting with "adafruit-circuitpython-bundle-2.x" where 2.x is the most recent version of CircuitPython. It's currently 2.1! The file unzips into a folder called lib. Create a lib folder on your CIRCUITPY drive, and drag the adafruit_circuitplayground directory from the bundle lib folder to the newly created CIRCUITPY/lib folder.
You can also checkout the Adafruit Library Bundle Quick Start Guide for more information.
CircuitPython sends data to the computer connected to the Circuit Playground Express. You can see the output of print statements and any errors you encounter along the way by connecting to the serial REPL.
To get started with the serial REPL, check out the tutorial here: Serial Console (REPL). This covers setup on Mac, Linux and Windows.
Once you've gotten your serial connection, press
Ctrl+C then any key to enter the REPL. You should have a prompt that looks like this:
This is a Python prompt. Here you can type any python code and have it run.
Every programmer in every programming language starts with a piece of code that says, "Hello, World." We're going to say hello to something else. Next to that prompt, type:
Welcome to programming!
To learn more, take a look at the Introduction to Circuit Playground Express Circuit Python section. The guide covers all the basics and provides plenty of examples to try and learn from. Check it out!