##############################################################
# OLED (SSD1306) Interface #
##############################################################
#
# Interfacing 128x64 Monochrome OLED (SSD1306) with Raspberry Pi Pico
#
# Check out the link for Code explanation and Hardware details
# Link:
# http://tech.arunkumarn.in/blogs/raspberry-pi-pico/interfacing-128x64-monochrome-oled-ssd1306-with-raspberry-pi-pico/
#
#
from machine import Pin, I2C
import ssd1306
import time
# ----------------------------------------
# OLED Display Configuration
# ----------------------------------------
# I2C1 is used here:
# SDA -> GP2
# SCL -> GP3
i2c = I2C(1, scl=Pin(3), sda=Pin(2), freq=400000)
# OLED resolution (128x64)
oled_width = 128
oled_height = 64
# Initialize OLED display
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
# ----------------------------------------
# Function to display startup message
# ----------------------------------------
def startup_screen():
oled.fill(0) # Clear display
oled.text('Welcome to',25,20)
oled.show()
time.sleep_ms(250)
oled.text("Aavishkarah",20,34)
oled.show()
time.sleep(2)
# ----------------------------------------
# Function to display a counter
# ----------------------------------------
def counter_demo():
count = 0
while True:
oled.fill(0) # Clear display
oled.text("Counter", 0, 0)
oled.text("Count:", 0, 20)
oled.text(str(count), 60, 20)
oled.text("Aavishkarah", 25, 50)
oled.show()
count += 1
time.sleep(1)
# ----------------------------------------
# Function to draw shapes
# ----------------------------------------
def shapes_demo():
oled.fill(0)
# Draw rectangle border
oled.rect(0, 0, 128, 64, 1)
# Draw filled rectangle
oled.fill_rect(10, 10, 40, 20, 1)
# Draw horizontal line
oled.hline(0, 35, 128, 1)
# Draw vertical line
oled.vline(64, 0, 64, 1)
oled.text("Shapes!", 70, 10)
oled.text("Demo", 75, 25)
oled.show()
time.sleep(3)
# ----------------------------------------
# Main Program Execution
# ----------------------------------------
startup_screen()
shapes_demo()
counter_demo()