import machine
from machine import Pin, SoftI2C, I2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
from dht import DHT22
from time import sleep

#i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000) #Connect scl to D22, sda to D21 the I2C method for ESP32
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=10000)      #Connect scl to D5, sda to D4 the I2C method for ESP8266

lcd = I2cLcd(i2c, 0x27, 2, 16) # I2cLcd(i2c, I2CAddress, totalRows, totalColumns)

dht = DHT22(machine.Pin(23))

while True:
    dht.measure()
    lcd.clear()
    lcd.move_to(0,0)
    lcd.putstr("Humidity: " + str(dht.humidity()) + "%") 
    lcd.move_to(0,1)
    lcd.putstr("Temp: " + str(dht.temperature()) + "°C")
    sleep(1)