Skip to content

Instantly share code, notes, and snippets.

@leon-anavi
Created September 20, 2025 17:39
Show Gist options
  • Select an option

  • Save leon-anavi/2874aab81fd0ee83bcaa43280a1010e8 to your computer and use it in GitHub Desktop.

Select an option

Save leon-anavi/2874aab81fd0ee83bcaa43280a1010e8 to your computer and use it in GitHub Desktop.
Python 3 script to measure temperature from DS18B20 digital 1-wire sensor attached to Raspberry Pi
import glob
device_file = glob.glob('/sys/bus/w1/devices/28-*')[0] + '/w1_slave'
with open(device_file, 'r') as f:
temp_str = f.readlines()[1].split('t=')[-1]
temp_c = float(temp_str) / 1000.0
print(f"Temperature: {temp_c:.2f} °C")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment