# 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. Quionol
# Modules
from machine import I2C, Pin # Since I2C communication would be used, I2C class is imported
from time import sleep
# Very important
# This module needs to be saved in the Raspberry Pi Pico in order for the LCD I2C to be used
from pico_i2c_lcd import I2cLcd
# 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(4), scl=Pin(5), freq=400000)
# Getting the 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
# In the example below: 2 number of rows, 16 number of columns
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
# Continuously print and clear "hello world!" text in the LCD screen while the board has power
while True:
# print text that allows printing of the string onto the LCD screen
# Like other methods that can be used, check lcd_api module
lcd.move_to(0, 0) # Move to first row
lcd.putstr("Hello world!") # Print on first row
lcd.move_to(0, 1) # Move to second row
lcd.putstr(" Campus 02") # Print on second row
sleep(5) # "Hello world!" text would be displayed for 5 secs
lcd.clear() # Clear the text for 1 sec then print the text again
sleep(1)