# Project objectives:
# * Print a "Hello world!" text on the LCD screen to test its functionality
# * Learn how to use I2C communication between the LCD and Raspberry Pi Pico
# * Get familiarized with the pico_i2c_lcd and lcd_api modules
# Hardware and connections used:
# * LCD GND Pin to Raspberry Pi Pico GND
# * LCD VCC Pin to Raspberry Pi Pico VBUS
# (Note: VBUS is only to be used as power for the screen.
# It can't be used as power for the entire circuit if there are other components interfaced.)
# * LCD SDA Pin to Raspberry Pi Pico GPIO Pin 0
# * LCD SCL Pin to Raspberry Pi Pico GPIO Pin 1
# Programmer: Adrian Josele G. Quional
from machine import I2C, Pin # Import I2C and Pin classes
from time import sleep # Import sleep for delays
from pico_i2c_lcd import I2cLcd # Import the LCD driver module
# Create an I2C object using SDA on GPIO 4 and SCL on GPIO 5
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
# Scan for the I2C address of the LCD
I2C_ADDR = i2c.scan()[0]
# Create the LCD object (2 rows, 16 columns)
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
# Main loop: display "Hello world!" centered on second row
while True:
lcd.clear() # Clear the screen
lcd.move_to(2, 1) # Move to column 2, row 1 (second row)
lcd.putstr("Hello world!") # Print centered text
sleep(5) # Show message for 5 seconds
lcd.clear() # Clear screen
sleep(1) # Wait 1 second before repeating