T1W1: Circuit Playground Express and MakeCode

Welcome to the Lowell STEMapalooza elective class! For the first class we will dive in to learning how to program a Circuit Playground Express (CPX) microcontroller board using MakeCode, a visual programming language. Everyone will get a board, which can plug in to your Chromebook over USB. In future terms we will use these boards as the brains of other electronics projects, and we will use MakeCode to program games on a handheld game console.

The Circuit Playground Express (CPX) board is a microcontroller board from Adafruit that is similar to an Arduino board but better in every way! It can be programmed in multiple languages and environments, including C/C++ in Arduino, Circuit Python, and MakeCode and even JavaScript.

One of the best things about the CPX board is that it comes with a large number of sensors and output devices, so you can do interesting stuff without needing to hook anything else up. Here is a picture of the board with the components labelled:

Circuit Playground Express Sensors and Inputs:

  • Motion sensor (LIS3DH triple-axis accelerometer with tap detection, free-fall detection)

  • Temperature sensor (thermistor)

  • Light sensor (phototransistor). Can also act as a color sensor and pulse sensor.

  • Sound sensor (MEMS microphone)

  • Push buttons, labeled A and B

  • Slide switch

  • Infrared receiver - remote control codes, data communication, proximity sensor

  • 7 capacitive touch or digital inputs

  • 8 Analog inputs (12 bit, 350 ks/s)

Circuit Playground Express Outputs:

  • 10 x mini NeoPixels, each one can display any color

  • Mini speaker with class D amplifier (7.5mm magnetic speaker/buzzer)

  • Infrared transmitter

  • Red "#13" LED for basic blinking

  • USB port can act like serial port, keyboard, mouse, joystick or MIDI!

  • 8 digital output pins

  • I2C, UART, multiple PWM outputs

  • Analog output (10 bit, 350 ks/s)

Circuit Playground Express Specs:

  • ATSAMD21 ARM Cortex M0 Processor, running at 3.3V and 48MHz

  • 2 MB of SPI Flash storage for Python code and libraries

  • 256KB of flash memory, 32KB static RAM on the microcontroller

  • MicroUSB port for programming and debugging

  • Battery power input, runs at 4.5V

  • Alligator-clip compatible I/O pads

We will be programming our Circuit Playground Express boards with MakeCode, which is easy to learn but has some powerful and convenient features. MakeCode is a visual programming language like Scratch that is developed by Microsoft and lets you run your programs on a bunch of different microcontroller boards. MakeCode lets you write programs by arranging graphical blocks instead of typing program code into a text editor. It includes an on-screen emulator of the device you are working with so you can try out your code before downloading it to the device.

The right side of the MakeCode window holds your program code diagram. The column of blocks in the middle holds the statements and functions you can add to your code. The section on the left is an emulator for your CPX board that lets you test and debug your programs before they get downloaded to the real hardware. At the bottom of the window, the Download button lets you send your program to the CPX board.

Downloading Programs

To download a MakeCode program to your CPX board, first make sure the board is connected to your Chromebook using a USB cable. The CPX board should show up as a flash disk drive called "CPLAYBOOT" when it is plugged in. When you first plug it in you might get notifications about a "Removable device detected". You can dismiss the notification by clicking on the "X", or you can open the ChromeOS Files app to see what is in the CPX flash memory - program code will show up as a *.UF2 file (or possibly a *.py file if CircuitPython has been used).

To start the download, press the small "RESET" button in the middle of the CPX board. The LEDs around the board should turn red and then stay green. When the LEDs are green the board is waiting for a download. If the LEDs don't turn green you may need to double-click on the RESET button.

Once the LEDs are green, press the pink [Download] button at the bottom of the MakeCode window. A ChromeOS "Save file as" window should appear. Select the "CPLAYBOOT" drive at the bottom of the left side drive list and press "SAVE". The program should download and the green lights should turn off - the CPX board is now running your program!

If you aren't asked where to save the file, ChromeOS may be automatically saving it in your Downloads folder on the Chromebook. To turn this feature off, go to the Chrome browser's Settings, then click on Advanced->Downloads. Under the Downloads section, look for the "Ask where to save each file before downloading" switch and turn it ON (blue). This will give you a chance to select the CPX board when you click the "Download" button.

Running Tutorials

For the rest of the class time, try running some of the MakeCode tutorials - they will step you through the features and menus of the MakeCode environment. In the MakeCode home page, look under the "My Projects" section for the "Tutorials" section, and click on the first project called "Siren". The tutorials are aimed at younger kids and feature charming Cartoon Network characters to help make them more appealing - try not to cringe.

The tutorials are pretty short so you should be able to do a bunch during class time. Please try to download some of them to your CPX board so you get familiar with the process - I will be available to help if needed.