Initial commit

This commit is contained in:
Daniel Meiburg 2025-01-14 15:25:48 +01:00
commit d55996a6b8
Signed by: dm
GPG Key ID: E5827ECFFE0AA4F2
3 changed files with 44 additions and 0 deletions

BIN
GPIO-Pinout-Diagram-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

23
README.md Normal file
View File

@ -0,0 +1,23 @@
# DHT22 Demo
Vollständige Anleitung: https://randomnerdtutorials.com/raspberry-pi-dht11-dht22-python/
## Requirements
```bash
pip install adafruit-circuitpython-dht
```
## Connection
- DHT22 + -> RPI 3.3V
- DHT22 - -> RPI GND
- DHT22 out -> RPI GPIO 2
![Pinout](GPIO-Pinout-Diagram-2.png)
## Run
```bash
python3 dht22.py
```

21
dht22.py Normal file
View File

@ -0,0 +1,21 @@
import time
import board
import adafruit_dht
# board.D2 is GPIO2, some other pins can work as well
sensor = adafruit_dht.DHT22(board.D2)
while True:
try:
print(f"{sensor.temperature=:.1f}ºC, {sensor.humidity=:.1f}%")
except RuntimeError as error:
# Errors happen fairly often, just keep going
print(error.args[0])
time.sleep(2)
continue
except Exception as error:
sensor.exit()
raise error
time.sleep(10)