-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhumidityTest.py
More file actions
49 lines (40 loc) · 1.12 KB
/
humidityTest.py
File metadata and controls
49 lines (40 loc) · 1.12 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
import os
import serial
import time
import signal
import sys
import matplotlib.pyplot as plt
import matplotlib.animation as animation
plt.style.use('fivethirtyeight')
x = []
y1 = []
y2 = []
i = 0
arduino = serial.Serial(port='COM5', baudrate=9600, timeout=.1)
def signal_handler(sig, frame):
print('You pressed Ctrl+C!')
arduino.close()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def animate(i):
val = arduino.readline()
if val != "":
s="{0}.{1}".format(time.localtime().tm_min,
time.localtime().tm_sec)
humidity = val.split(',')[0]
temp = val.split(',')[1]
print s,val
x.append(i)
i +=1
y1.append(temp)
y2.append(humidity)
plt.cla()
plt.title('Temperature Vs Humidity')
plt.plot(x, y2, label = "Temperature")
plt.plot(x, y1, label = "Humudity")
# show a legend on the plot
plt.legend()
ani = animation.FuncAnimation(plt.gcf(), animate, interval=1000)
plt.tight_layout()
plt.show()
arduino.close()