commit d55996a6b83056936ce583e5b4db8899951fa86e Author: Daniel Meiburg Date: Tue Jan 14 15:25:48 2025 +0100 Initial commit diff --git a/GPIO-Pinout-Diagram-2.png b/GPIO-Pinout-Diagram-2.png new file mode 100644 index 0000000..8726329 Binary files /dev/null and b/GPIO-Pinout-Diagram-2.png differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5215dc --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/dht22.py b/dht22.py new file mode 100644 index 0000000..f921d20 --- /dev/null +++ b/dht22.py @@ -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)