-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataLogger.py
More file actions
62 lines (47 loc) · 1.15 KB
/
dataLogger.py
File metadata and controls
62 lines (47 loc) · 1.15 KB
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
import serial
import matplotlib.pyplot as plt
port = "COM3"
baud = 9600
fName = "EMG_Data.csv"
print("Initialising .... ")
ser = serial.Serial(port, baud, timeout = 1)
print("Connected to Arduino port:" + port)
file = open(fName, "a")
print("Data read")
xData = []
yData = []
# plt.close("all")
# plt.figure()
# plt.ion()
# plt.show()
i = 0
with open(fName, "w") as f:
while(i < 100):
l = str(ser.readline())[2:-5]
if(i == 0):
continue
f.write(str(l) + "\n")
print(i, ":", l)
line = l.split(",")
try:
x = float(i)
y = float(line[0])
xData.append(x)
yData.append(y)
# plt.cla()
# plt.plot(y)
# plt.pause(0.01)
except:
pass
i +=1
#Ensuring equal sizes for collected x and y data
if(len(xData) - len(yData) > 0):
for i in range(len(xData) - len(yData)):
yData.append(0)
if(len(xData) - len(yData) < 0):
for i in range( len(yData)- len(xData) ):
xData.append(0)
#Displaying collected data
plt.ylim(0, 4095)
plt.plot(xData, yData)
plt.show()