Simple test

Ensure your device works with this simple test.

examples/dht_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import time
from board import D2
import adafruit_dht

#initial the dht device
dhtDevice = adafruit_dht.DHT22(D2)

while True:
    try:
        # show the values to the serial port
        temperature = dhtDevice.temperature * (9 / 5) + 32
        humidity = dhtDevice.humidity
        print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity))

    except RuntimeError as error:
        print(error.args)

    time.sleep(2.0)