from machine import Pin
import dht
import time
from machine import Timer
tim2 = Timer(2)
#Timer Function Callback
def timerFunc2(t):
print(dhts.temperature())
print(dhts.humidity())
#----------------------------------------------------------
try:
dhts=dht.DHT22(Pin((4)));dhts.measure();time.sleep(2)
dhts.measure()
tim2.init(period=1000, mode=Timer.PERIODIC, callback=timerFunc2)
#----------------------------------------------------------
#End of Try statement
#----------------------------------------------------------
except:
print('Error occured')
#----------------------------------------------------------
#End of except statement