Advertisement
Guest User

Untitled

a guest
Aug 29th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import serial # import Serial Library
  2. import numpy as np # Import numpy
  3. import adafruit_max31856
  4. import matplotlib.pyplot as plt #import matplotlib library
  5. from drawnow import *
  6. import datetime
  7. import math
  8. import csv
  9.  
  10.  
  11. Temp1= []
  12. Temp2=[]
  13. plt.ion()
  14. cnt=0
  15.  
  16. def makeFig(): #Create a function that makes our desired plot
  17. #plt.ylim(80,90) #Set y min and max values
  18. plt.title('My Super Beautiful Live Streaming Sensor Data :-)') #Plot the title
  19. plt.grid(True) #Turn the grid on
  20. plt.ylabel('Temperature') #Set ylabels
  21. plt.plot(Temp1, 'ro-',label='Temp1') #plot the temperature
  22. plt.plot(Temp2, 'b^-',label='Temp2')
  23. plt.legend(loc='upper left') #plot the legend
  24.  
  25. plt.show()
  26.  
  27. ## user-defined params
  28.  
  29. serialPort = 'COM3' ## the serial device
  30. path = 'C:\\Users\\Alphinity\\Desktop\\python3\\' ## the output file path
  31. outputFile = "signalSerial.csv" ## the output file name
  32.  
  33.  
  34. ser = serial.Serial('COM3', 115200)
  35. outputFile = path + outputFile
  36.  
  37.  
  38. f = open(outputFile,'w') #create and/or open a file and give the command to write the informations
  39. f.write(outputFile) #write inside the file created
  40. f.close()
  41.  
  42. print ("Writing the serial stream into file: " + outputFile)
  43. print (" [to see the stream: tail -f '+outputFile+' ]")
  44. print (" [to exit: ctrl+c (the elegant way :) ]")
  45.  
  46. while True: # While loop that loops forever
  47. line = ser.readline()
  48. string = line
  49. Temp1.append(string[0]) #Build our tempF array by appending temp readings
  50. Temp2.append(string[1])
  51. drawnow(makeFig)
  52. plt.pause(.000001)
  53. cnt=cnt+1
  54. if(cnt>50): #If you have 50 or more points, delete the first one from the array
  55. Temp1.pop(0) #This allows us to just see the last 50 data points
  56. #Temp2.pop(0)
  57. if (string != ''):
  58. f = open(outputFile, 'a')
  59. f.write(str(string))
  60. f.write("\n")
  61. f.close()
  62. print(string.decode()) ## ctrl+c to stop the code
  63.  
  64. valueRead.decode().strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement