Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial # import Serial Library
- import numpy as np # Import numpy
- import adafruit_max31856
- import matplotlib.pyplot as plt #import matplotlib library
- from drawnow import *
- import datetime
- import math
- import csv
- Temp1= []
- Temp2=[]
- plt.ion()
- cnt=0
- def makeFig(): #Create a function that makes our desired plot
- #plt.ylim(80,90) #Set y min and max values
- plt.title('My Super Beautiful Live Streaming Sensor Data :-)') #Plot the title
- plt.grid(True) #Turn the grid on
- plt.ylabel('Temperature') #Set ylabels
- plt.plot(Temp1, 'ro-',label='Temp1') #plot the temperature
- plt.plot(Temp2, 'b^-',label='Temp2')
- plt.legend(loc='upper left') #plot the legend
- plt.show()
- ## user-defined params
- serialPort = 'COM3' ## the serial device
- path = 'C:\\Users\\Alphinity\\Desktop\\python3\\' ## the output file path
- outputFile = "signalSerial.csv" ## the output file name
- ser = serial.Serial('COM3', 115200)
- outputFile = path + outputFile
- f = open(outputFile,'w') #create and/or open a file and give the command to write the informations
- f.write(outputFile) #write inside the file created
- f.close()
- print ("Writing the serial stream into file: " + outputFile)
- print (" [to see the stream: tail -f '+outputFile+' ]")
- print (" [to exit: ctrl+c (the elegant way :) ]")
- while True: # While loop that loops forever
- line = ser.readline()
- string = line
- Temp1.append(string[0]) #Build our tempF array by appending temp readings
- Temp2.append(string[1])
- drawnow(makeFig)
- plt.pause(.000001)
- cnt=cnt+1
- if(cnt>50): #If you have 50 or more points, delete the first one from the array
- Temp1.pop(0) #This allows us to just see the last 50 data points
- #Temp2.pop(0)
- if (string != ''):
- f = open(outputFile, 'a')
- f.write(str(string))
- f.write("\n")
- f.close()
- print(string.decode()) ## ctrl+c to stop the code
- valueRead.decode().strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement