CircuitPython is Adafruit's suggestion for coding in addition to using MakeCode. CircuitPython can gather data for later analysis or send output to the Mu editor where it will plot values similar to MakeCode.

If you are new to CircuitPython, Adafruit has a great beginners guide.

To get set up with CircuitPython and the Mu Editor, you can follow this guide page.

The code below will read the Circuit Playground Express light sensor and send the output to the Serial port (also called the REPL) in a form called a Tuple. A tuple is just a group of fixed values gathered together, surrounded by parenthesis. For one value, a tuple would be shown as (tuplevalue, ), to two (tupleval1, tupleval2), etc. The comma in the first one makes sure it's a tuple and not a number in parenthesis like in math.

import time

import analogio
import board

light = analogio.AnalogIn(board.LIGHT)

while True:

Open the Mu editor on your computer and copy the code above. Then, save it as file to your Circuit Playground Express flash drive. When you plug your board into USB, it should show up as a flash drive called CIRCUITPY.

The code sets up the Circuit Playground Express light sensor as a light object via analog reads. Then in an infinite forever style loop, the code reads the light sensor value and prints values out as a single value tuple. There is a tenth of a second (0.1 second) pause between each reading (it is highly suggested a tenth of a second or so be the minimum time between samples, feel free to make it longer).

To see what the program is doing, click both the Mu Serial button and the Mu Plotter button:

Your screen should look like this - feel free to resize the individual windows for better viewing:

Now cover your Circuit Playground Express light sensor and then show it bright light like from the computer screen. You'll see the values change accordingly in both data on the bottom left left and the plot on the bottom right.

Going Further

Feel free to add plotting to your programs.

Adafruit has an entire guide devoted to plotting the Circuit Playground Express sensor values in CircuitPython and Mu. Click the button below to check out that guide.

This guide was first published on Jul 23, 2018. It was last updated on Jul 23, 2018.

This page (CircuitPython and Mu) was last updated on Jan 25, 2021.