Micro:bit Space Launch Lesson 9 (Storing Data)


Lesson 9 – Storing Data

Our previous lessons have all focussed on different ways to measure and monitor things using our micro:bits. When we send them up into near-space there will be no one to press buttons, read the screen or take note of the various readings that we will want to capture. We also cannot transmit the data anywhere so we have to find a way to store the data on the micro:bit or another device so that we can retrieve and analyse the information at a later date.

This also means that we need to find our payload again once the balloon has burst and the box returns back to earth. Fortunately we have that part covered and we will be using both a GPS SMS device and a satellite tracker to helps us pinpoint the exact location. You can find more information about the tracking of our balloon journey on the Space Launch FAQs page.

We now need to focus on how to store the measurements we take and fortunately there are a couple of ways we can do this. The first uses an external datalogger (provided by SparkFun) which when connected to the micro:bit enables us to save our measurements to a microSD card which we can plug into a computer to retrieve the information later. I’ll give a brief overview of how this works, and whilst we will use this approach for one of our experiments, it was not the subject of a lesson with the pupils due to the cost of the device and complexity of the implementation. I’ll provide some details of the second option that we used with the pupils later on.

The first approach was to use a datalogging device, the OpenLog, made by SparkFun specifically for this sort of application. The tiny device can be wired to the microbit and it takes a microSD card and lets you store information from the micro:bit on to the card for retrieval later.


The OpenLog requires 3.3volts as a minimum so does not power up reliably when powered from the micro:bit directly – an external source of power is required – I used a USB powerbar and ran it on the 5v supply. The other two connections required go from the OpenLog to the microbit and the PXT editor lets you decide which pins are used to write to the Serial device.

The simple example above will store the temperature from the micro:bit sensor onto the SD card when button A is pressed.  This file can then be opened on a PC or Mac to review the data later.  The TX pin of the micro:bit (pin 8 in my example above) has to be connected to the RX pin of the OpenLog and RX pin (pin 12) goes to the TX pin out.  If you require more details then there’s plenty of information on the OpenLog on the Sparkfun website.

The second approach is somewhat easier and uses the micro:bit filesystem to store information.  The PXT editor has support for using the filesystem but it is very much a beta function & can be a little confusing to use (currently the editor may report some errors but the code does work when running on the micro:bit).  The following commands are available when you add the FileSystem package via the PXT editor:

For our computer club lesson we kept things simple and used the “Settings Read” and “Settings Save” block to record a high score in a game that is saved even when the micro:bit is switched off or reset.  The other blocks for appending lines/files/strings all require you to then output the file to a serial console in order to retrieve the information and this was too complex to implement in our lesson but I did demonstrate the capability so that the students understood how this would be used when our micro:bit experiments are launched!

This was the simple game that we used to demonstrate the micro:bit filesystem capability – on start the current high score is shown, a countdown from 3 is performed and then the player has to press the B button as many times as possible in the 5 second time limit.  The players score is then shown and if it is higher than the current high score then it is saved to the micro:bit and replaces the current highest score.

The game was very popular and was a simple way to demonstrate how the micro:bit can save data to it’s flash memory for retrieval later – which will be very important if we’re to get any readings back from space! It’s important to note that the filesystem is erased when the micro:bit is flashed with a new hex file.

Back to Mission Control

C a l e n d a r
S e a r c h
S o c i a l   M e d i a
S u b s c r i b e