empowering creative people

Videos / How to Datalog with Micro:bit Using OpenLog and uSD Cards

The Micro:bit by BBC is a great data collection tool, it just needs a little help remembering what it has measured! This tutorial is made for those Micro:bit projects where transmitting your sensor data over radio or Bluetooth to a computer just won’t cut it. To take it one step further, this solution uses MakeCode (it works with any code).

Search Videos

Related Content

Transcript

+

Hi, Steven here from Core Electronics, in this tutorial I'm going to show you how to make a standalone data logger using the Micro-Bit and the SparkFun open log the open logs.

A great tool because it takes incoming serial data and saves it onto an SD card and there's really nothing more than you need to do to make it work. All we need to do is redirect our serial data from the USB where it usually goes to our open log, so I'll show you how to do that within MakeCode. So do get our serial data to redirect to our open log, we just need to use this serial redirect to block MakeCode and then we're going to assign it to the pin 15 and 14 and I should mention that you'll need a break out of some sort to connect to your Micro-Bit too. So, you can access those pins because it's not easy to access any of those small pins on the bottom of the Micro-Bit without a breakout of some sort.

The next thing we want to do to make our file usable that's it's going to be created with the open log is we want to format it in a way that's it becomes a CSV, so what we want is we want headers with each item separated by a comma and then we want our respective data points separated by commas saved beneath it. So when we start up the program will join together all these different words into one string since we're recording microseconds time light acceleration and temperature and we'll set them all to the valuable header and then we'll write that line once, so then that will be our header within the file and then in our forever loop we'll copy and paste our header creation and change the variable to "row" and then we'll just put our inputs in each place of the header and then we'll write that.

So is often as is possible the Micro-Bit it is currently recording the running time in microseconds, the running time in milliseconds, the light level the acceleration of the board and the current temperature and it's saving that into an ever-growing log file on a microSD card with an open log. So something I should talk about is the baud rate that the open log uses, the default baud rate is 9600 which is pretty slow but it's good enough for most uses but if you really want to get as many data points as you can per second then it's probably best to crank up that baud rate to as high as it goes. So to change the battery on the open log, we'll put a micro SD card in it once turn it on and then take our micro SD card out and put it into an SD card reader in your computer and when you open it open it up there's going to be a config file and there's going to be a log file. So if we look at our config file it will look like this and these are the easily controlled settings that we can change with an open log and the first number is the bod number so it was 9600, I've changed it to a 115200 and because I changed that, saved it, put the SD card back and open log I now need to make the baud rate match on our serial redirect block, so it communicates properly.

To read the data that's saved on the SD card we need to take the SD card out and put it into the computer but it is possible with the open log to read directly off of the SD card but it requires some firmware changes and for this project I felt that it was perfectly fine to be able to just remove the SD card to check it. So, if you want to look at the data that's on the SD card all we need to do is remove it from the divet device and put it into an SD card reader on your computer and you will see the log file recorded here. So I've opened up one of my log files I have my header across the top and then all the data below it with timestamps if you're going to be recording a lot of data over a long period of time it's worthwhile to create a function within your code that converts the time in milliseconds or microseconds into something a little more usable like days and hours and minutes because milliseconds in microseconds can quickly become something that's a little hard to quantify or you're going to have to do math afterwards or of course you can just make a function for it within an Excel spreadsheet.

Once you're done but if the time in time grows high enough in milliseconds and microseconds it will turn negative and start counting down, so that limits the number of digits that the that the Micro-Bit it will transmit at once when trying to when trying to record time and say microseconds so it'll go all the way up to its maximum number of digits go negative count back down and then count back up again is many times as you give it time for, so we're recording quite a bit of or not a whole lot of data right now but I did some back of the napkin calculations and let it record for an hour and based on the size little log file we should be able to in a 16 gigabyte SD card, we should be able to log this amount of data for about 280 days before we run out of space.

comments