# Nokia 5110 LCD Demo for Wokwi Simulation with Raspberry Pi Pico W
import machine
import time
import framebuf
# Import our LCD driver
from pcd8544 import PCD8544
# Define pin assignments - Wokwi compatible
spi = machine.SPI(0, baudrate=2000000, polarity=0, phase=0)
cs = machine.Pin(5, machine.Pin.OUT)
dc = machine.Pin(3, machine.Pin.OUT)
rst = machine.Pin(4, machine.Pin.OUT)
bl = machine.Pin(2, machine.Pin.OUT)
# Initialize the display
lcd = PCD8544(spi, cs, dc, rst, bl)
# Set a comfortable contrast for Wokwi simulation
lcd.contrast(60)
def display_welcome():
"""Display welcome message"""
lcd.clear()
lcd.text("Nokia 5110", 10, 0, 1)
lcd.text("on Wokwi", 15, 10, 1)
lcd.text("Simulation", 10, 20, 1)
lcd.hline(0, 30, 84, 1)
lcd.text("Pi Pico W", 15, 35, 1)
lcd.show()
time.sleep(3)
def draw_progress_bar():
"""Animate a progress bar"""
lcd.clear()
lcd.text("Loading...", 15, 10, 1)
lcd.rect(10, 25, 64, 10, 1)
# Animate the progress bar
for i in range(1, 63):
lcd.fill_rect(11, 26, i, 8, 1)
lcd.show()
time.sleep(0.05)
lcd.text("Complete!", 15, 40, 1)
lcd.show()
time.sleep(2)
def display_readings():
"""Simulate sensor readings"""
for i in range(10):
lcd.clear()
lcd.text("Temp:", 0, 0, 1)
lcd.text(f"{20 + i}C", 50, 0, 1)
lcd.text("Humidity:", 0, 10, 1)
lcd.text(f"{40 + i}%", 50, 10, 1)
lcd.text("Pressure:", 0, 20, 1)
lcd.text(f"{1000 + i}hPa", 50, 20, 1)
# Draw a simple graph
for j in range(10):
height = 5 + (j * 2) + (i % 3)
lcd.fill_rect(j * 8 + 2, 48 - height, 6, height, 1)
lcd.show()
time.sleep(1)
def draw_bitmap():
"""Draw a simple bitmap (smiley face)"""
lcd.clear()
lcd.text("Bitmap Demo", 0, 0, 1)
# Define an 8x8 smiley face bitmap
smiley = bytearray([
0x3C, 0x42, 0xA5, 0x81,
0xA5, 0x99, 0x42, 0x3C
])
fb = framebuf.FrameBuffer(smiley, 8, 8, framebuf.MONO_HLSB)
# Draw the bitmap multiple times
for x in range(10, 70, 20):
for y in range(15, 40, 15):
lcd.framebuf.blit(fb, x, y, 0)
lcd.show()
time.sleep(3)
def main():
try:
while True:
# Run each demo function
display_welcome()
draw_progress_bar()
display_readings()
draw_bitmap()
# Demonstrate inverting the display
lcd.invert(True)
time.sleep(1)
lcd.invert(False)
time.sleep(1)
except KeyboardInterrupt:
# Clear display on exit
lcd.clear()
lcd.show()
print("Demo ended")
# Start the main loop
main()
Loading
nokia-5110
nokia-5110