Use micro:bit as a wireless data logger recording readings from its sensors.
2 Micro:bits (V2)
1 Power Pack
1 USB cable
Personal Computer
Python Editing Environment or Python Mu (has a plotting option in built)
Toy Car
Ramp
Elastic Bands
Flash the transmitter program onto a micro:bit with battery pack and either attach it to something that moves (like the inside of a salad spinner) or get ready to play catch with it. The program takes constant accelerometer readings of the forces in 3 dimensions (x, y and z axes) and transmits them by radio.
Connect the receiver micro:bit to a computer by USB and flash the logger program on to it using the Mu Python editor app.
This micro:bit receives the accelerometer data and send as serial data to your computer. Click on the ‘Plotter’ button in Mu and you should see graphs of the live data readings appear on the screen.
Place the sensor micro:bit on each side and see how the readings in each axis change. Throw it in the air, spin it in a salad spinner: what do you see?
Mu saves the numerical data as a CSV (comma separated values) file in your computer's home folder. Look in 'mu_code' and then the 'data_capture' folder.
You can open the CSV file in a spreadsheet program to analyse. If you delete the second and third time columns, leaving only the first, you can plot the data on a scatter graph in your spreadsheet showing how the forces change over time.
Python
1 from microbit import *
2 import radio
3 radio.config(group=99)
4 radio.on()
5
6 while True:
7 force = accelerometer.get_strength()
8 radio.send(str(force))
9 sleep(20)
Python
1 from microbit import *
2 import radio
3 import log
4
5 log.set_labels('test', 'force')
6 radio.config(group=99)
7 radio.on()
8
9 test = 0
10 observing = False
11
12 while True:
13 if observing:
14 record = radio.receive()
15 if record:
16 log.add({
17 'test' : test,
18 'force': record
19 })
20 if button_b.was_pressed():
21 observing = False
22 display.show(Image.NO)
23 elif button_a.was_pressed():
24 observing = True
25 test += 1
26 display.show(str(test))
Add Comments to the code to demonstrate your understanding of how it works.
Pause the receiver by pressing 'b', then open the MY_DATA.HTM file to check data has been logged. If so, move on, otherwise you may need to do some debugging to find out what is not working as expected.
ReDownload/Flash the program on to your micro:bit and run the tests, changing the variables(e.g height of ramp). Press the 'a' button to start the recording of each and the 'b' button to finish.
Open the MY_DATA.HTM file and download the table as a CSV file.
Open the CSV file in spreadsheet software and create a line graph for the force measured over time. You should 'clean up' the data (e.g. remove data points captured in error) and set each test up as a series before graphing.