Initial commit
This commit is contained in:
commit
d55996a6b8
Binary file not shown.
|
After Width: | Height: | Size: 142 KiB |
|
|
@ -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
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 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)
|
||||||
Loading…
Reference in New Issue