from machine import Pin, SoftI2C
import ssd1306
from machine import Pin
import dht
from time import sleep
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
sensor=dht.DHT22(Pin(5))
i2c=SoftI2C(scl=Pin(22),sda=Pin(21),freq=10000)
I2C_ADDR=0x3c
oled_width=128
oled_height=64
oled=ssd1306.SSD1306_I2C(oled_width,oled_height,i2c,I2C_ADDR)
I2C_ADDR2 = 0x27
totalRows = 4
totalColumns = 20
temp=0
hum=0
i2c2 = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000) #initializing the I2C method for ESP32
lcd2 = I2cLcd(i2c2, I2C_ADDR2, totalRows, totalColumns)
while True:
sleep(2)
sensor.measure()
temp1=sensor.temperature()
hum1=sensor.humidity()
if(temp!=temp1 or hum!=hum1):
lcd2.clear()
lcd2.putstr("Temp: "+str(temp1)+" C")
lcd2.move_to(0,1)
lcd2.putstr("Hum: "+str(hum1)+" %")
oled.fill(0)
oled.show()
oled.text("Temp: "+str(temp)+" C",0,10)
oled.text("Hum: "+str(hum)+" %",0,30)
oled.show()
temp=temp1
hum=hum1