from machine import Pin,SoftI2C
from ssd1306 import SSD1306_I2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import dht
from time import sleep
i2c = SoftI2C(scl = Pin(22), sda = Pin(21), freq = 100000)
i2c_addr = 0x27
totalRows = 2
totalColumns = 16
lcd = I2cLcd(i2c, i2c_addr, totalRows, totalColumns)
I2C_ADDR = 0x3c
width = 128
height = 64
oled = SSD1306_I2C(width,height,i2c,I2C_ADDR)
sensor = dht.DHT22(Pin(14))
while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
oled.text("Temp: "+str(temp)+"C",0,0)
oled.text("Humidity: "+str(hum)+"%",0,10)
lcd.move_to(0,0)
lcd.putstr("Temp: "+str(temp)+"C")
lcd.move_to(0,1)
lcd.putstr("Humidity: "+str(hum)+"%")
oled.show()
oled.fill(0)
sleep(0.5)
except OSError as e:
print("Failed to read Sensor")