blob: ed6538461902d342b7e4db3d71bfb88bd79f0052 (
plain)
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
|
BINS = 128
import serial
s = serial.Serial("/dev/ttyACM0", 115200)
def acquire_data():
nb_val = 0
while nb_val != BINS+1:
l = s.readline()
d = l.decode("utf8")
v = d.split(' ')
nb_val = len(v)
n = [0] * BINS
for i in range(BINS):
try:
n[i] = int(v[i])
except ValueError:
n[i] = 0
return n
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
li, = ax.plot(range(BINS))
plt.axis([0, BINS, 0, 250])
fig.canvas.draw()
plt.show(block=False)
while True:
try:
y = acquire_data()
print(y)
li.set_ydata(y)
fig.canvas.draw()
except KeyboardInterrupt:
break
|