Raspberry Pi practice problem · I²C, SPI, UART & 1-Wire
A thermometer is a file
EasyBudget $8Python · gpiozero
On a Pi, a 1-Wire DS18B20 shows up as a folder /sys/bus/w1/devices/28-…. Its w1_slave file has two lines; the second ends with t= and the temperature in thousandths of a degree:
72 01 4b 46 7f ff 0e 10 57 : crc=57 YES
72 01 4b 46 7f ff 0e 10 57 t=23125
Build: a DS18B20 with its data pin on GPIO4 and a 4.7 kΩ pull-up (the DS18B20 probe module kit has the resistor fitted).
Program: read the file over and over and print the temperature with two decimals:
Temp: 21.25 C
The test holds 21.25 °C, then −3.5 °C from 3 s. Each read takes 0.75 s (the conversion time).
Tip: glob.glob("/sys/bus/w1/devices/28-*/w1_slave")[0] finds the file.