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.

raspberry pi 4 cpu temperature observations

The short video above shows the Adafruit Feather displays attached to the Raspberry Pi 4, along with the micro:bit and scroll:bit I wrote about last post. The Adafruit Feather work was done over a year ago. You can find and read about it in the section Golang.

Basically I’m using the USB as well as the GPIO/I2C connections to drive a number of devices. In one terminal I have tempmonitor.py running, and in another I have a Bash script, clock.sh, running. The Bash script uses some of the Go developed apps to manipulate the Adafruit Feather displays using I2C. The Bash script simply displays the system time, sleeps a bit, and then displays the system date. Then it repeats. The script for this is at the bottom of the post.

Observations

  • I’ve taken the top off the official Raspberry Pi 4 case. It’s open now, and as a consequence the CPU is now running a good 15C cooler than it was with the top on. Which begs the question who designed that case that way without any vents at all for circulation of the heat out of the enclosure.
  • Running the same code on the Raspberry Pi 3B+ shows the CPU temp to be a good 20C cooler, and this board is in a case. The case has a lot of ventilation holes in it, and thus probably helps it run cool. Furthermore, that CPU has a heat sink attached to it as well.
  • When the Raspberry Pi 4 is running cooler, the entire board is running cooler, especially the USB chip itself. When it’s hot, USB communication is intermittent and can be seen when the micro:bit/scroll:bit fails to scroll the temperature sent to it. I’ve debugged the original Python script, and know when it’s sending a message to the micro:bit when I see a corresponding message on the terminal. About one out of every eight attempts to send a message fails when the CPU is registering 75C. At this much cooler temperature (around 55C) all messages are sent across and scrolled. You can draw your own conclusions.
  • I’ve ordered a Flirc aluminum case which has a heatsink that’s part of the case and is designed to pull heat away from the CPU. I don’t know when it’ll arrive since this was a pre-order, but it was only about US $12, so I figured why not.
#!/bin/bash## Copyright (c) 2019 William H. Beebe, Jr.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## ------------------------------------------------------------------------------## A simple clock that uses the Bash shell to send the Unix date and time to a# pair of Adafruit displays.## CTRL C is trapped to turn off the displays before exiting from the script.#trap ctrl_c INTfunction ctrl_c() {display clear > /dev/nullexit}## Get the date from the Unix date command, using +%r to get the time formatted# in the locale's time format. This will give it in 12 hour format, with an# AM or PM. Then use the Bash shell's built-in regex to replace the last ':'# and second digits with a space, so that the time string is in the format# '12:00 PM' and will print across the eight Adafruit hexadecimal digits.#while true; doDATE=$(date +%r)display print "${DATE//:[0-9][0-9] / }" > /dev/nullsleep 3DATE=$(date +%D)display print "$DATE" > /dev/nullsleep 3display clear > /dev/nulldone