Created
September 20, 2025 17:39
-
-
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
This file contains hidden or 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 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