Skip to content

Instantly share code, notes, and snippets.

@mvidalgarcia
Created October 7, 2015 12:08
Show Gist options
  • Save mvidalgarcia/abe129d64fc09be596d5 to your computer and use it in GitHub Desktop.
Save mvidalgarcia/abe129d64fc09be596d5 to your computer and use it in GitHub Desktop.
import os
import time
os.system('modprobe w1-gpio')
os.system('modprobe w1_therm')
temp_sensor = '/sys/bus/w1/devices/28-0215635d39ff/w1_slave'
def temp_raw():
f = open(temp_sensor, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp():
lines = temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = temp_raw()
temp_output = lines[1].find('t=')
if temp_output != -1:
temp_string = lines[1].strip()[temp_output+2:]
temp_celsius = float(temp_string)/1000.0
return temp_celsius
while True:
print(read_temp())
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment