from machine import Pin, I2C
import utime
import lcd_api # Library for LCD API (download and place in same directory)
import pico_i2c_lcd # Library for I2C LCD control on Pico (download and place in same directory)
# LED pins for visual test
redled = Pin(15, Pin.OUT) # Red LED on GPIO 15 (output)
yellowled = Pin(13, Pin.OUT) # Yellow LED on GPIO 13 (output)
greenled = Pin(12, Pin.OUT) # Green LED on GPIO 12 (output)
# I2C setup for LCD
I2C_ADDR = 0x27 # I2C address of the LCD (change if different)
I2C_NUM_ROWS = 2 # Number of rows on the LCD
I2C_NUM_COLS = 16 # Number of columns on the LCD
# Initialize I2C communication (I2C0, SDA on GP4, SCL on GP5, 400kHz frequency)
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
# Create LCD object using the I2C connection and LCD parameters
lcd = pico_i2c_lcd.I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
# Initial LCD test
lcd.putstr("Hi") # Display "Hi" on the LCD
utime.sleep(2) # Wait for 2 seconds
lcd.clear() # Clear the LCD
lcd.putstr("Testing LCD!") # Display "Testing LCD" on the LCD
# Main loop: Blink LEDs for visual confirmation
while True:
redled.value(1) # Turn on red LED
yellowled.value(1) # Turn on yellow LED
greenled.value(1) # Turn on green LED
utime.sleep(0.5) # LEDs on for 0.5 seconds
redled.value(0) # Turn off red LED
yellowled.value(0) # Turn off yellow LED
greenled.value(0) # Turn off green LED
utime.sleep(0.5) # LEDs off for 0.5 seconds