Below is a basic data logging program to record the values of the CPX temperature sensor, light sensor, and the value of analog pin A1 (a homemade soil sensor) periodically. 

Using a wire, you can connect the Circuit Playground Express pad A1 to a nail placed in a potted plant. The readings will be directly proportional to the moisture in the soil.

For more on soil sensing, see the following guide:

Loading the Program to the CPX

Save the file on your computer. It is the name of the project with a UF2 file extension. Plug your Circuit Playground Express into your computer with a known good data+power USB cable. The CPX will show up as a flash drive in your file explorer/finder program as a flash drive named CPLAYBOOT. (If you see a drive named CIRCUITPY, press the reset button twice).

Copy the UF2 file to the CPLAYBOOT flash drive. The drive will eject itself as a flash drive. On Windows, you will see a message saying "Installing CPlay Express (app)" and the CPlay Express (app) device will appear in Settings -> Devices. Other operating systems may give a similar message.


When you press the B button, the program logs the data to the flash memory (displaying green LEDs) until you press the A button, at which time the CPX displays yellow LEDs. This is your indication the data logging is stopped and you can copy the data to your computer as shown below.

The default time between logged data samples is 10 seconds as set in the last line of the forever loop. If you want a different time between samples, change this value noting the number is in milliseconds (thousandths of a second).

Viewing Your Data

When your project is logging, a new flash drive should appear named MAKECODE.

The SPIFLASH directory contains program data. Logging data is written to a file named log.csv

Be sure you have stopped logging your data prior to accessing log.csv with any program. Pressing Reset or unplugging the CPX without pausing the data logging with the A button will corrupt the log.csv file!

In the example, press the A button to stop logging which will properly close the file and allow copying the data.

Copy the log.csv file to your hard drive to save it and view it.

Opening the log.csv file on the MAKECODE flash drive directly may be problematic if logging was not turned off prior to using. Stop logging by pressing the A button, copy log.csv to a hard drive and open it there for best results.

Open a spreadsheet program such as Google Sheets, Microsoft Excel, macOS Numbers etc. Open the log.csv file. The spreadsheet should recognize the CSV (if your program does not, you might have to specify you are trying to open a CSV file or use an import feature). In Google Sheets, the file just opens correctly.

The sep= and NAN lines may be ignored if they appear.

Line 2 has the headings for the data you read. Time first, then for the example: temp, light, and soil moisture readings in each column.

The data can go for quite a ways as the example logs data every 10 s. You can log data slower, 60 seconds (1 minute), 300 seconds (5 minutes), etc.

The data may be used to for analysis or to graph values over the time period. Using the Google Sheets graph function, push the graph button on the toolbar and without any formatting you have a great graph!

This guide was first published on Aug 27, 2019. It was last updated on Apr 16, 2024.

This page (Datalogger Use) was last updated on Mar 08, 2024.

Text editor powered by tinymce.