from machine import Pin, SoftI2C
from i2c_lcd import I2cLcd
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=40000) #initializing the I2C method for ESP32
lcd = I2cLcd(i2c, 0x27, 2, 16)
lcd.backlight_on()
lcd.clear()
import dht
import time
sensor = dht.DHT22(Pin(4))
import BlynkLib
import network
### =============================================
WIFI_SSID = 'Music'
WIFI_PASS = '00000000'
BLYNK_AUTH = 'IxkikBsZSvu3Xjtv--M6_cr73croNRLM'
wifi = network.WLAN(network.STA_IF)
### =============================================
if not wifi.isconnected():
print("Connecting to WiFi...")
wifi.active(True)
wifi.connect(WIFI_SSID, WIFI_PASS)
while not wifi.isconnected():
pass
print('IP:', wifi.ifconfig()[0])
blynk = BlynkLib.Blynk(BLYNK_AUTH)
while 1:
time.sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
txtTemp = 'Temp: {:6.2f} c '.format(temp)
lcd.move_to(0,0)
lcd.putstr(txtTemp)
txthum = ' hum: {:6.2f} % '.format(hum)
lcd.move_to(0,1)
lcd.putstr(txthum)
txt = 'Temp: {:6.2f} c,Hum: {:5.2f} %'.format(temp,hum)
print(txt)
blynk.virtual_write(0,temp)
blynk.virtual_write(1,hum)
# lcd.move_to(0,0)
# lcd.putstr("temp: ")
# lcd.move_to(7,0)
# lcd.putstr(temp)
# lcd.move_to(14,0)
# lcd.putstr("c")
# lcd.move_to(0,1)
# lcd.putstr("hum:")
# lcd.move_to(7,1)
# lcd.putstr(hum)
# lcd.move_to(14,1)
# lcd.putstr("%")