from machine import I2C, Pin
from time import sleep
from pico_i2c_lcd import I2cLcd
import dht
# creating an I2C object, specifying the data (SDA) and clock (SCL) pins used in the Raspberry Pi Pico
# any SDA and SCL pins in the Raspberry Pi Pico can be used (check documentation for SDA and SCL pins)
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
# getting I2C address
I2C_ADDR = i2c.scan()[0]
# creating an LCD object using the I2C address and specifying number of rows and columns in the LCD
# LCD number of rows = 2, number of columns = 16
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
# DHT pin
sensor = dht.DHT22(Pin(2))
# continuously print and clear "Hello world!" text in the LCD screen while the board has power
while True:
sensor.measure()
temp = sensor.temperature()
humid = sensor.humidity()
lcd.clear()
#lcd.move_to(0, 0)
lcd.putstr("Temp = ")
lcd.putstr(str(temp))
lcd.move_to(0, 1)
lcd.putstr("Hum = ")
lcd.putstr(str(humid))
sleep(2)