Created
March 29, 2014 12:16
-
-
Save stlehmann/9853451 to your computer and use it in GitHub Desktop.
Raspberry Pi - Python code for reading temperature data from a connected sensor on the w1 bus. The temperature data is printed out on a connected Adafruit 16x2 LCD plate.
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
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate | |
from time import sleep | |
def read_temp(): | |
""" | |
Read temperature from w1 bus. | |
""" | |
with open("/sys/bus/w1/devices/28-000004ac7761/w1_slave") as f: | |
text = f.read() | |
secondline = text.split("\n")[1] | |
temperaturedata = secondline.split(" ")[9] | |
temperature = float(temperaturedata[2:]) / 1000 | |
return temperature | |
#Init the Adafruit LCD Plate | |
lcd = Adafruit_CharLCDPlate() | |
lcd.numlines=2 | |
lcd.clear() | |
msg = "Temperatur:" | |
lcd.message(msg) | |
while True: | |
lcd.setCursor(0, 1) | |
lcd.message("%.2f C" % read_temp()) | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment