diff options
author | Pacien TRAN-GIRARD | 2015-04-17 11:09:45 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-04-17 11:09:45 +0200 |
commit | f26c24f83eba172804efbdf506cf18d19f48b176 (patch) | |
tree | 007b0fcfa2bb23495e5a3ed13b8f95a1d9108d27 /visualizer | |
download | museduino-f26c24f83eba172804efbdf506cf18d19f48b176.tar.gz |
Import project
Diffstat (limited to 'visualizer')
-rw-r--r-- | visualizer/visualizer.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/visualizer/visualizer.py b/visualizer/visualizer.py new file mode 100644 index 0000000..ed65384 --- /dev/null +++ b/visualizer/visualizer.py | |||
@@ -0,0 +1,53 @@ | |||
1 | |||
2 | BINS = 128 | ||
3 | |||
4 | |||
5 | import serial | ||
6 | |||
7 | s = serial.Serial("/dev/ttyACM0", 115200) | ||
8 | |||
9 | |||
10 | def acquire_data(): | ||
11 | |||
12 | nb_val = 0 | ||
13 | while nb_val != BINS+1: | ||
14 | l = s.readline() | ||
15 | d = l.decode("utf8") | ||
16 | v = d.split(' ') | ||
17 | nb_val = len(v) | ||
18 | |||
19 | n = [0] * BINS | ||
20 | for i in range(BINS): | ||
21 | try: | ||
22 | n[i] = int(v[i]) | ||
23 | |||
24 | except ValueError: | ||
25 | n[i] = 0 | ||
26 | |||
27 | return n | ||
28 | |||
29 | |||
30 | import matplotlib.pyplot as plt | ||
31 | import numpy as np | ||
32 | |||
33 | |||
34 | fig = plt.figure() | ||
35 | ax = fig.add_subplot(111) | ||
36 | |||
37 | li, = ax.plot(range(BINS)) | ||
38 | plt.axis([0, BINS, 0, 250]) | ||
39 | |||
40 | fig.canvas.draw() | ||
41 | plt.show(block=False) | ||
42 | |||
43 | |||
44 | while True: | ||
45 | try: | ||
46 | y = acquire_data() | ||
47 | print(y) | ||
48 | li.set_ydata(y) | ||
49 | fig.canvas.draw() | ||
50 | |||
51 | except KeyboardInterrupt: | ||
52 | break | ||
53 | |||