from machine import Pin
import utime
# Pin setup
RS = Pin(12, Pin.OUT)
EN = Pin(11, Pin.OUT)
D4 = Pin(10, Pin.OUT)
D5 = Pin(9, Pin.OUT)
D6 = Pin(8, Pin.OUT)
D7 = Pin(7, Pin.OUT)
# Send enable pulse
def lcd_strobe():
EN.value(1)
utime.sleep_us(500)
EN.value(0)
utime.sleep_us(500)
# Send command/data
def lcd_send(data, mode):
RS.value(mode)
D7.value((data >> 7) & 1)
D6.value((data >> 6) & 1)
D5.value((data >> 5) & 1)
D4.value((data >> 4) & 1)
lcd_strobe()
D7.value((data >> 3) & 1)
D6.value((data >> 2) & 1)
D5.value((data >> 1) & 1)
D4.value((data >> 0) & 1)
lcd_strobe()
# LCD initialization
def lcd_init():
lcd_send(0x33, 0) # 8-bit mode init
lcd_send(0x32, 0) # 4-bit mode
lcd_send(0x28, 0) # 2 lines, 5x7 matrix
lcd_send(0x0C, 0) # Display on, cursor off
lcd_send(0x06, 0) # Increment cursor
lcd_send(0x01, 0) # Clear display
# Print string on LCD
def lcd_print(text):
for char in text:
lcd_send(ord(char), 1)
# Setup and display
lcd_init()
lcd_print("Hello Bishnu!")
lcd_send(0xC2, 0) # Move to row 2, col 2
lcd_print("> Pi Pico <")
utime.sleep(5)
#Print string on LCD
def lcd_print(text):
for char in text:
lcd_send(ord(char), 2)
lcd_init()
lcd_print("Hru!")
lcd_send(0xC2, 0) # Move to row 2, col 2
lcd_print("> Pi Pico <")