Quantcast
Channel: Blog My Wiki! » Microbit
Viewing all articles
Browse latest Browse all 68

Microbit wireless data logger with printout

$
0
0

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

Viewing all articles
Browse latest Browse all 68

Trending Articles