-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple-data-logger.py
82 lines (62 loc) · 2.9 KB
/
simple-data-logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
###############################################
# #
# Python Data Logger D Burrin April 2016 #
# #
# Logs accelerometer to Sparkfun openlogger #
# #
###############################################
# http://microbitsandbobs.co.uk/downloads/MicroPi-Logger.py
# http://www.microbitsandbobs.co.uk/projects.html
#for more details on the microbit api see
#http://microbit-micropython.readthedocs.org/en/latest/microbit_micropython_api.html
#for more detils on the sparkfun open logger see
#https://www.sparkfun.com/tutorials/393
from microbit import *
#Configure the output rate for the microbit url
#it supports a range of bauds and strem types
#Openlogger supports th full range of bauds but seems fixed to 8N1
#As the default setting for open logger is 9600 baud i've left it alone
#and initilised the microbit to match
uart.init(baudrate=9600, bits=8, parity=None, stop=1, pins=None)
#Write a set of heading to the log file for use in your spreadsheet later
#the newline at the start is to seperate from the openlog control value that is written on initilaisation
uart.write("\nTime,X,Y,Z,\n")
#microbit infinity loop
while True:
#start logging
if button_a.is_pressed():
#Write a set of heading to the log file for use in your spreadsheet later
#the newline at the start is to seperate from the openlog control value that is written on initilaisation
uart.write("\nTime,X,Y,Z,\n")
#get the initialisation time in MS of the Microbit we'll use this later for tracking time
#running time is the number of miliseconds since power on
starttime = running_time()
#display an X to show logging has started
display.show("X")
while True:
#get time of data was logged
logtime = running_time()-starttime
#convert to string and write to uart
uart.write(str(logtime))
uart.write(",")
#get values from accelerometer - comes in as a list (x,y,z)
G_reading=accelerometer.get_values()
#write x value
uart.write(str(G_reading[0]))
#write the seperator
uart.write(",")
#Write y value
uart.write(str(G_reading[1]))
uart.write(",")
#Write Z value
uart.write(str(G_reading[2]))
#write new line character
uart.write("\n")
#stop logging on button b
if button_b.is_pressed():
#Clear the screen
display.clear()
#wait for 0.5 seconds to ensure last value is writtrn befofe exit
sleep(500)
break
display.show("Not Logging")