working with the adafruit circuit playground express using the raspberry pi 4

Attach the Circuit Playground Express

Physically and electrically attach the Adafruit Circuit Playground Express (CPE) to the Raspberry Pi 4 via one of its USB ports. It doesn’t matter if it’s USB 2 or USB 3. The CPE should begin to operate; a little green power light next to the micro USB port will light, and all 10 of its NeoPixel LEDs will turn on in a continuous counter-clockwise sequence, starting at the micro USB port. For an extra sanity check you can see if the Raspberry Pi can see the USB connection as a serial TTY device:

pi@raspberrypi:~ $ ls -AlFh /dev/ttyACM0 crw-rw---- 1 root dialout 166, 0 Jul 31 22:58 /dev/ttyACM0pi@raspberrypi:~ $

We’ll talk about the ttyACM0 device later on.

Download the Circuit Python Interpreter

We want to program the CPE using Python, but unfortunately the CPE doesn’t come with Python, or more specificly, Circuit Python installed. That means we’ll need to install the Circuit Python interpreter maintained by Adafruit. As of the date of this posting I’m using Circuit Python version 4.1.0 RC1. First let me list several key web locations you’ll want to remember.

  1. Circuit Python Git releases location – https://github.com/adafruit/circuitpython/releases
  2. Circuit Python download location – https://circuitpython.org/board/circuitplayground_express/

The first location has a full list, and is the area where all active development and support takes place. You can even download the Circuit Python interpreter for the CPE from there, although it’s a bit crowded to read, and thus find. Instead, go to 2, and select either the stable or the so-called unstable release. In our case, the RC1, or release candidate #1, is as good as stable. That will be the second selection on the right. Pick your language (it defaults to English) then download it into ~/Download in your login area on the Raspberry Pi. When I downloaded it the file name was adafruit-circuitpython-circuitplayground_express-en_US-4.1.0-rc.1.uf2. The file name will change over time, but the extension, uf2, will not.

Update 3 August

The official CircuitPython version 4.1.0 was released on 2 August 2019. Now when you go to the download site, 4.1 is the default download. When downloaded it will have the same file name, minus ‘-rc.1’, in the file name. Just be aware that over time these release versions will continue to increase, so adjust these instructions accordingly as you follow along.

Put the Circuit Playground Express in Bootloader Mode

Unlike the micro:bit, the CPE does not come with Adafruit’s equivalent to MicroPython, CircuitPython, installed. However it’s very easy to install it. With the CPE still connected to the Raspberry Pi 4 click the reset button ONCE. If your CPE is like one of mine, then a new file device named CPLAYBOOT will appear on your Raspbian desktop. You’ll also get  a dialog asking if you want to open or execute. Chose to open, or if you close the dialog, double click on the CPLAYBOOT device on the desktop.

Once the CPLAYBOOT file explorer is open, this is what you’ll see.

Now open up another file explorer to where you downloaded the CircuitPython interpreter file to.

Drag that file, ending in UF2, from the download area and drop it onto the CPE. The CPE will briefly reset after the file is copied, and then reappear as a different attached file device named CIRCUITPY.

At this point, the only lit LED is the power on LED to the left of the micro USB socket. On the CIRCUITPY device there is an empty lib folder and a text file. Opening the text file shows the following single line:

Adafruit CircuitPython 4.1.0-rc.1 on 2019-07-19; Adafruit CircuitPlayground Express with samd21g18

That single line shows the release version and the build date. That should match what you copied onto the CPE earlier, and it shows that the CPE booted into the interpreter. You’re now ready for the next stage.

Using CircuitPython

Writing CircuitPython applications is as simple as writing a Python application and dropping it onto CIRCUITPY. The file must be named main.py for it to execuite. But before you do that you can work directly with CircuitPython via REPL (read-eval-print loop). There is a Raspbian utility that can be used to work with the REPL as well as act as a debug port. It’s called screen.

You can tell if screen is installed with which screen. If it prints out a full path to the utility, then it’s installed. If it returns nothing, then install screen with sudo apt install screen -y.

To start screen open a console window and type screen /dev/ttyACM0 115200. The terminal will clear and you’ll see the following:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.Press any key to enter the REPL. Use CTRL-D to reload.

Now just press Enter to enter the REPL. Type a simple Python command at the REPL prompt.

Adafruit CircuitPython 4.1.0-rc.1 on 2019-07-19; Adafruit CircuitPlayground Express with samd21g18>>> print('Hello')Hello>>>

Everything is continuing to check out, and you now have a way to work directly with the CPE. Now let’s type something more ambitious.

>>> import board, neopixel>>> pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2)>>> RED = (63, 0, 0)>>> pixels.fill(RED)>>> GREEN = (0, 63, 0)>>> pixels.fill(GREEN)>>> BLUE = (0, 0, 63)>>> pixels.fill(BLUE)>>>

If you’ve been looking over at your Circuit Playground Express after each pixel.fill() command you’ll see that all the NeoPixels have been lighting up respectively as red, green, and blue. This tiny bit should whet your appetite to dig in deeper and work with the Circuit Playground Express via CircuitPython. In the next post we’ll add an application the the Circuit Playground Express and show how to use the screen as a debugging aid. Until the next time.

3 thoughts on “working with the adafruit circuit playground express using the raspberry pi 4

Comments are closed.