1import serial # import Serial Library
2import numpy # Import numpy
3import matplotlib.pyplot as plt #import matplotlib library
4from drawnow import *
5
6tempF= []
7pressure=[]
8arduinoData = serial.Serial('com11', 115200) #Creating our serial object named arduinoData
9plt.ion() #Tell matplotlib you want interactive mode to plot live data
10cnt=0
11
12def makeFig(): #Create a function that makes our desired plot
13 plt.ylim(80,90) #Set y min and max values
14 plt.title('My Live Streaming Sensor Data') #Plot the title
15 plt.grid(True) #Turn the grid on
16 plt.ylabel('Temp F') #Set ylabels
17 plt.plot(tempF, 'ro-', label='Degrees F') #plot the temperature
18 plt.legend(loc='upper left') #plot the legend
19 plt2=plt.twinx() #Create a second y axis
20 plt.ylim(93450,93525) #Set limits of second y axis- adjust to readings you are getting
21 plt2.plot(pressure, 'b^-', label='Pressure (Pa)') #plot pressure data
22 plt2.set_ylabel('Pressrue (Pa)') #label second y axis
23 plt2.ticklabel_format(useOffset=False) #Force matplotlib to NOT autoscale y axis
24 plt2.legend(loc='upper right') #plot the legend
25
26
27while True: # While loop that loops forever
28 while (arduinoData.inWaiting()==0): #Wait here until there is data
29 pass #do nothing
30 arduinoString = arduinoData.readline() #read the line of text from the serial port
31 dataArray = arduinoString.split(',') #Split it into an array called dataArray
32 temp = float( dataArray[0]) #Convert first element to floating number and put in temp
33 P = float( dataArray[1]) #Convert second element to floating number and put in P
34 tempF.append(temp) #Build our tempF array by appending temp readings
35 pressure.append(P) #Building our pressure array by appending P readings
36 drawnow(makeFig) #Call drawnow to update our live graph
37 plt.pause(.000001) #Pause Briefly. Important to keep drawnow from crashing
38 cnt=cnt+1
39 if(cnt>50): #If you have 50 or more points, delete the first one from the array
40 tempF.pop(0) #This allows us to just see the last 50 data points
41 pressure.pop(0)
42
1import serial # import Serial Library
2import numpy # Import numpy
3import matplotlib.pyplot as plt #import matplotlib library
4from drawnow import *
5
6tempF= []
7pressure=[]
8arduinoData = serial.Serial('com11', 115200) #Creating our serial object named arduinoData
9plt.ion() #Tell matplotlib you want interactive mode to plot live data
10cnt=0
11
12def makeFig(): #Create a function that makes our desired plot
13 plt.ylim(80,90) #Set y min and max values
14 plt.title('My Live Streaming Sensor Data') #Plot the title
15 plt.grid(True) #Turn the grid on
16 plt.ylabel('Temp F') #Set ylabels
17 plt.plot(tempF, 'ro-', label='Degrees F') #plot the temperature
18 plt.legend(loc='upper left') #plot the legend
19 plt2=plt.twinx() #Create a second y axis
20 plt.ylim(93450,93525) #Set limits of second y axis- adjust to readings you are getting
21 plt2.plot(pressure, 'b^-', label='Pressure (Pa)') #plot pressure data
22 plt2.set_ylabel('Pressrue (Pa)') #label second y axis
23 plt2.ticklabel_format(useOffset=False) #Force matplotlib to NOT autoscale y axis
24 plt2.legend(loc='upper right') #plot the legend
25
26
27while True: # While loop that loops forever
28 while (arduinoData.inWaiting()==0): #Wait here until there is data
29 pass #do nothing
30 arduinoString = arduinoData.readline() #read the line of text from the serial port
31 dataArray = arduinoString.split(',') #Split it into an array called dataArray
32 temp = float( dataArray[0]) #Convert first element to floating number and put in temp
33 P = float( dataArray[1]) #Convert second element to floating number and put in P
34 tempF.append(temp) #Build our tempF array by appending temp readings
35 pressure.append(P) #Building our pressure array by appending P readings
36 drawnow(makeFig) #Call drawnow to update our live graph
37 plt.pause(.000001) #Pause Briefly. Important to keep drawnow from crashing
38 cnt=cnt+1
39 if(cnt>50): #If you have 50 or more points, delete the first one from the array
40 tempF.pop(0) #This allows us to just see the last 50 data points
41 pressure.pop(0)
42
43