Skip to content

Instantly share code, notes, and snippets.

@stlehmann
Created March 29, 2014 12:16
Show Gist options
  • Save stlehmann/9853451 to your computer and use it in GitHub Desktop.
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.
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