Skip to content

Instantly share code, notes, and snippets.

@pkramme
Created June 9, 2019 15:26
Show Gist options
  • Save pkramme/4700bf3582d54a92e6d65565a5112ecc to your computer and use it in GitHub Desktop.
Save pkramme/4700bf3582d54a92e6d65565a5112ecc to your computer and use it in GitHub Desktop.
Read temp value from DS1820 temp sensor connected to raspberry pi
#!/usr/bin/python3
from pathlib import Path
import sys
devicepath = "/sys/bus/w1/devices/"
devicerawtempfile = "w1_slave"
with Path(devicepath, sys.argv[1], devicerawtempfile).open() as rawtemp:
_, templine = rawtemp.readlines()
_, tempinc = templine.rstrip().split("=")
print(int(tempinc) / 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment