# 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
import machine
import utime
# Initialize I2C bus
i2c = machine.I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
# LCD display configuration
LCD_ADDR = 0x27
LCD_ROWS = 2
LCD_COLS = 16
# Initialize LCD display
lcd = machine.I2C(1, sda=machine.Pin(0), scl=machine.Pin(1))
lcd.writeto_mem(LCD_ADDR, 0x00, bytearray([0x38])) # Function set
lcd.writeto_mem(LCD_ADDR, 0x00, bytearray([0x0C])) # Display on, cursor off, blink off
lcd.writeto_mem(LCD_ADDR, 0x00, bytearray([0x01])) # Clear display
# Print a message on the LCD
lcd.writeto_mem(LCD_ADDR, 0x00, bytearray([0x80, ord('H'), ord('e'), ord('l'), ord('l'), ord('o'), ord(','), ord(' '), ord('W'), ord('o'), ord('r'), ord('l'), ord('d'), ord('!')]))