dht_temp.py
The 3-pin DHT module sends temperature and humidity over a software bit-banged 1-Wire bus from GPIO4 (pin 7). read_retry re-attempts reads, which can be finicky on small-CPU boards like the model-b-rev1. Prints every 2 s, ideal for a greenhouse or wine cellar logger.
Hardware
A Raspberry Pi Model B revision 1 (BCM2835, 26-pin GPIO header, original through-hole ports, no standard 40-pin P1 connector). One DHT11 or DHT22 sensor, a 10k pull-up resistor, dupont wires.
Wiring
VCC to 3.3 V, GND to GND, DATA to GPIO4 (pin 7) with a 10k pull-up to 3.3 V. Confirm on the official P1 schematic.
How it works
The script sends a start pulse; the sensor answers with 40 bits. Software timing depends on CPU load, hence the retries.
Running it
Copy the script to the board (scp or USB stick), then run it with python3 (or bash). These boards often run an old Raspbian: gpiozero is still apt-installable. GPIO pins follow the 26-pin header in the official schematic.
Variants
DHT22 is more accurate (±0.5 °C) than DHT11; log to CSV for history. The revision 1 board (256 MB) is modest: keep peripherals light and check the supply voltage.
dht_temp.py
# dht_temp.py — lit temperature et humidite (DHT11/DHT22).
# Deps: pip3 install Adafruit_DHT (ou depot officiel)
import time
import Adafruit_DHT
SENSOR = Adafruit_DHT.DHT22 # DHT11 sur les petits modules bleus
PIN = 4 # GPIO4, broche 7
while True:
humidity, temperature = Adafruit_DHT.read_retry(SENSOR, PIN)
if humidity is not None and temperature is not None:
print(f"T={temperature:0.1f}C H={humidity:0.1f}%")
else:
print("Lecture rate: verifier cablage, pull-up 10k et alimentation")
time.sleep(2)