Created
October 7, 2015 12:08
-
-
Save mvidalgarcia/abe129d64fc09be596d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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