-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrealplot.py
More file actions
42 lines (33 loc) · 1.04 KB
/
Copy pathrealplot.py
File metadata and controls
42 lines (33 loc) · 1.04 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
import serial
import numpy as np
# from vpython import *
import matplotlib.pyplot as plt
from drawnow import *
arduinoDataStream = serial.Serial('/dev/ttyACM0',9600)
plt.ion() # indicate matplotlib that we are graphing live
tempc = []
humidity = []
count = 0
def makeLiveFigure():
#plt.ylim(10,50)
plt.title('Fluctuations in Humidity and Temperature')
plt.grid(True)
plt.plot(humidity,'o-',label='Humidity')
#plt2 = plt.twinx()
plt.plot(tempc,'o-',label='Temperature(C)')
plt.legend() # dynamically changes the location
while True:
if arduinoDataStream.inWaiting() > 0:
fluctuations = arduinoDataStream.readline()
#print(fluctuations)
dataStream = fluctuations.split(',')
hum = float(dataStream[0])
humidity.append(hum)
temp = float(dataStream[1])
tempc.append(temp)
drawnow(makeLiveFigure) # update the live graph
plt.pause(.0001) # delays the process
count += 1
if count > 35:
humidity.pop(0)
tempc.pop(0)