Published: 27.08.2018
Copyright by Joy-IT
7
Combi Sensor
#!/usr/bin/python
# coding=utf
-
8
# Required modules are imported and set up
import
RPi.
GPIO
as
GPIO
import
Adafruit_DHT
import
time
# The pause of two seconds between measurements is set here
sleeptime
=
2
# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
DHTSensor
=
Adafruit_DHT.
DHT11
# The pin to which the sensor module is connected can be declared here
GPIO_Pin
=
23
(
'KY
-
015 Sensortest
-
Temperatur und Luftfeuchtigkeit'
)
try
:
while
(
1
)
:
# Measurement is started and the result is written to the corresponding vari-
ables
Luftfeuchte
,
Temperatur
=
Adafruit_DHT.
read_retry(
DHTSensor
,
GPIO_Pin
)
(
"
-----------------------------------------------------------------
"
)
if
Luftfeuchte
is
not
None
and
Temperatur
is
not
None
:
# Das gemessene Ergebnis wird in der Konsole ausgegeben
(
'Temperatur = {0:0.1f}°C | rel. Luftfeuchtigkeit =
{1:0.1f}%'
.
format(
Temperatur
,
Luftfeuchte
))
# Because the Raspberry Pi is disadvantaged for real
-
time applications due to
the Linux operating system,
# communication may fail due to timing problems.
# In this case an error message is displayed
-
a result should be available
at the next attempt
else
:
(
'Fehler beim Auslesen
-
Bitte warten auf nächsten Versuch!'
)
(
"
-----------------------------------------------------------------
"
)
(
""
)
time
.
sleep(
sleeptime
)
# Cleanup after the program is finished
except
KeyboardInterrupt
:
GPIO.
cleanup()
Содержание Combi Sensor
Страница 1: ...3 Combi Sensor KY 015...