---
title: Datalogging with the micro:bit Part 2
description: If you are looking to track data in real-time using the micro:bit, try sending the data to a computer through a USB cable or using the radio functionality of the micro:bit.
image: https://lh4.googleusercontent.com/wxsRKk3HtmAyCWJWoDQnRtf18PF0VaUUvI2DiWPka3wHBKm5V9lN-dJ-YMw6MWjxtu72TKJNCr5gcSMrf95Q8v9h8QqWwEIHylcxyupExhKyAcY8dcX17p1jNb0BT5p93RAXzlTMXO-wMS80Fg
---

[![Sparkfun](https://www.sparkfuneducation.com/img/logo.png)](https://www.sparkfuneducation.com/index.html)

- [SparkFun Webstore](https://www.sparkfuneducation.com)
- [Higher Ed](https://sparkfuneducation.com/higher-ed/index.html)
- [Contact Us](https://www.sparkfuneducation.com/contact-us.html)
- [Follow Us](https://twitter.com/SparkFunEDU)

- [Home](https://www.sparkfuneducation.com)
- [Blog](https://blog.sparkfuneducation.com)
- [Curriculum](https://www.sparkfuneducation.com/curriculum.html)
- [PD/Events](https://www.sparkfuneducation.com/professional-dev.html)
- [KITS/Materials](https://www.sparkfuneducation.com/materials.html)
- [Educator Stories](https://www.sparkfuneducation.com/educator-stories.html)
- [Activities](https://activities.sparkfuneducation.com)

[Blog Home](https://blog.sparkfuneducation.com/) / [micro:bit](https://blog.sparkfuneducation.com/topic/microbit) / Datalogging with the micro:bit Part 2

<https://blog.sparkfuneducation.com/rss.xml>

# Datalogging with the micro:bit Part 2

BY [Derek Runberg](https://blog.sparkfuneducation.com/author/derek-runberg) 8/23/18 6:24 AM

[3](https://blog.sparkfuneducation.com/datalogging-with-the-microbit-part-2#comments-listing)

[micro:bit](https://blog.sparkfuneducation.com/topic/microbit), [programming](https://blog.sparkfuneducation.com/topic/programming), [microcontroller](https://blog.sparkfuneducation.com/topic/microcontroller), [helpful information](https://blog.sparkfuneducation.com/topic/helpful-information)

![](https://blog.sparkfuneducation.com/hubfs/EDU/BLOG%20Images/Derek.jpg)

In the [first installment](https://blog.sparkfuneducation.com/remote-sensing-and-datalogging-with-the-microbit) of this short series on data logging with the micro:bit we looked at how to use the SparkFun OpenLog to log data to a microSD card over a longer period of time. The OpenLog is a great tool for doing that; creating a project that logs data every couple of minutes and let the program run for hours or days. But, what about looking at data real time? In this post we will explore using serial data once again, but this time sending it to your computer through your USB cable.

## Serial Redirect

![Serial Redirect code using MakeCode](https://lh4.googleusercontent.com/IpfmRSGBZ7C_EXpKr1OutrHgzri9U-is1sGPQkOXHT_BHs9_3SgrfDmFXo3FagoXh_rZ5WlSHauQDvHuHBagY6utpdwNUXtzr8MNrI0Nu3RITliOoh1P4yKvGeqlfmJ-4AvfWls1-mM6M-Nxcg)

In the [previous post](https://blog.sparkfuneducation.com/remote-sensing-and-datalogging-with-the-microbit), we used the serial blocks to send data over pin 0 to the OpenLog. For this project, we need to redirect that serial data to the USB Port. We do this by using the Serial Redirect to USB block and we place it in the On Start event. This will redirect any Serial functions to USB rather than a pin.

---

## Collecting Data

![forever loop with serial light level using MakeCode](https://lh4.googleusercontent.com/J6ldSeAWf0rD7e3AZrbf0jSzL9Gvwsf40FwU-63rE2GmiizCykSBx7x357Qv52mkxpz4T-d9p2ZcPc_0oVQtGMGssTJ6pKV3zifBPc2D36yNu00LEygvs4UbntBw-pwV4b3vUb-W9L-Jnfm_vw)

Now that the Serial data is redirected to the USB cable we need to collect some data and send it! In the **forever** event loop we read the light value using the light sensor built into the LED array on the micro:bit, which we access through the Input called **light level**, and then turn that into a string using the **join** block trick (see the first blog post for more on this) to send that value as a line over the serial UART with no delay to get as accurate and responsive data as possible using the **serial write line** block. Perfect! Go ahead and save and upload that program to your micro:bit. But wait… the micro:bit doesn't seem to be doing anything?!

---

## Viewing the Data

OK, you are now confused as to what your micro:bit is actually doing. The micro:bit is reading the light value of the room you are in and sending that value as a number over the USB cable to the computer or Chromebook that you are programming on. What we have to do now is figure out how to view that data and capture it.

![Serial Monitor app download](https://lh4.googleusercontent.com/6ctne4hGeVvyzYvXAX00nn7LE9iIsCaaOeEbRs2XGZXtLcU0OKqwz8bVUG73afGuHJq_KzmAz-b9kg4cFuHy1cTcgPSbZhYckpFWqlrlJ2bKYUlGDgAgNhu92jnx20Bu894dI0WbfJioVXlwqg)

There are a number of tools out there to allow you to view and interact with devices that are talking serial to your computer. For this application with the micro:bit, we looked for something that would work on both full blown operating systems (Mac OS and Windows), but also on Chromebooks that you find in the classroom in the form of a chrome app. Enter the Chrome Serial Monitor App.

You can search for “Serial Monitor” in the chrome app store or [navigate directly to the app here](https://chrome.google.com/webstore/detail/serial-monitor/ohncdkkhephpakbbecnkclhjkmbjnmlo?utm_source=chrome-ntp-launcher).

This app is incredibly simple, but a powerful tool for doing precisely what we are trying to do. Once you have installed the app, go ahead and open it. There are two drop down menus for you to pick a few things. The first option is your serial port, there should be only one option here, but if there are multiple, try the options below.

1. Windows Machine… pick your highest COM Port
2. Mac the micro:bit is a dev/tty device with a few random numbers at the end
3. Chromebook… see #2

Once you have selected the port, it is time to select the baud rate that the device is communicating at. For the micro:bit over USB this number is 115200. It is not super clear in any documentation, we had to figure this out for ourselves. Now you know.

![data retrieved from micro:bit](https://blog.sparkfuneducation.com/hs-fs/hubfs/EDU/BLOG%20Images/Screen%20Shot%202018-07-27%20at%203.29.57%20PM.png?width=600&name=Screen%20Shot%202018-07-27%20at%203.29.57%20PM.png)

Now that you have selected both the **serial port** and **baud rate** you can now click the **Connect** button. If everything is working properly, you should start seeing numbers list out in the field below the drop-down menus. This is your light sensor data. Place your hand over the micro:bit's LED array and see the value drop. Once you let this run for a bit of time you can then copy and paste these values from the window into a .csv file, or directly into a spreadsheet program of your choice.

Boom, you have data.

---

## Going the Distance

OK, many of you may not be impressed. You may be thinking to yourself…"Yeah, but now I am tethered to the computer via a USB cable…not cool!”

But wait, there's more!

If you have two micro:bits on hand, you can leverage the Radio functionality of the micro:bits combined with USB serial by turning one of the micro:bits into a base station for a remote wireless logger somewhere out in the field.

---

## Programming the Base Station

![programming a micro:bit base station using MakeCode](https://lh3.googleusercontent.com/HMEPT__Sdski7Y7D4ZvJKPm7Qy362V5tJse5FTkypycoAJ4o0VHtR2_fe3MyVeG1-0JGv9gnH6qmJDygH4h5W_wPA0w44HmxVURs1Y263o1kzDkWxQF_S-EyXwfwgdmn0tMssCS5cYrcwIRM1A)

First off, let’s write the program for the base station. It should look somewhat familiar to you with some small changes. In your **On Start** event we have our **serial redirect to USB** block and we **radio set group** to 1. We need to make sure that we set the radio group value to the same number on both micro:bits otherwise they will not talk/listen to one another.

We then add an **On Radio Received number** event block. This function will happen any time that the radio receives a number from the other micro:bit. In this function we use the **serial write line** block with that same setup we used before with the **join** block, but instead of the light value, we grabbed the **receivedNumber** variable from the variable drawer. So, anytime a number is received over the radio, the base station turns that number into a string and sends that over USB to the chrome Serial Monitor app.

![setting up radio groups using MakeCode](https://lh4.googleusercontent.com/wxsRKk3HtmAyCWJWoDQnRtf18PF0VaUUvI2DiWPka3wHBKm5V9lN-dJ-YMw6MWjxtu72TKJNCr5gcSMrf95Q8v9h8QqWwEIHylcxyupExhKyAcY8dcX17p1jNb0BT5p93RAXzlTMXO-wMS80Fg)

As with the base station, we **radio set group** to the same number as we used before.

***Note: if you are using this in the classroom your students will need to work out their radio groups in pairs, or you can assign them.***

---

## Not working!?

In the **forever** event, we use the **radio send number** block to send the light level over the radio and then use a **pause** block to wait 200 milliseconds before repeating again. Pretty simple! Once you save this program to your second micro:bit and power both up (making sure that the base station is connected to the chrome Serial Monitor app) you should start to see data populating in the app which is the light level of the remote / mobile unit. If you don’t get data try these tricks:

1. Double check the connection, port and baud rate of your base station. This is a common error even for seasoned vets of serial devices.
2. Double check your radio group and/or make sure someone else is not on the same group as you. Getting odd numbers? This is probably the issue.
3. When all else fails reinstall your programs to your base station and your remote unit.

With that, I want to bid you adieu and happy data logging! If you have any ideas, questions or comments please use the comments area for this post to ask, I would be happy to help you out with using this technique in the classroom!

- [Tweet](https://twitter.com/share)

### Subscribe to SparkFun Education Blog

### Topics

- [helpful information (79)](https://blog.sparkfuneducation.com/topic/helpful-information)
- [Maker Education (60)](https://blog.sparkfuneducation.com/topic/maker-education)
- [teaching tools (55)](https://blog.sparkfuneducation.com/topic/teaching-tools)
- [getting started (54)](https://blog.sparkfuneducation.com/topic/getting-started)
- [Guest Post (44)](https://blog.sparkfuneducation.com/topic/guest-post)
- [computer science (40)](https://blog.sparkfuneducation.com/topic/computer-science)
- [micro:bit (38)](https://blog.sparkfuneducation.com/topic/microbit)
- [student projects (37)](https://blog.sparkfuneducation.com/topic/student-projects)
- [STEM (36)](https://blog.sparkfuneducation.com/topic/stem)
- [programming (34)](https://blog.sparkfuneducation.com/topic/programming)
- [STEAM (31)](https://blog.sparkfuneducation.com/topic/steam)
- [Events (28)](https://blog.sparkfuneducation.com/topic/events)
- [Arduino (25)](https://blog.sparkfuneducation.com/topic/arduino)
- [robotics (20)](https://blog.sparkfuneducation.com/topic/robotics)
- [e-textiles (18)](https://blog.sparkfuneducation.com/topic/e-textiles)
- [Professional Development (17)](https://blog.sparkfuneducation.com/topic/professional-development)
- [basic circuits (17)](https://blog.sparkfuneducation.com/topic/basic-circuits)
- [What is a (16)](https://blog.sparkfuneducation.com/topic/what-is-a)
- [announcement (16)](https://blog.sparkfuneducation.com/topic/announcement)
- [makerspace (15)](https://blog.sparkfuneducation.com/topic/makerspace)
- [Community Partnership Program (14)](https://blog.sparkfuneducation.com/topic/community-partnership-program)
- [Training (13)](https://blog.sparkfuneducation.com/topic/training)
- [raspberry pi (13)](https://blog.sparkfuneducation.com/topic/raspberry-pi)
- [python (11)](https://blog.sparkfuneducation.com/topic/python)
- [AVC (10)](https://blog.sparkfuneducation.com/topic/avc)
- [paper circuits (10)](https://blog.sparkfuneducation.com/topic/paper-circuits)
- [Makey Makey (8)](https://blog.sparkfuneducation.com/topic/makey-makey)
- [SIK (8)](https://blog.sparkfuneducation.com/topic/sik)
- [Adventures in Science (7)](https://blog.sparkfuneducation.com/topic/adventures-in-science)
- [microcontroller (7)](https://blog.sparkfuneducation.com/topic/microcontroller)
- [Internet of Things (5)](https://blog.sparkfuneducation.com/topic/internet-of-things)
- [Processing (4)](https://blog.sparkfuneducation.com/topic/processing)
- [Javascript (3)](https://blog.sparkfuneducation.com/topic/javascript)
- [LilyPad (3)](https://blog.sparkfuneducation.com/topic/lilypad)
- [funding (3)](https://blog.sparkfuneducation.com/topic/funding)
- [weather (3)](https://blog.sparkfuneducation.com/topic/weather)
- [Insider (1)](https://blog.sparkfuneducation.com/topic/insider)
- [Johnny-five (1)](https://blog.sparkfuneducation.com/topic/johnny-five)

All Tags

### Recent Authors

- [Megan Hemmings (79)](https://blog.sparkfuneducation.com/author/megan-hemmings)
- [Maya Kleinbort (22)](https://blog.sparkfuneducation.com/author/maya-kleinbort)
- [Derek Runberg (21)](https://blog.sparkfuneducation.com/author/derek-runberg)
- [Shane Diller (16)](https://blog.sparkfuneducation.com/author/shane-diller)
- [Jeff Branson (15)](https://blog.sparkfuneducation.com/author/jeff-branson)
- [Angela Sheehan (12)](https://blog.sparkfuneducation.com/author/angela-sheehan)
- [Melissa Felderman (9)](https://blog.sparkfuneducation.com/author/melissa-felderman)
- [Megan Arnold (8)](https://blog.sparkfuneducation.com/author/megan-arnold)
- [Brian Huang (6)](https://blog.sparkfuneducation.com/author/brian-huang)
- [Shawn Hymel (6)](https://blog.sparkfuneducation.com/author/shawn-hymel)
- [Shelby Landsman (6)](https://blog.sparkfuneducation.com/author/shelby-landsman)
- [Jahnell Pereira (5)](https://blog.sparkfuneducation.com/author/jahnell-pereira)
- [Hailey Blessing (5)](https://blog.sparkfuneducation.com/author/hailey-blessing)
- [Mike Grusin (3)](https://blog.sparkfuneducation.com/author/mike-grusin)
- [Peter Hanson (3)](https://blog.sparkfuneducation.com/author/peter-hanson)
- [Andrew Milne (3)](https://blog.sparkfuneducation.com/author/andrew-milne)
- [Toni Klopfenstein (2)](https://blog.sparkfuneducation.com/author/toni-klopfenstein)
- [Joanna Drusin (1)](https://blog.sparkfuneducation.com/author/joanna-drusin)
- [Joe Romano (1)](https://blog.sparkfuneducation.com/author/joe-romano)
- [Mrinali P. Kesavadas (1)](https://blog.sparkfuneducation.com/author/mrinali-p-kesavadas)
- [Christa Flores (1)](https://blog.sparkfuneducation.com/author/christa-flores)
- [Michelle Shorter (1)](https://blog.sparkfuneducation.com/author/michelle-shorter)
- [Colleen Graves (1)](https://blog.sparkfuneducation.com/author/colleen-graves)
- [Janelle Curtis (1)](https://blog.sparkfuneducation.com/author/janelle-curtis)
- [Eric Bogatin (1)](https://blog.sparkfuneducation.com/author/eric-bogatin)
- [Athena Zhang Baker (1)](https://blog.sparkfuneducation.com/author/athena-zhang-baker)
- [Janice Levenhagen (1)](https://blog.sparkfuneducation.com/author/janice-levenhagen)
- [Carol Hamilton (1)](https://blog.sparkfuneducation.com/author/carol-hamilton)
- [Vanessa Lail (1)](https://blog.sparkfuneducation.com/author/vanessa-lail)
- [Bobby Chan (1)](https://blog.sparkfuneducation.com/author/bobby-chan)
- [Glenn Samala (1)](https://blog.sparkfuneducation.com/author/glenn-samala)
- [Zack Weaver (1)](https://blog.sparkfuneducation.com/author/zack-weaver)
- [Dr. Jean-Sébastien Blouin (1)](https://blog.sparkfuneducation.com/author/dr-jean-sébastien-blouin)
- [Daphne Sipes (1)](https://blog.sparkfuneducation.com/author/daphne-sipes)
- [Axel Reitzig (1)](https://blog.sparkfuneducation.com/author/axel-reitzig)
- [Justin Weisz (1)](https://blog.sparkfuneducation.com/author/justin-weisz)
- [Kylie Peppler (1)](https://blog.sparkfuneducation.com/author/kylie-peppler)
- [Michael Megliola (1)](https://blog.sparkfuneducation.com/author/michael-megliola)
- [Casey Kuhns (1)](https://blog.sparkfuneducation.com/author/casey-kuhns)
- [Rebecca Grabman (1)](https://blog.sparkfuneducation.com/author/rebecca-grabman)
- [Sylvia Martinez (1)](https://blog.sparkfuneducation.com/author/sylvia-martinez)
- [Charles Randolph (1)](https://blog.sparkfuneducation.com/author/charles-randolph)
- [Ira Sather-Olson (1)](https://blog.sparkfuneducation.com/author/ira-sather-olson)
- [Kathy Strickland (1)](https://blog.sparkfuneducation.com/author/kathy-strickland)
- [Pete Lewis (1)](https://blog.sparkfuneducation.com/author/pete-lewis)
- [Jamie Roth (1)](https://blog.sparkfuneducation.com/author/jamie-roth)
- [Mimi Tran Zambetti (1)](https://blog.sparkfuneducation.com/author/mimi-tran-zambetti)
- [Ryan Jenkins (1)](https://blog.sparkfuneducation.com/author/ryan-jenkins)
- [Kristen Deuschle (1)](https://blog.sparkfuneducation.com/author/kristen-deuschle)
- [Erika Myers (1)](https://blog.sparkfuneducation.com/author/erika-myers)
- [Sara Gonzalez (1)](https://blog.sparkfuneducation.com/author/sara-gonzalez)
- [Celeste Moreno (1)](https://blog.sparkfuneducation.com/author/celeste-moreno)
- [Samantha Nagle (1)](https://blog.sparkfuneducation.com/author/samantha-nagle)
- [Pearce Melcher (1)](https://blog.sparkfuneducation.com/author/pearce-melcher)

All Authors

### Recent Posts

### Submit Your Idea

[![SparkFun Education](https://www.sparkfuneducation.com/img/logo.png)](http://www.sparkfuneducation.com/index.html)

#### Other Resources

- [Contact Us](http://www.sparkfuneducation.com/contact-us.html)
- [About SparkFun](http://www.sparkfun.com)
- [FAQs](https://www.sparkfun.com/static/faq)

- [Customer Service](https://www.sparkfun.com/support)
- [Shipping](https://www.sparkfun.com/support)
- [Terms and Conditions](https://www.sparkfun.com/terms)

#### Sign Up for Newsletter

© Copyright 2016. All Rights Reserved.