Data Logging with a microbit

Published October 29, 2016 by Sean

Here is an example of how the BBC micro:bit can be used as a data logger. I was specifically interested in capturing the voltage of a LiPo battery as it discharged into a fixed load (so I could determine the capacity). I’ve also made a video of how this arrangement can be used to monitor the voltage on a supercap as it charges and discharges in a circuit.

Test Setup

The microbit has 6 inputs which can be used as Analogue to Digital inputs, including pins[0..2]. These sample voltages from 0V to 3.3V, returning the results as an integer from 0 to 1023. It is important that the inputs are not taken above the supply rail (as discussed on Electronics stack-exchange here) so I have used a series resistor (6k8 Ω, since that was the first I found). I use a 10k Ω potentiometer to adjust the full-scale reading to the maximum voltage that I need at any particular time.

Data Logger circuit

The source code can be found on github. There are two python scripts, one for the microbit which takes readings and sends them over the USB serial port when either the voltage changes or a couple of minutes passes. This is a trade-off between generating lots of data and capturing fast moving events. I have one LED flashing rapidly to give me some confidence that it’s not crashed and two set up to show a voltage readout as two analogue indicators.

On a windows PC (provided you have the mbed serial port driver) it should be easy enough to use a serial terminal application to save the data to a file. Since I’m using Windows 10 and the serial drivers are not always reliable, I use crouton on my chromebook (an Ubuntu chroot environment) where I can run python. Running the simple_log.py (as root) will guess the port name, dump the data to a file and copy it to the screen.

Here is a graph of the data captured in the video.

SuperCap charge profile

 

The charge phase is very rapid and it also shows that after running for a few minutes the unit seems to turn off (and the voltage stabilises again). This shows how it can sometimes be useful to monitor a circuit for minutes or hours to catch interesting events.

The noise on the plot is an artifact of my sampling algorithm, which captures positive peaks in noise, but tends to avoid negative noise peaks.  If I was using this again, I might re-think that sampling strategy.

 

Filed under microbit,Science

Comments (0)

Comments RSS - Trackback - Write Comment

No comments yet

Write Comment

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close