# Make It Log

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/058/492/medium800/sensors_davinci_notebook.jpg?1533217002 Picture by Todd Dailey via Flickr CC BY-SA 2.0) https://www.flickr.com/photos/twid/3013680713)

## The Past

Before the advent&nbsp; of computers, all data was written in notebooks. One of Leonardo da Vinci's notebooks, above, is an example, as are the notebooks by the great scientists of the past.&nbsp;

## The Present

While observation by eye is still used today, more often than not we automate readings by electronics. In any given day, billions of sensors worldwide take readings of heat, light, wind, etc. But where does that data go?

## The Spreadsheet

To record and analyze readings, it is easiest for most folks to use a spreadsheet. Available on all computer platforms, a spreadsheet is one of the first programs people learn. And, the analytical capabilities (re. plotting/graphing) are excellent.

This guide will quickly allow you to learn about placing data readings directly into the spreadsheet of your choice, A Circuit Playground Express and it's multitude of sensors, will log data to a spreadsheet and an Android phone.

## Parts List
### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
![A Black woman's manicured hand holds a round microcontroller with lit up LEDs.](https://cdn-shop.adafruit.com/640x480/3333-05.jpg)

### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

Out of Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
![USB cable - USB A to Micro-B - 3 foot long](https://cdn-shop.adafruit.com/640x480/592-01.jpg)

## For the plant monitoring example - there is an all-in-one kit or if you already have an Circuit Playground Express, add alligator clips:
### Circuit Playground Express Soil Sensor Mini Kit

[Circuit Playground Express Soil Sensor Mini Kit](https://www.adafruit.com/product/4060)
The thirst is real! Keep your flora (plants, [not the board](https://www.adafruit.com/product/659)&nbsp;\*wink\*) happy and hydrated with the **Circuit Playground Express Soil Sensor Mini Kit**. This kit will teach you all about how to keep your plants in good condition,...

In Stock
[Buy Now](https://www.adafruit.com/product/4060)
[Related Guides to the Product](https://learn.adafruit.com/products/4060/guides)
![Hand squeezing a water bottle into a potted plant with metal nail stuck into soil. Nail connects to Circuit Playground lit up green.](https://cdn-shop.adafruit.com/640x480/4060-01.jpg)

or

## For monitoring to an Android phone, add:
### Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long

[Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long](https://www.adafruit.com/product/3610)
This cable is a little unusual, rather than having a USB A plug on one end, it has _two_ Micro B USB connections! What is this for? It's for when you have a "USB On-The-Go (OTG)" device, and you want to plug in another USB device. For example, a Pi Zero or Pi Zero W has a...

In Stock
[Buy Now](https://www.adafruit.com/product/3610)
[Related Guides to the Product](https://learn.adafruit.com/products/3610/guides)
![Micro USB to Micro USB OTG Cable](https://cdn-shop.adafruit.com/640x480/3610-01.jpg)

Or a standard USB OTG cable adapter

### USB OTG Host Cable - MicroB OTG male to A female

[USB OTG Host Cable - MicroB OTG male to A female](https://www.adafruit.com/product/1099)
This cable looks like a USB micro cable but it isn't! Instead of a USB A Plug, it has a USB A Socket on the end. This cable is designed for use with OTG (On the Go) host devices (like the Arduino Due or many tablets) so you can connect a mouse, keyboard, or any other USB device. You'll...

In Stock
[Buy Now](https://www.adafruit.com/product/1099)
[Related Guides to the Product](https://learn.adafruit.com/products/1099/guides)
![USB OTG Host Cable with Micro B OTG male to A female in black](https://cdn-shop.adafruit.com/640x480/1099-00.jpg)

# Make It Log

## Logging Into a Spreadsheet

![](https://cdn-learn.adafruit.com/assets/assets/000/059/128/medium800thumb/makecode_spreadsheet2_%281%29.jpg?1534291061)

There are several ways to record data into a spreadsheet. The following examples will have Circuit Playground Express poll its sensors and then output the data over USB in such a way that it will "type" the numbers into a on-screen&nbsp;computers spreadsheet.

This method uses the USB feature known as human interface device protocol (HID). Plug in a keyboard or mouse into modern computers via USB, and they "just work". Computers can have multiple keyboards, it doesn't confuse them. So we'll use this property to have the Circuit Playground Express output data like a keyboard would, "typing" characters out.

For spreadsheets, to go "to the next line" the keystrokes are typically the down arrow followed by the left arrow to get back to column 1. We'll emulate those keystrokes also to align the data into nice, neat columns.

The first examples shows logging data via CircuitPython. The second example demonstrates the same concept in Microsoft MakeCode.

# Make It Log

## CircuitPython

![](https://cdn-learn.adafruit.com/assets/assets/000/058/493/medium800/sensors_makecode_circuitpython_circuit_playground_adafruit_blinka_computer.png?1533222328)

## CircuitPython

This program is written in CircuitPython, the easy to use language for microcontrollers. If you'd like to learn more about CircuitPython and how to easily get started, [please read this guide](https://learn.adafruit.com/welcome-to-circuitpython?view=all "CircuitPython Introduction").

Adafruit recommends the Mu editor. Available for PC, Mac, and Linux for free, it provides a clean, easy to use interface and code upload directly to Adafruit boards. You can [learn about Mu here](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor "Mu").

## How it Works

The following program will take three readings:

1. **time** relative to the power-on of the board, not time of day - this is what we get when we request `time.monotonic()`
2. **light intensity** - this is not in lux but it does have higher numbers when theres more light. This is what we get when we request `light.value`
3. **temperature** in Celsius (unless you uncomment one line to get Fahrenheit). This is what we get when we request `thermistor.temperature`

Once we've collected those three data points, the values are written out via Keyboard emulation to your computer.

## Enabling/Disabling the Keyboard
When the slide switch is closed, moved toward the black speaker, it does not log data. When the switch is moved towards the microphone, data will be "typed" out by the board and populate your spreadsheet. Moving the switch back stops the logging so you can use your regular keyboard without numbers being injected into your work.

&nbsp;

Start with the switch closed (to the left)

![makecode_switch.png](https://cdn-learn.adafruit.com/assets/assets/000/059/121/medium640/makecode_switch.png?1534289387)

## The Code

Copy the following code into Mu. Then save the code to the Circuit Playground Express as **code.py**. The program runs immediately, so be sure to switch the closed as explained above!

Warning: 

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Make_It_Log/code.py

## The Spreadsheet

You should have your computer open to a spreadsheet where you want the data (often cell A1). You can use Excel, Google sheets, OpenOffice Calc...anything you like!

![](https://cdn-learn.adafruit.com/assets/assets/000/059/117/medium800/makecode_image.png?1534289197)

## Use

When the slide switch is to the right, the data outputs the characters for the time, light intensity and temperature to the screen. Tabs are used to go from cell to cell and emulated cursor keys to get to the first cell of the next row.

When you are done logging, move the slide switch left towards the square black speaker.

If you want more delay between readings, see the bottom of the code to place a call to `time.sleep` with the parameter afterwards the number of seconds between each reading, such as `time.sleep(2.0)` to wait 2 seconds between readings.

If you find that the data is getting into the wrong column, adjust the delay between arrow keystrokes a tiny bit - we are "faking" typing, and the Circuit Playground Express can type faster than we can.

# Graphing

Each spreadsheet is a bit different on how it graphs so you should read the guides for your spreadsheet on how to do this. Generally you highlight the data (three columns by the number of rows you want graphed and then tell the spreadsheet to plot the data.

The first value will usually be chosen as the x-axis which is good - the time value will give you a basis for consistent reading times for the plot. The light and temperature readings should be plotted as two y values with separate scales.

The following is a plot on Google Sheets:

![](https://cdn-learn.adafruit.com/assets/assets/000/058/494/medium800/sensors_Google_Sheets_Example_1.png?1533223545)

Plotting both on the same graph is a bit limiting as the scales are very different for light and temperature. I used a logarithmic scale to adjust, but you might wish to plot each separately to see variations.

# Make It Log

## MakeCode

The MakeCode program acts 100% like the CircuitPython code. You will need to take a couple of steps to set up MakeCode to use Keyboard extension blocks to have the days go into individual spreadsheet cells.

## Setup

As of this guide (August 14, 2018) you will need to use the beta web version of MakeCode.

[https://makecode.adafruit.com/beta](https://makecode.adafruit.com/beta)

As this uses the Keyboard extension which has some very new edits. They should be in the main MakeCode builds later in the month.

To install the Keyboard extension, click on the **ADVANCED** block then the **EXTENSIONS**.

![makecode_ext.png](https://cdn-learn.adafruit.com/assets/assets/000/059/123/medium640/makecode_ext.png?1534289591)

Select the Keyboard extension and a new block, group colored black, named **KEYBOARD** will be available. You can use the blocks in this group to move the arrow keys in the spreadsheet.

![makecode_sensors_keyboard-extension.png](https://cdn-learn.adafruit.com/assets/assets/000/059/124/medium640/makecode_sensors_keyboard-extension.png?1534289661)

## How it Works

The following program will take three readings:

1. **time** relative to the power-on of the board, not time of day - this is the **millis (ms)** block
2. **light intensity** - this is not in lux but it does have higher numbers when theres more light. This is the **light level** block
3. **temperature** in Celsius or Fahrenheit, this is the **temperature** block

The values are written out via Keyboard emulation to your computer.

Here's the full MakeCode block set:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/092/medium800/sensors_makecode.png?1534258955)

[See this example in MakeCode](https://makecode.com/_FPv6AfPM5g5j)
## The Spreadsheet

You should have your computer open to a spreadsheet where you want the data (often cell A1). You can use Excel, Google sheets, OpenOffice Calc...anything you like!

![](https://cdn-learn.adafruit.com/assets/assets/000/059/125/medium800/makecode_image.png?1534289910)

Note that this code will not work with a word processor as-is as it assumes using arrow keys and tabs to change columns. The character 9 in the data writes is the standard code for the tab key so the numbers are written and the code will output a tab afterwards going to the next cell in the spreadsheet.

When the slide switch is closed, moved toward the black speaker, it does not log data. When the switch is moved towards the microphone, data will be "typed" out by the board and populate your spreadsheet. Moving the switch back stops the logging so you can use your regular keyboard without&nbsp; numbers being injected into your work.

## Changes

Feel free to make changes to read other sensors. Also you can use the Pause block to slow down readings in case you believe the readings are being taken too quickly.

## Additional use of Keyboard Commands

See the Adafruit tutorial [Make it a Keyboard](https://learn.adafruit.com/make-it-a-keyboard) for additional keyboard examples.

# Make It Log

## Plant Monitoring

![](https://cdn-learn.adafruit.com/assets/assets/000/058/495/medium800/sensors_plant.jpg?1533223826)

Adafruit's basic tutorial for monitoring soil moisture is [in this guide](https://learn.adafruit.com/soil-moisture-sensor-with-circuit-playground-express "Soil Moisture Sensor Tutorial").

This page expands that project to log plant data to a spreadsheet. It includes the soil moisture level as measured in the soil moisture tutorial via a capacitive touch pad connected to a piece of metal in the soil of the plant. Measuring the temperature and light levels gives a complete picture of the plant's progress.

## The Code

The CircuitPython code is the same as the previous example with these changes:

- The soil moisture is read on a capacitive touch pad connected to a nail in the soil
- The moisture data is a fourth column in the spreadsheet.

Here is the code:

## Plotting

Here I used Microsoft Excel to hold the data this time. The time units were from 613 to 698 seconds after the board was powered. That forms the x-axis values. The plots are the light (varies the most), temperature and soil moisture (which usually don't vary much over a few minutes).

![](https://cdn-learn.adafruit.com/assets/assets/000/058/496/medium800/sensors_Excel_Example_2.png?1533229059)

## Use

This code provides a complete plant monitoring solution. You can monitor the light and temperature and how moist the soil is over time.

The code could be expanded to possibly self-water. You would need a soil moisture value at which you consider the soil to be dry. We have found that 1500 is a good baseline that you can use based on the type of plant and it's requirements.

You would check if the moisture was \< 1500, then do something that releases a determined amount of water (which again varies by the plant type, pot, etc.) to water the plant appropriately.&nbsp;

# Make It Log

## Logging Via Android Phone

![](https://cdn-learn.adafruit.com/assets/assets/000/058/498/medium800/sensors_Capture.png?1533236151)

In the tutorial&nbsp;Android [GBoard Morse Code Control with Circuit Playground Express](https://learn.adafruit.com/android-gboard-morse-code-at-with-circuitplayground-express), Adafruit demonstrates using the HID Keyboard functions to enter data into an Android phone and then use a feature of the Google GBoard keyboard to turn Morse Code into text.

But you don't have to use Morse Code, you can plug the CPX right into your Android phone or tablet and have it type just the same way it does on your computer with a spreadsheet above. This time you can go mobile. All you need is a special USB cable called OTG (on the go).

# Make It Log

## Connecting Your Phone to the Board

![](https://cdn-learn.adafruit.com/assets/assets/000/057/824/medium800/circuitpython_1200px-USB_OTG_Log-sm.svg?1532093720 source: Wikipedia, marked "Fair Use")

Android phones typically come with a micro-B USB connection. This USB connection follows the USB on-the-go (OTG) specification so peripherals can be plugged in to the port and be used by the phone.&nbsp;

This project is going to use the capabilities of Circuit Playground Express to act as a human interface device (HID), _namely a keyboard_. When the user wants the Express to send a key, they'll use a button, the board will translate this to some keyboard character, and the phone will believe a keyboard was used to enter the character.

This type of behavior is useful for a great many projects. Control of devices using alternative interfaces is the most popular. This can be in manufacturing, at home, or in assistive technology (AT) situations where traditional keyboards cannot be conveniently used.

## Making the Connection
For this project you will need a micro-B male to micro-B male connection that conforms to the OTG specification. Both the phone and the Circuit Playground Express have a micro-B female connector.

&nbsp;

The cable at left is the most direct connection. Some electronics stores carry these - [Adafruit sells them as product #3610](https://www.adafruit.com/product/3610).

&nbsp;

There are also a number of other OTG to regular USB connector devices including [Adafruit Tiny OTG Adapter](https://www.adafruit.com/product/2910)&nbsp;and the short [USB OTG Host Cable - MicroB OTG male to A female](https://www.adafruit.com/product/1099).

![circuitpython_2910-01.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/979/medium640/circuitpython_2910-01.jpg?1532440032)

![circuitpython_1099-00.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/980/medium640/circuitpython_1099-00.jpg?1532440042)

![circuitpython_3610-01.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/820/medium640/circuitpython_3610-01.jpg?1532092772)

### Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long

[Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long](https://www.adafruit.com/product/3610)
This cable is a little unusual, rather than having a USB A plug on one end, it has _two_ Micro B USB connections! What is this for? It's for when you have a "USB On-The-Go (OTG)" device, and you want to plug in another USB device. For example, a Pi Zero or Pi Zero W has a...

In Stock
[Buy Now](https://www.adafruit.com/product/3610)
[Related Guides to the Product](https://learn.adafruit.com/products/3610/guides)
![Micro USB to Micro USB OTG Cable](https://cdn-shop.adafruit.com/640x480/3610-01.jpg)

# The Final Phone Setup
Here is a picture of the connections with a USB OTG adapter rather than the micro-micro cable as I did not have the cable at hand. The connections would be identical - connect the phone micro-B USB to the Circuit Playground Express micro-USB connector.

![circuitpython_P1000013.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/994/medium640/circuitpython_P1000013.jpg?1532444723)

# Make It Log

## Logging to the Phone

![](https://cdn-learn.adafruit.com/assets/assets/000/058/497/medium800thumb/sensors_ezgif.com-video-to-gif.jpg?1533235388)

With your USB connection from the Circuit Playground to your phone set, the Circuit Playground Express data can be logged to the phone.

Warning: 

## Spreadsheet or other Data Capture Program

You should also use the Google Play Store to install a spreadsheet (or other program of your choice) to capture data from the Circuit Playground Express acting as a HID keyboard.

As Android is Google-centric, the best option is to go to the Google App store and load **Google Sheets** if it is not already available. I note that Microsoft Excel is also available in the Google App Store, but we didn't try it!

## Code

The code can be either of the programs earlier in this tutorial. The demonstration will use the second example which includes plant soil moisture data in the fourth column of the spreadsheet. You can change the program to add or subtract data as desired.&nbsp;

# Usage

Load your spreadsheet app and select that you want to create a new spreadsheet. Position the focus on cell A1. Switch the slide switch and watch the data flow.

This type of data capture is great for gathering data "in the field" or "on the go".


## Featured Products

### Circuit Playground Express Soil Sensor Mini Kit

[Circuit Playground Express Soil Sensor Mini Kit](https://www.adafruit.com/product/4060)
The thirst is real! Keep your flora (plants, [not the board](https://www.adafruit.com/product/659)&nbsp;\*wink\*) happy and hydrated with the **Circuit Playground Express Soil Sensor Mini Kit**. This kit will teach you all about how to keep your plants in good condition,...

In Stock
[Buy Now](https://www.adafruit.com/product/4060)
[Related Guides to the Product](https://learn.adafruit.com/products/4060/guides)
### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

Out of Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
### Large Alligator Clip Test Lead (set of 10)

[Large Alligator Clip Test Lead (set of 10)](https://www.adafruit.com/product/321)
Connect this to that without soldering using these handy alligator clip test leads. 20" cables with alligator clip on each end, color coded. You get 10 pieces in 5 colors. Strong and grippy, these always come in handy! We often use these in conjunction with a multimeter so we don't...

Out of Stock
[Buy Now](https://www.adafruit.com/product/321)
[Related Guides to the Product](https://learn.adafruit.com/products/321/guides)
### Circuit Playground Express - Base Kit

[Circuit Playground Express - Base Kit](https://www.adafruit.com/product/3517)
It's the **Circuit Playground Express Base Kit!** &nbsp;It provides&nbsp;the few things you'll need to get started with the new [Circuit Playground Express](https://www.adafruit.com/product/3333).&nbsp;This version of Circuit Playground is super powered, and will...

In Stock
[Buy Now](https://www.adafruit.com/product/3517)
[Related Guides to the Product](https://learn.adafruit.com/products/3517/guides)
### Circuit Playground Express Advanced Pack

[Circuit Playground Express Advanced Pack](https://www.adafruit.com/product/2769)
 **Circuit Playground Express** &nbsp;is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to program....

In Stock
[Buy Now](https://www.adafruit.com/product/2769)
[Related Guides to the Product](https://learn.adafruit.com/products/2769/guides)
### Code.org Circuit Playground Express Educators' Pack

[Code.org Circuit Playground Express Educators' Pack](https://www.adafruit.com/product/3399)
For many years, instructors and teachers have asked us to come up with a better way to teach programming and electronics. We have worked on Circuit Playground Express for over a year to come up with a board that is powerful, beautiful, fun, and perfect for teaching

In Stock
[Buy Now](https://www.adafruit.com/product/3399)
[Related Guides to the Product](https://learn.adafruit.com/products/3399/guides)
### Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long

[Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long](https://www.adafruit.com/product/3610)
This cable is a little unusual, rather than having a USB A plug on one end, it has _two_ Micro B USB connections! What is this for? It's for when you have a "USB On-The-Go (OTG)" device, and you want to plug in another USB device. For example, a Pi Zero or Pi Zero W has a...

In Stock
[Buy Now](https://www.adafruit.com/product/3610)
[Related Guides to the Product](https://learn.adafruit.com/products/3610/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [CircuitPython Sound Box](https://learn.adafruit.com/circuitpython-sound-box.md)
- [How to Use Video Greenscreen in MakeCode](https://learn.adafruit.com/how-to-use-video-greenscreen-in-makecode.md)
- [Pearl's Gem Weapon – Steven Universe](https://learn.adafruit.com/pearl-s-spear-steven-universe.md)
- [Sensor Plotting with Mu and CircuitPython](https://learn.adafruit.com/sensor-plotting-with-mu-and-circuitpython.md)
- [Which CircuitPython Board is Right for You?](https://learn.adafruit.com/choose-your-circuitpython-board.md)
- [Compost Friend!](https://learn.adafruit.com/compost-optimization-machine.md)
- [Edit CircuitPython Code on iOS with Runestone](https://learn.adafruit.com/editing-circuitpython-on-ios-with-runestone.md)
- [Circuit Playground Express Head-Tilt Ears](https://learn.adafruit.com/circuit-playground-express-head-tilt-ears.md)
- [Circuit Playground Seashell Pendant](https://learn.adafruit.com/circuit-playground-seashell-pendant.md)
- [Tappy Robotic Hand](https://learn.adafruit.com/robotic-tapping-hand-with-cpx.md)
- [Circuit Playground Hourglass](https://learn.adafruit.com/circuit-playground-hourglass.md)
- [Infrared Transmit and Receive on Circuit Playground Express in C++](https://learn.adafruit.com/infrared-transmit-and-receive-on-circuit-playground-express-in-c-plus-plus-2.md)
- [LED NeoPixel Corset with Circuit Playground Express and MakeCode](https://learn.adafruit.com/led-corset-with-circuit-playground-and-makecode.md)
- [Sound Activated Shark Mask](https://learn.adafruit.com/sound-activated-shark-mask.md)
- [LEGO Head Lamp with Audio](https://learn.adafruit.com/lego-head-lamp-with-audio.md)
