Raspberry Pi Pico/CircuitPython display on SSD1327 grayscale OLED

Exercises run on Raspberry Pi Pico (RP2040) flashed CircuitPython 8.0.5, to display on 1.5" 128x128 grayscale OLED with I2C SSD1327 driver.


Prepare Libraries:

Visit https://circuitpython.org/libraries
download and extract CircuitPython Library Bundle for Version 8.x

Upload adafruit_ssd1327.mpy and adafruit_display_shapes folder to CircuitPython device /lib folder.

Connection
between Raspberry Pi Pico and SSD1327 I2C OLED

	SSD1327 OLED	Raspberry Pi Pico
	=================================
	SDA		GP14
	SCL		GP15
	VCC		3V3
	GND		GND

Exercise Code:

rpi_ssd1327_a.py
import os, sys
import board
import time
import busio
import displayio
import adafruit_ssd1327
from adafruit_display_shapes.rect import Rect

displayio.release_displays()

DISP_WIDTH = 128
DISP_HEIGHT = 128
SDA = board.GP14
SCL = board.GP15
i2c = busio.I2C(SCL, SDA)

display_bus = displayio.I2CDisplay(i2c, device_address=60)
display = adafruit_ssd1327.SSD1327(display_bus, width=DISP_WIDTH, height=DISP_HEIGHT)
"""
“displayio” drivers will also work with CircuitPython to display error messages
and other output to the display when the user code is not using it.
"""

print(sys.implementation[0], os.uname()[2],
      "\nrun on", os.uname()[4])
print()
print("1.5\" 128x128 SSD1327")
print(adafruit_ssd1327.__name__)
print(adafruit_ssd1327.__version__)
print()
time.sleep(0.5)

group = displayio.Group()

no_of_color = 256
bg_bitmap = displayio.Bitmap(display.width, display.height, no_of_color)
bg_palette = displayio.Palette(no_of_color)
bg = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette)

for i in range(256):
    bg_palette[i] = i*0x10000 + i*0x100 +i
    
for x in range(128):
    for y in range(128):
        bg_bitmap[x, y] = x+y

group.append(bg)

sq = Rect(0, 0, 10, 10, fill=0xB0B0B0)
group.append(sq)

"""
show() is deprecated and will be removed in CircuitPython 9.0.0. Use .root_group = group instead.
https://docs.circuitpython.org/en/latest/shared-bindings/displayio/index.html#displayio.Display.show
"""
#display.show(group)
display.root_group = group

x_dir=1
y_dir=1
x_step=3
y_step=2

while True:
    time.sleep(0.05)
    sq.x = sq.x + x_dir*x_step
    sq.y = sq.y + y_dir*y_step
    
    if x_dir>0:
        if sq.x>=DISP_WIDTH-1-sq.width:
            x_dir = -1
    else:
        if sq.x<=0:
            x_dir = 1
            
    if y_dir>0:
        if sq.y>=DISP_HEIGHT-1-sq.height:
            y_dir = -1
    else:
        if sq.y<=0:
            y_dir = 1

    



rpi_ssd1327_b.py
import os, sys
import board
import time
import busio
import displayio
import adafruit_ssd1327
from adafruit_display_shapes.rect import Rect

displayio.release_displays()

DISP_WIDTH = 128
DISP_HEIGHT = 128
SDA = board.GP14
SCL = board.GP15
i2c = busio.I2C(SCL, SDA)

display_bus = displayio.I2CDisplay(i2c, device_address=60)
display = adafruit_ssd1327.SSD1327(display_bus, width=DISP_WIDTH, height=DISP_HEIGHT)
"""
“displayio” drivers will also work with CircuitPython to display error messages
and other output to the display when the user code is not using it.
"""

print(sys.implementation[0], os.uname()[2],
      "\nrun on", os.uname()[4])
print()
print("1.5\" 128x128 SSD1327")
print(adafruit_ssd1327.__name__)
print(adafruit_ssd1327.__version__)
print()
time.sleep(0.5)

group = displayio.Group()

no_of_color = 256
bg_bitmap = displayio.Bitmap(display.width, display.height, no_of_color)
bg_palette = displayio.Palette(no_of_color)
bg = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette)

for i in range(256):
    bg_palette[i] = i*0x10000 + i*0x100 +i
    
for x in range(128):
    for y in range(128):
        bg_bitmap[x, y] = x+y

group.append(bg)

for sx in range(8):
    for sy in range (8):
        sq = Rect(sx*16+4, sy*16+4, 8, 8, fill=0xB0B0B0)
        group.append(sq)


"""
show() is deprecated and will be removed in CircuitPython 9.0.0. Use .root_group = group instead.
https://docs.circuitpython.org/en/latest/shared-bindings/displayio/index.html#displayio.Display.show
"""
#display.show(group)
display.root_group = group

x_dir=1
y_dir=1
x_step=3
y_step=2

while True:
    pass
    



rpi_ssd1327_c.py
import os, sys
import board
import time
import busio
import displayio
import adafruit_ssd1327
from adafruit_display_shapes.rect import Rect

displayio.release_displays()

DISP_WIDTH = 128
DISP_HEIGHT = 128
SDA = board.GP14
SCL = board.GP15
i2c = busio.I2C(SCL, SDA)

display_bus = displayio.I2CDisplay(i2c, device_address=60)
display = adafruit_ssd1327.SSD1327(display_bus, width=DISP_WIDTH, height=DISP_HEIGHT)
"""
“displayio” drivers will also work with CircuitPython to display error messages
and other output to the display when the user code is not using it.
"""

print(sys.implementation[0], os.uname()[2],
      "\nrun on", os.uname()[4])
print()
print("1.5\" 128x128 SSD1327")
print(adafruit_ssd1327.__name__)
print(adafruit_ssd1327.__version__)
print()
time.sleep(0.5)

group = displayio.Group()

no_of_color = 16
bg_bitmap = displayio.Bitmap(display.width, display.height, no_of_color)
bg_palette = displayio.Palette(no_of_color)
bg = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette)

for i in range(no_of_color):
    bg_palette[i] = 0x000000

for x in range(128):
    for y in range(128):
        bg_bitmap[x, y] = int(x/8)

group.append(bg)

rect = Rect(3, 60, 122, 5, fill=0xB0B0B0)
group.append(rect)

"""
show() is deprecated and will be removed in CircuitPython 9.0.0. Use .root_group = group instead.
https://docs.circuitpython.org/en/latest/shared-bindings/displayio/index.html#displayio.Display.show
"""
#display.show(group)
display.root_group = group

while True:
    time.sleep(5)
    for i in range(16):
        bg_palette[15-i] = i*16*0x10000 + i*16*0x100 + i*16
    
    time.sleep(5)
    for i in range(16):
        bg_palette[i] = i*16*0x10000 + i*16*0x100 + i*16
"""
    time.sleep(5)
    for i in range(16):
        bg_palette[i] = 0x000000
""" 


Related:
Drive SSD1327 I2C grayscale OLED with Nano RP2040 Connect (in Arduino framework), using "Adafruit SSD1327" library.

Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator