We are constantly awash with data. Our brains must analyze data on a continual basis to make decisions. And here comes all the electronic sensors around us with their streams of data.

How does one look at electronic data and make decisions on what is happening over time? The tried and true answer is plotting (also called graphing).

This guide will quickly show you how to plot data Using Microsoft MakeCode and CircuitPython.

Parts List

All you need is a Circuit Playground Express! It's got all the sensors built in already.

A Black woman's manicured hand holds a round microcontroller with lit up LEDs.
Circuit Playground Express is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and...
Out of Stock

Nearly all tutorials on the Adafruit Learning System are written such that the user can use the web version of MakeCode. The web version runs on multiple computer types providing broad compatibility.

There is another version of MakeCode available from Microsoft in the form of an app that runs on Windows 10 and Windows 11 machines.

The big advantage the Windows Microsoft Store version of MakeCode is the ability to read data back and easily plot it, something the web version lacks at present.

The MakeCode App for Windows 10/11

The Microsoft MakeCode App is located in the Microsoft App Store.

Installation

In the Windows Search bar (usually next to your Start Button), type "Microsoft Store". In the search bar for the store app, type MakeCode. Select MakeCode for Adafruit.

Click the Install button for MakeCode for Adafruit. The app will install and you can then press the Launch button.

The introductory screens are identical to the web application.

With the Windows app MakeCode for Adafruit, you have the new availability to send serial data back to the MakeCode console, similar to the Mu Editor Serial/REPL capability.

When you want to see data (and to plot it), you use blocks in the CONSOLE block group, which is under the black ADVANCED block group.

The console log block will send any value to the console via the Circuit Playground Express USB connection. The console log value block does the same, and you can name the value, which is good if you are sending multiple types of information out.

Take a simple task to send light sensor values to the console. Without downloading this code, the interface will run using the simulator with the light level adjustable via a circle to the upper left of the simulated board.

The difference is shown when you actually download the code to the Circuit Playground Board. Using the Windows 10 app, the interface adds a Show console Simulator button below the Show console Device button.

Click the Show console Device button and you'll see the following:

In the device console, you'll see the values for the light sensor in a window towards the bottom and a plot vs. time to the right of the image of the Circuit Playground Express.

You can plot any kind of data in the device console. You can also display and plot multiple values. It is best if you use the console log value block and name your feeds. To plot the temperature and the light, value press the words Go back then change the code: 

Download the code to your Circuit Playground Express board and then click the Show console Device button again:

You can see the values being printed below and each reading plotted verses time. You can see the labels help identify the values.

If the readings are done too quickly, you can put a pause or wait block in to take values in a more timed fashion as shown below where the readings are taken once a second (= 1000 milliseconds)

Download to an Excel Spreadsheet

If you have Excel on your Windows PC, you can click the button shown below (far right) above the plots (circled in red below):

MakeCode will open Excel and paste the data to a new spreadsheet!

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.

# SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time

import analogio
import board

light = analogio.AnalogIn(board.LIGHT)

while True:
    print((light.value,))
    time.sleep(0.1)

Open the Mu editor on your computer and copy the code above. Then, save it as code.py 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.