Start tinkering with the Circuit Playground Express | Opensource.com

Start tinkering with the Circuit Playground Express

Learn what you can do with these tiny gadgets and a bit of Python code.

Tools in a cloud
Image by : 
Opensource.com
x

Subscribe now

Get the highlights in your inbox every week.

I've been a gadget person as long as I can remember, so I was delighted when I discovered an Adafruit Circuit Playground Express (CPX) in the swag bag I got at PyConUS in May. I became fascinated with these little devices last year, when Nina Zakharenko highlighted them in her All Things Open presentation, Five Things You Didn't Know Python Could Do, with Python-powered earrings.

After finding one in my PyCon bag, I set out to learn more about these mesmerizing little devices. First, I attended a "how-to" session at one of the Open Spaces meetups at PyCon. But learning always requires hands-on practice, and that's what I did when I got home. I connected the CPX device to my Linux laptop with a USB-to-MicroUSB cable. The unit mounts just like any standard USB drive, listed as CIRCUITPY.

The CPX works on MacOS, Windows, and Linux (including Chromebooks). The device comes pre-loaded with code and some sound files. Adafruit's extremely well-written documentation answered most of my questions. I discovered the unit can be programmed on Linux three different ways: MakeCode, the Arduino IDE, and the Python-based CircuitPython, which I chose.

Adafruit provides excellent documentation for creating and editing CircuitPython code, which I found helpful. You can use a variety of editors (e.g., Emacs, Visual Studio Code, gedit), but Adafruit recommends the Mu Python editor, which I wrote about last year. I installed Mu on my system with pip3 install --user mu-editor. Then I opened a terminal and entered mu-editor. It asked me how to run Mu, and I chose Adafruit Circuit Python. Then I was able to look at the code that powers the CPX.

To open a connection between Mu and the CPX connected to your computer, press the Serial button in Mu. Then you can see any serial data from the CPX and edit it using Python's REPL shell.

Adafruit's programmers have written a library called adafruit_circuitplayground.express that enables CircuitPython to interact with the CPX board. To use it, add import adafruit.circuitplayground.express to your code. Or, to make it simpler, you can use the acronym cpx, shortening the code (as shown below) to from adafruit_circuitplayground.express import cpx.

The way you name your file is essential. The four options are code.txt, code.py, main.txt, and main.py. CircuitPython looks for the code files in that order and runs the first one it finds. Save the code to your CIRCUITPY drive each time you change it.

The main.py code included with a new CPX offers an example of the device's capabilities.

When you execute this code, the CPX displays beautiful, brightly colored LEDs whirling in a rainbow of colors. With my rudimentary knowledge, I could tweak a few settings, like increasing the brightness and turning on the TOUCH_PIANO capability, but other modifications were beyond my coding ability at this point.

Eager to do more, I wanted to find code snippets I could use as building blocks to learn. First, I reached out to Nina Zakharenko on Twitter and asked for some help. She recommended I contact Kattni Rembor, who pointed me to her GitHub repo and some code examples she wrote for the Chicago Linux User Group.

Each of these simple building blocks left me more confident in my Python journey. In addition to making lights blink, the CPX can also function as a sensor, and I wanted to try that. Here is code for a simple light sensor:

And here is the CPX with the D13 LED blinking:

I also discovered a way to create some fun for my grandson by making the CPX "come to life." I recorded a couple of .wav files with Audacity and saved them to the device. Then I wrote some simple code that utilized the A and B buttons on the device to make the CPX "talk" to him:

I've really enjoyed tinkering with the code to explore the CPX's capabilities. I am always looking for ways to make Python code come alive for students I teach. The CPX is a great way to help new users learn and enjoy coding and digital making. Another excellent resource for new users is Mike Barela's book Getting Started with Adafruit Circuit Playground Express. I found its information and examples very helpful as I was learning.

Get a Circuit Playground Express and start writing your own code. And then please share how you are using it in the comments.

About the author

Don Watkins - Educator, education technology specialist,  entrepreneur, open source advocate. M.A. in Educational Psychology, MSED in Educational Leadership, Linux system administrator, CCNA, virtualization using Virtual Box. Follow me at @Don_Watkins .