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)
lcd = I2cLcd(i2c, 0x27, 2, 16)
oled = SSD1306_I2C(128,64,i2c,0x3c)
sensor = dht.DHT22(Pin(14))
while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
lcd.clear()
oled.text("Temp: "+str(temp)+"C",0,0)
oled.text("Humidity: "+str(hum)+"%",0,10)
lcd.putstr("Temp: "+str(temp)+"C")
lcd.move_to(0,1)
lcd.putstr("Humidity: "+str(hum)+"%")
oled.show()
oled.fill(0)
except OSError as e:
print("Failed to read Sensor")