24 lines
755 B
Python
24 lines
755 B
Python
import time
|
|
import board
|
|
import adafruit_dht
|
|
import psutil
|
|
# We first check if a libgpiod process is running. If yes, we kill it!
|
|
for proc in psutil.process_iter():
|
|
if proc.name() == 'libgpiod_pulsein' or proc.name() == 'libgpiod_pulsei':
|
|
proc.kill()
|
|
#D20 is the pin number, DHT11 is the sensor type
|
|
sensor = adafruit_dht.DHT11(board.D20)
|
|
while True:
|
|
try:
|
|
temp = sensor.temperature
|
|
humidity = sensor.humidity
|
|
print("Temperature: {}*C Humidity: {}% ".format(temp, humidity))
|
|
except RuntimeError as error:
|
|
print(error.args[0])
|
|
time.sleep(2.0)
|
|
continue
|
|
except Exception as error:
|
|
sensor.exit()
|
|
raise error
|
|
#time between temp and humidity checks
|
|
time.sleep(2.0) |