#shows the address of liquid crystal display as 0x27. You will most likely get the same address for LCD with 16 columns and 2 rows.
'''import machine
sdaPIN=machine.Pin(21) #for ESP32
sclPIN=machine.Pin(22)
i2c=machine.I2C(sda=sdaPIN, scl=sclPIN, freq=10000)
devices = i2c.scan()
if len(devices) == 0:
print("No i2c device !")
else:
print('i2c devices found:',len(devices))
for device in devices:
print("At address: ",hex(device))'''
import machine
from machine import Pin, SoftI2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
from time import sleep
import dht
sensor=dht.DHT22(Pin(14))
I2C_ADDR = 0x27
totalRows = 4
totalColumns = 20
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000) #initializing the I2C method for ESP32
#i2c = I2C(scl=Pin(5), sda=Pin(4), freq=10000) #initializing the I2C method for ESP8266
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns)
# WRITE A MICRO PYTHON SCRIPT TO DISPLAY FATHER CONTACT NUMBER IN ROW 0 AND MOTHER IN ROW 1
while True:
try:
sleep(2)
sensor.measure()
temp=sensor.temperature()
hum=sensor.humidity()
temp_f=temp*(9/5) + 32.0
print('Temperature in C:',temp,' C ')
print('Temperature in F:',temp_f,' C ')
print('Humidity in %:',hum,' % ')
lcd.move_to(0,0)
lcd.putstr('Temp in C: ')
lcd.putstr(str(temp))
lcd.move_to(0,1)
lcd.putstr('Hum IN %:')
lcd.putstr(str(hum))
except OSError as e:
print('Failed to read sensor')