-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserial-to-arduino--data-capture.py
54 lines (41 loc) · 1.08 KB
/
serial-to-arduino--data-capture.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
#serialtoarduino2.py
import serial
ser = serial.Serial('/dev/tty.usbserial-A700dB2V', 115200, timeout = 2)
def main():
outfile=open("STMdata.csv","w")
point = [] #initialize point as a blank array
header = 0
while(header < 32768):
print "looking for header data..."
temp_var = ser.read(2)
if len(temp_var)>0:
(header_bg, header_sm) = temp_var
header_sm=ord(header_sm)
header_bg=ord(header_bg)
header=header_sm + (header_bg << 8)
print "found header: "
print header
outfile.write('header: ')
outfile.write(str(header))
outfile.write('\n')
data = 0
while(data < 32768):
# import pdb; pdb.set_trace()
temp_var = ser.read(2)
if len(temp_var)>1:
(data_bg, data_sm) = temp_var
data_sm=ord(data_sm)
data_bg = ord(data_bg)
data_bg = data_bg << 8
data = data_sm + data_bg
if len(point) == 3:
outfile.write(','.join(point))
outfile.write('\n')
point = []
point.append(str(data))
outfile.write('footer: ')
outfile.write(','.join(point))
outfile.write('\n')
point = []
outfile.close() #closes the file
main()