micro:climate Kit Experiment Guide

Pages
Contributors: D___Run___
Favorited Favorite 1

Experiment 7: Logging to the MicroSD Card

Introduction

We are almost done with our whirlwind series of weather experiments. In this final experiment we will look at how to log all of this amazing weather data to a microSD card using the OpenLog.

Parts Needed

  • 1x micro:bit board (Not included)
  • 1x weather:bit carrier board
  • 1x micro-B USB cable (Not included)
  • 1x OpenLog (with headers)
  • 1x microSD card (NOT INCLUDED WITH THIS KIT)
micro:bit Board

micro:bit Board

DEV-14208
$14.95
5
SparkFun OpenLog

SparkFun OpenLog

DEV-13712
$14.95
19
microSD Card with Adapter - 16GB (Class 10)

microSD Card with Adapter - 16GB (Class 10)

COM-13833
$19.95
5
SparkFun weather:bit

SparkFun weather:bit

DEV-14214
$14.95
USB Micro-B Cable - 6"

USB Micro-B Cable - 6"

CAB-13244
$1.95
3

Suggested Reading

Introducing the SparkFun OpenLog

OpenLog

The OpenLog Data Logger is a simple-to-use open source solution for logging serial data from your projects. The OpenLog provides a simple serial interface to log data from a project to a microSD card.

The primary interface with the OpenLog is the FTDI header on the board edge. This header is designed to plug directly into the weather:bit carrier board’s serial port, which allows the micro:bit to send data over a serial connection to the OpenLog.

Header

There are two status LEDs on the OpenLog to help you with troubleshooting.

  • STAT1 — This blue indicator LED toggles on/off when a new character is received. This LED blinks when serial communication is functioning.
  • STAT2 — This green LED is connected to Arduino D13 (SPI Serial Clock Line/ATmega328 PB5). This LED only blinks when the SPI interface is active. You will see it flash when the OpenLog records 512 bytes to the microSD card.

Stat LEDs

Hardware Hookup

You are going to love this! First thing is that you need to insert a microSD card into the OpenLog with the text side “up” as shown in the image below.

Exp7_HookUp1 | Adding a microSD card

Make sure the card “clicks” into place and stays in place.

Exp7_HookUp2 | microSD card inserted OpenLog

Next insert the OpenLog’s pins into the serial port on the weather:bit carrier board as shown below. Make sure that all of the pins are aligned and inserted correctly. Offsetting these pins could end in damaging your OpenLog or micro:bit. Finally, if you haven’t already, plug your micro:bit into the weather:bit. With that you should be good to go!

Exp7_HookUp3

Running Your Script

Please open a browser window and navigate to https://makecode.microbit.org. This should open the MakeCode environment that you used to install the weather:bit package.

Code to Note

Code to Note Exp 7

Serial Redirect To

We use the Serial Port on the weather:bit board to write data to the SparkFun OpenLog. To do this we need to do some setup for the micro:bit to use it correctly. We do this through the Serial Redirect To block placed in our On Start block.

In the Serial Redirect To block we set the transmit (TX) and receive (RX) pins. In this case we use pins 15 and 14. We also set the baud rate which is the rate at which two devices “agree” to communicate at. The OpenLog is preprogrammed to communicate at 9600 baud, so that is what we will set it at.

Join

The join block is one of the most useful blocks out there. You use it to join pieces of data together to build a long string that you then store in a variable. For example for our header we stored comma separated names as a single variable called header. The join blocks standard size is 2 slots. To add more slots click on the gear button and drag more slots in place as you have with the if / else if statements in previous experiments.

Serial Write Line

To send data to the OpenLog we use the Serial Write Line block. This command sends whatever data you attach to it over the serial lines you have specified in your Serial Redirect to block with a carriage return at the end of it.

Running Time(ms)

The running time block returns the number of milliseconds that the micro:bit has been powered up and running the current program. We are using it as a timestamp for data logging since there is no access to a realtime clock.

What You Should See

When you power your micro:bit, you will eventually see an “X” on the LED array. Press the A button to start logging data every 30 seconds. A check mark will be displayed on your LED array. Let the program run for a couple of minutes and press the A button again. You will see an “X” again. It is now safe to remove the microSD card from the OpenLog.

Exp 7 Powered without X

Now, using the microSD card slot on your computer or an adapter, open up the microSD card on your computer. You should see two files. One is a config file, which you can ignore. The other, which has a file name of “LOGXXXXX.txt,” is what you are looking for; go ahead and open it.

openlog files

The data in this text file is a Comma Separated Value (CSV) set of the data you sent it. The format is that the first line is the “header,” which is the name of each “column.” You see that our header is the following:

time,temperature,humidity,pressure,altitude

The header is followed by lines of values associated with each reading.

In fact, if you are a user of Google Sheets you can import this text file as a CSV and then graph these values pretty easily. We recommend this quick guide from Google on how to import a .txt file as a CSV into sheets.

Troubleshooting

  • Doesn’t seem to be logging — Make sure your openLog is oriented correctly in the Serial port

  • The log has weird characters —Make sure you have the serial baud rate set to 9600!

  • It still doesn’t workDrop us a line, we would love to help you figure it out!