import dht
import machine
import ssd1306
import time
dht_sensor = dht.DHT22(machine.Pin(18))
i2c = machine.I2C(0, sda=machine.Pin(0), scl=machine.Pin(1))
oled = ssd1306.SSD1306_I2C(128, 32, i2c)
while True:
try:
dht_sensor.measure()
temperature = dht_sensor.temperature()#*1.03826
humidity = dht_sensor.humidity()
oled.fill(0)
oled.text(f"Temp: {temperature:.2f} C", 0, 0)
oled.text(f"Humidity: {humidity:.2f}%", 0, 20)
oled.show()
time.sleep(2)
if 21 < temperature < 25:
print("Normal")
elif temperature >= 25:
print("Hot")
else:
print("Cold")
except Exception as e:
print("Error:", e)