-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHT11.py
31 lines (30 loc) · 978 Bytes
/
DHT11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from machine import Pin
import utime as time
from time import sleep
from dht import DHT11
# Initialisieren des DHT11-Sensors
dataPin = 16
myPin = Pin(dataPin, Pin.OUT, Pin.PULL_DOWN)
sensor = DHT11(myPin)
time.sleep(1)
def read_temperature():
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
# Daten auf der immer gleichen Zeile darstellen
# im Print-Befehl "\r", voranstellen, am Ende schreibst Du end=''
print("Temperatur: {}°C, Luftfeuchtigkeit: {}%".format(temp, hum))
time.sleep(1)
#return temp, hum
except OSError as e:
print("Fehler beim Lesen vom DHT11-Sensor: ", e)
return None, None
# Hauptschleife
while True:
#temp, hum = read_temperature()
read_temperature()
#if temp is not None and hum is not None:
# Veröffentlichen Sie die Werte oder führen Sie andere Aktionen durch
# pass
sleep(5)