Enable I2C and SPI as described here, then
pi@raspberrypi:~ $ sudo apt install libgpiod2
pi@raspberrypi:~ $ python3 -m pip install adafruit-circuitpython-dht
As in this, connect the DHT11 to the pi's right pins (pin 4 for data stream)
and run
import time
import board
import adafruit_dht
dhtDevice = adafruit_dht.DHT11(board.D4)
while True:
try:
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
print("Temp: {:.1f} F / {:.1f} C Humidity: {}% "
.format(temperature_f, temperature_c, humidity))
except RuntimeError as error:
time.sleep(1.0)
time.sleep(2.0)
to get
Temp: 75.2 F / 24.0 C Humidity: 26%
Temp: 75.2 F / 24.0 C Humidity: 27%
Temp: 75.2 F / 24.0 C Humidity: 25%