# NAME: UMAR YAHAYA
# ID: 20222993
# ASSIGNMENT N0. 4
from machine import Pin, I2C
import dht
from time import sleep
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
# Configure GPIO pins
sda = Pin(0)
scl = Pin(1)
# Set up the DHT22 sensor
dht22 = dht.DHT22(machine.Pin(14))
# Set up the LCD Display
i2c = I2C(0, sda = sda, scl = scl, freq = 400000)
#Print(i2c.scan()) # Print lcd i2c Address
I2C_ADDR = 39
I2C_ROWS = 2
I2C_COLS = 16
lcd = I2cLcd(i2c, I2C_ADDR, I2C_ROWS, I2C_COLS)
while True:
# Read the Temperature and Humidity from the DHT22 sensor
dht22.measure()
temp = dht22.temperature()
hum = dht22.humidity()
lcd.clear()
# line 1 of the LDC
lcd.move_to(0,0)
lcd.putstr("Temp: {:.1f} C".format(temp))
sleep(0.01)
# Line 2 of the LCD
lcd.move_to(0,1)
lcd.putstr("Humidity: {:.1f}%".format(hum))
# Wait for 2 Seconds Before Reading the Sensor Again
sleep(2)