Skip to content

Raspberry pi pico sh1106 display issues #3

@diminDDL

Description

@diminDDL

I tried to get 2 sh1106 displays working on the raspberry pi pico for the last 2 days. One of them is a Waveshare 1.3 inch 128x64 SH1106 OLED (in SPI mode), the other one is a generic 128x64 SPI OLED experimentally identified to be an SH106 module since just like the first one it worked perfectly with an aruino nano with the following library. However, when trying to get it working in CircuitPython on 6.3 the display occasionally only turned on and showed noise, however when switching to latest release of 7.0.0-beta I got some text out of the display, also randomly but not like it's supposed to be. In both cases the latest release of this repo was used for the libraries. It also appears that perhaps some memory mishap is going on since on several occasions I witnessed the REPL output appearing on the OLED:
image

The code I used is as follows:

import board
import displayio
import terminalio
from adafruit_display_text import label
import adafruit_displayio_sh1106

displayio.release_displays()

oled_reset = board.GP6

# Use for I2C
# i2c = board.I2C()
# display_bus = displayio.I2CDisplay(i2c, device_address=0x3C, reset=oled_reset)

# Use for SPI
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)
oled_cs = board.GP7
oled_dc = board.GP5
display_bus = displayio.FourWire(spi, command=oled_dc, chip_select=oled_cs,
                                reset=oled_reset, baudrate=1000000)

WIDTH = 128
HEIGHT = 64  # Change to 64 if needed
BORDER = 5

display = adafruit_displayio_sh1106.SH1106(display_bus, width=WIDTH, height=HEIGHT)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF  # White

bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000  # Black
inner_sprite = displayio.TileGrid(
    inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
splash.append(inner_sprite)

# Draw a label
text = "Hello World!"
text_area = label.Label(
    terminalio.FONT, text=text, color=0xFFFFFF, x=28, y=HEIGHT // 2 - 1
)
splash.append(text_area)

while True:
    pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions