-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab3plot.py
77 lines (62 loc) · 1.73 KB
/
lab3plot.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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import sys, time, math
import serial
import serial.tools.list_ports
xsize = 120
try:
ser.close() # try to close the last opened port
except:
print('')
portlist=list(serial.tools.list_ports.comports())
print ('Available serial ports (will try to open the last one):')
for item in portlist:
print (item[0])
# configure the serial port
ser = serial.Serial(
port=item[0],
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.EIGHTBITS
)
ser.isOpen()
print ('To stop press Ctrl+C')
def data_gen():
t = data_gen.t
while True:
strin = ser.readline()
t+=1
val= float(strin.decode())
print(float(strin.decode()))
yield t, val
def run(data):
# update the data
t,y = data
if t>-1:
xdata.append(t)
ydata.append(y)
if t>xsize: # Scroll to the left.
ax.set_xlim(t-xsize, t)
line.set_data(xdata, ydata)
return line
def on_close_figure(event):
sys.exit(0)
data_gen.t = -1
fig = plt.figure()
fig.canvas.mpl_connect('close_event', on_close_figure)
ax = fig.add_subplot(111)
line, = ax.plot([], [], lw=2, label='Temperature curve')
ax.set_ylim(0, 250)
ax.set_xlim(0, xsize)
ax.grid()
ax.legend()
plt.title('Reflow Oven Tempereature by Group Marimba c. All Rights Reserved.')
plt.xlabel('Time (Seconds)')
plt.ylabel('Temperature (Celsius)')
xdata, ydata = [], []
# Important: Although blit=True makes graphing faster, we need blit=False to prevent
# spurious lines to appear when resizing the stripchart.
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=500, repeat=False)
plt.show()