Microbit wireless data logger with printout

This project uses 2 microbits – one attached to a thermal till-roll printer as before. This time there’s a second microbit which can be battery-powered and put on a car, parachute, dog, whatever takes your fancy. Every 10 seconds it transmits radio data about its temperature, x/y/z data from the accelerometer and its compass heading. This is picked up by the printer’s microbit and logged on paper. (You could also save a file with the data which might be more useful!). Time information is missing of course, but if you know when you started you could always work that out…

Here’s the astonishingly compact Python code for microbit A which stays put and is attached to the printer. It constantly polls for incoming radio messages; when it gets one it prints the message with a few blank lines after. Flash it to the microbit using the Mu editor.

from microbit import *
import radio

uart.init(baudrate=19200, bits=8, parity=None, stop=1, tx=pin8, rx=None)

radio.on()
while True:
    incoming = radio.receive()
    if incoming:
        uart.write(incoming+"\n\n\n")

Here is the Python code for microbit B which flies away and has adventures in temperature and space. Once calibrated by drawing a circle, every 10 seconds it sends its temperature, compass heading and accelerometer data by radio to the printer. You could obviously increase the time or have its transmission triggered instead by another event such as a button press or even falling!

from microbit import *
import radio

compass.calibrate()
# remove next line to save power
display.scroll('transmitting data', wait=False, loop=True)
radio.on()

while True:
    x = accelerometer.get_x()
    y = accelerometer.get_y()
    z = accelerometer.get_z()
    tx_message = str(temperature())
         +"c  head "+str(compass.heading())
          +"\nx"+str(x)+" y"+str(y)+" z"+str(z)
    radio.send(tx_message)
    sleep(10000)   # wait 10 seconds
This entry was posted in microbit and tagged , , . Bookmark the permalink.

2 Responses to Microbit wireless data logger with printout

  1. David Held says:

    I saw in a recent video that you were using the mu editor and there was a plotter button. i just downloaded Mu and there is no plotter button. What is your download source?

    Ps Great Blog

Leave a Reply to blogmywiki Cancel reply