- Input/Output (I/O)
- Using the CPX as Computer Input
- Learning Resources
- Next Lesson
- Educational reflections
Figure. The Circuit Express Playground. Image from Adafruit.
The Circuit Playground Express (CPX) is an introductory physical computing board created by Adafruit. It is a wonderful electronic prototyping platform board for learning electronics and programming and for creating imaginative physical computing projects (e.g., see samples here).
Compared with Arduino, the CPX’s advantages for novice makers are twofold:
First, the CPX can be programmed with an easy-to-use drag-and-drop visual programming language called MakeCode developed by Microsoft, which is similar to Scratch. As students and makers gain experience and expertise, they can switch over to more advanced programming languages such as CircuitPython (Python), or Arduino (C/C++)
Second, the CPX includes a variety of built-in inputs and outputs, so you do not need to purchase or wire-up external components (or even use a breadboard). On-board inputs include a LIS3DH accelerometer, a light-level sensor (a phototransistor), multiple push buttons, a microphone, and outputs include neopixel LEDS, a speaker, and infrared receivers/transmitters.
To contextualize CPX’s potential even further, we can use the three evaluation criteria for creative construction kits that Mitchell Resnick and Brian Silverman outline in their fantastic IDC’05 paper “Some Reflections on Designing Construction Kits for Kids”. Creative constructions kits should have:
- Low floors—kits should be approachable, easy-to-use for beginners;
- high ceilings—kits should grow with you as you learn and gain experience, allowing you to create increasingly advanced projects;
- and wide walls—kits should support a breadth of designs and projects.
We believe the CPX meets each of these criteria—making it a powerful prototyping and educational platform. As an example, at the University of Washington, the CPX has been used in our MHCI+D program as well as some introductory electrical engineering courses—quite the range of contexts!
One key benefit of the CPX hardware—compared with vanilla Arduino boards like the Uno—is that it’s full of amazing input/output (IO) components. Adafruit provides a detailed “guided tour” but, in short, the board includes five types of input include motion, temperature, light, sound, and buttons as well as two types of output (LEDs, sound).
It’s OK if you don’t understand all of the terminology used below. In fact, if this is the first time you’ve ever played with electronics, we fully expect that this is mostly all new to you. Still, it’s worthwhile to skim over the sections below to get a sense of what’s possible with the CPX before we start building!
Video. The CPX has lots of really fun and interesting on-board sensors, including an accelerometer, temperature, light, sound, and more. In the video above, I’m showing how to use the on-board accelerometer (motion sensor) to create a “motion mouse” with the CPX. See L7.2: Accelerometer Mouse for more!
Specifically, the CPX includes the following built-in input/sensors:
- 1 x Motion sensor (LIS3DH triple-axis accelerometer with tap detection, free-fall detection)
- 1 x Temperature sensor (thermistor)
- 1 x Light sensor (phototransistor). Can also act as a color sensor and pulse sensor.
- 1 x Sound sensor (MEMS microphone)
- 2 x Push buttons, labeled A and B
- 1 x Slide switch
Figure. An annotated image of the CPX’s built-in sensors/input.
In addition to the built-in input, the CPX also has built-in LEDs and speaker for light and sound output. More specifically:
- 10 x mini NeoPixels, each one can display any color
- 1 x Mini speaker with class D amplifier (7.5mm magnetic speaker/buzzer)
- Green “ON” LED so you know its powered
- Red “#13” LED for basic blinking
Figure. An annotated image of the CPX’s built-in output.
In addition to the built-in components, the CPX has 14 connection pads to support interfacing with external input/output (I/O), including buttons, LEDs, and more. You can use a variety of connection strategies from sewing with conductive thread to wire wrapping to even small metal screws, the most common connection is an alligator clip.
Figure. An annotated image of the CPX’s 14 alligator pads for power and GPIO.
The CPX has eight general purpose I/O pins (GPIO) for interfacing with external electronic components. All of the I/O pads can be used as digital I/O, analog input, and PWM.
Each pad can provide up to ~20mA of current so do not connect a motor or other high-power component directly. If you don’t know what this means, that’s OK! You can always ask the instruction team whether a component is safe to use!
For more information, see Adafruit’s CPX Pinouts Guide.
Video. Pins A1-A7 on the CPX can be used for analog input to read voltages between 0-3.3V, which the CPX converts to a number between 0-1023. Here, I’m using a potentiometer, which dynamically changes its resistance (and splits the voltage levels) based on knob position. Learn more about analog input in L8: Analog Input!
The CPX has six pins that can read analog input (A1-A7). Analog input pins read voltage levels that range between 0V (GND) to 3.3V. The CPX converts these voltages to a number between 0-1023 using what’s called an analog-to-digital (ADC). The official CPX docs list the ADC as 12 bits (0-4096) but we’ve found that, in practice, it defaults to 10-bits. So, an analog signal is converted from 0 - 1023.
Below is the pinout diagram for the CPX highlighting the analog input pins (A1-A7):
You’ll learn more about analog input in L8: Analog Input!
Video. Pins A1-A7 on the CPX can be used for capacitive touch sensing. Here, I’m showing how we can use a soda can to build a simple hand proximity detector. Learn more here!
Of the eight GPIO pins, seven can be used for capacitive touch sensing (Pins A1-A7). You’ll learn more about capacitive sensing in Lesson 5!
As the Adafruit CPX guide describes, there are six power pads equally spaced around the CPX’s perimeter. Specifically, there are:
- 3 x GND pads, which are all connected together
- 2 x 3.3V out pads
- 1 x USB/battery Vout pad, which is a special power pad. This pin will supply either USB power (5V) or LiPoly power (3.7V). If both are connected, the CPX supplies the higher voltage. This output is not connected to the onboard regulator, so can supply up to 500mA continuous and 1A peak before tripping the internal fuse (if the fuse trips, just wait a minute and it will automatically reset)
Figure. An annotated image of the CPX’s GND and Vout power pads.
The CPX also has a powerful embedded microcontroller—the ATSAMD21 ARM Cortex M0 Processor—running at 3.3V and 48MHz. In comparison, the Arduino Uno is powered by a much older and slower microcontroller: the ATmega328P at 5V and 16 MHz.
Video. The CPX can be used as an input controller to your computer. You can make your own keyboard, mouse, joystick, and more! This example is from Lesson 5.3: Making a Capacitive Keyboard.
Like the Arduino Leonardo, the CPX can act like a keyboard, mouse, joystick, MIDI, or simply a serial port. So you can easily make custom input to your computer—neat!
You can learn more about this in:
- Lesson 5.3: Making a Capacitive Keyboard
- Lesson 6: Using the CPX as a Keyboard
- Lesson 7: Using the CPX as a Mouse
An additional benefit of the CPX compared with traditional Arduino is that it can be programmed multiple ways.
For novices with limited programming background or for those who simply like visual programming languages, you can use MakeCode. More advanced users may choose Python via CircuitPython or C/C++ via the Arduino IDE.
Microsoft’s MakeCode was designed to provide a visual, drag-and-drop interface for programming physical computing projects. This visual programming style—called block-based programming—was popularized by and is similar to Scratch. The video below shows how you program the CPX simply by dragging-and-dropping “puzzle pieces” (blocks).
Amazingly, you can also test your program and see how it behaves with a “virtual” CPX directly in MakeCode. Do you see that CPX on the left sidebar? That CPX is a simulator that shows how your code will run when eventually loaded on the CPX hardware itself!
Video. Rapidly creating a full program with MakeCode called “Blinky.” We will turn on all the NeoPixels (by setting them red) then pause then turn them off (by setting them black) and repeat “forever.” Code link.
To learn more, Adafruit and MakeCode have published a series of thoughtful, easy-to-understand tutorials:
A “What is MakeCode and How to Use it” primer
You can find step-by-step MakeCode + CPX tutorials within the MakeCode editor itself. The nice thing here is that the MakeCode editor walks you through each step. Pretty awesome!
You can also access the above tutorials as traditional, linear step-by-step guides here.
Finally, if you want to dive deeper into some of the CPX’s individual hardware components, Shawn Hymel, Adafruit, and MakeCode teamed up to make a video-based tutorial series called Behind the MakeCode Hardware, including topics on:
- Adafruit publishes example MakeCode+CPX example projects along with tutorials.
In the next lesson, we will make our first MakeCode+CPX program—called Blinky. As we build, we will learn about the MakeCode programming environment, the simulator, and how to load our program on to the CPX.
As someone who has worked with and taught physical computing for nearly a decade, MakeCode addresses several barriers to entry for novices (in rough order of importance):
- Second, event handling. A key challenge with Arduino for novices is handling events (e.g., when a button is pressed, do this), especially when programs contain lots of loops (which can make the system seem unresponsive, see this discussion)
- Third, there is a built-in simulation environment that immediately lets you see how your code will perform before uploading it to your physical CPX device
- Finally, it is a web-based editor. There is nothing to install and you can program the CPX from your web browser. And once you’ve loaded the editor, it stays cached in your browser (so works offline).