Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import os
  2. import glob
  3. import time
  4.  
  5. os.system('modprobe w1-gpio')
  6. os.system('modprobe w1-therm')
  7.  
  8. base_dir = '/sys/bus/w1/devices/'
  9. device_folder = glob.glob(base_dir + '28*')[0]
  10. device_file = device_folder + '/w1_slave'
  11.  
  12. def read_temp_raw():
  13. f = open(device_file, 'r')
  14. lines = f.readlines()
  15. f.close()
  16. return lines
  17.  
  18. def read_temp():
  19. lines = read_temp_raw()
  20. while lines[0].strip()[-3:] != 'YES':
  21. time.sleep(0.2)
  22. lines = read_temp_raw()
  23. equals_pos = lines[1].find('t=')
  24. if equals_pos != -1:
  25. temp_string = lines[1][equals_pos+2:]
  26. temp_c = float(temp_string) / 1000.0
  27. return temp_c
  28.  
  29. while True:
  30. i=(read_temp())
  31. print i, 'Degree Celsius'
  32. time.sleep(1)
Add Comment
Please, Sign In to add comment