Advertisement
Guest User

Data logger for DS18B20 on Raspberry Pi

a guest
Feb 6th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. import time
  2. import matplotlib
  3. matplotlib.use('Agg')
  4. import matplotlib.pyplot as plt
  5.  
  6. names = ("Fenster","Heizung","Gluehbirne","Schreibtisch","RasPi-Prozessor")
  7. mask = (1,1,1,1,1)
  8. file = []
  9. for i in range(5):
  10.     file.insert(i,open("/home/pi/logs/"+names[i]+".csv", 'w'))
  11.     file[i].seek(0,2)
  12. keys = ("28-0415a30daeff", "28-0415a30e46ff", "28-0415a35d77ff", "28-0415a35bd5ff", "28-0415a30f6eff")
  13. times = [[],[],[],[],[]]
  14. data = [[],[],[],[],[]]
  15. start = time.time()
  16. while 1:
  17.     for i in range(5):
  18.         if not mask[i]:
  19.             continue
  20.         ausgabe = open("/sys/bus/w1/devices/"+keys[i]+"/w1_slave").readlines()
  21.         ausgabe[0] = ausgabe[0].split(' ')[11]
  22.         ausgabe[1] = ausgabe[1].split("t=")[1]
  23.         ausgabe[1] = ausgabe[1].rstrip()
  24.         if int(ausgabe[1]) == 85000:
  25.             continue
  26.         if ausgabe[0] == "YES\n":
  27.             file[i].write(str(time.time())+"; "+ausgabe[1]+";\n")
  28.             file[i].flush()
  29.             times[i].append(time.time()-start)
  30.             data[i].append(int(ausgabe[1]))
  31.             print names[i]
  32.             print data[i]
  33.             plt.plot(times[i],data[i])
  34.             plt.xlabel('Zeit ab Start [s]')
  35.             plt.ylabel('Temperatur [mC]')
  36.             plt.title(names[i])
  37.             plt.grid(True)
  38.             plt.savefig("/home/pi/logs/"+names[i]+".png", format="png")
  39.             plt.savefig("/home/pi/logs/"+names[i]+".pdf", format="pdf")
  40.             plt.cla()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement