From a2921de66493d46ebe6e3ce87fc06e76e1cc8dcc Mon Sep 17 00:00:00 2001 From: miteshgithub-1396 <72193176+miteshgithub-1396@users.noreply.github.com> Date: Sun, 3 Oct 2021 18:42:21 +0530 Subject: [PATCH] new.c New changes --- new.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 new.c diff --git a/new.c b/new.c new file mode 100644 index 0000000..d25b585 --- /dev/null +++ b/new.c @@ -0,0 +1,18 @@ +import time + +import adafruit_dht +import board + +dht = adafruit_dht.DHT22(board.D2) + +while True: + try: + temperature = dht.temperature + humidity = dht.humidity + # Print what we got to the REPL + print("Temp: {:.1f} *C \t Humidity: {}%".format(temperature, humidity)) + except RuntimeError as e: + # Reading doesn't always work! Just print error and we'll try again + print("Reading from DHT failure: ", e.args) + + time.sleep(1)