from machine import Pin, SoftI2C
from ssd1306 import SSD1306_I2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
from time import sleep
import dht
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000)
I2C_ADDR=0x3c
oled_width=128
oled_height=64
oled=SSD1306_I2C(oled_width, oled_height, i2c, I2C_ADDR)
I2C_ADDR2 = 0x27
totalRows = 4
totalColumns = 20
lcd = I2cLcd(i2c, I2C_ADDR2, totalRows, totalColumns)
sensor =dht.DHT22(Pin(14))
while True:
sleep(2)
sensor.measure()
temp=sensor.temperature()
humi=sensor.humidity()
#print("Temperature in C: ",temp,"C")
temp_f=temp*(9/5)+32
#print("Temperature in F: ",temp_f,"F")
#print("Humidity: ",humi,"%")
oled.text(str(temp),0,0,1)
oled.text(str(humi),0,10,1) #text method only accept string value
oled.show()
lcd.move_to(0,0)
lcd.putstr(str(temp))
lcd.move_to(0,1)
lcd.putstr(str(humi))
#write a micropython script to display 1.ESP32 with LCD on 16x2 lcd 2.ESP32 with OLed on oled display