Skip to content

Commit 4dbd1b4

Browse files
committed
Add 128x128 OLED support and example.
1 parent e2e56ec commit 4dbd1b4

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

adafruit_displayio_sh1107.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@
5151
display = SH1107(bus, width=128, height=64)
5252
"""
5353

54+
DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297 = const(0x00)
55+
"""
56+
The hardware display offset to use when configuring the SH1107 for the
57+
`Adafruit Monochrome 1.12" 128x128 OLED <https://www.adafruit.com/product/5297>`_.
58+
59+
.. code-block::
60+
61+
from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297
62+
63+
# Constructor for the Adafruit Monochrome 1.12" 128x128 OLED
64+
display = SH1107(bus, width=128, height=128,
65+
display_offset=DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297, rotation=90)
66+
"""
67+
5468
DISPLAY_OFFSET_PIMORONI_MONO_OLED_PIM374 = const(0x00)
5569
"""
5670
The hardware display offset to use when configuring the SH1107 for the
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
"""
5+
Based on example by Mark Roberts (mdroberts1243).
6+
7+
This example writes text to the display, and draws a series of squares and a rectangle.
8+
"""
9+
10+
import board
11+
import displayio
12+
import terminalio
13+
from adafruit_display_text import bitmap_label as label
14+
from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297
15+
16+
displayio.release_displays()
17+
18+
# For I2C
19+
display_bus = displayio.I2CDisplay(board.I2C(), device_address=0x3D)
20+
21+
# For SPI:
22+
# import busio
23+
# spi_bus = busio.SPI(board.SCK, board.MOSI)
24+
# display_bus = displayio.FourWire(spi_bus, command=board.D6, chip_select=board.D5, reset=board.D9)
25+
26+
# Width, height and rotation for Monochrome 1.12" 128x128 OLED
27+
WIDTH = 128
28+
HEIGHT = 128
29+
ROTATION = 90
30+
31+
# Border width
32+
BORDER = 2
33+
34+
display = SH1107(
35+
display_bus,
36+
width=WIDTH,
37+
height=HEIGHT,
38+
display_offset=DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297,
39+
rotation=ROTATION,
40+
)
41+
42+
# Make the display context
43+
splash = displayio.Group()
44+
display.show(splash)
45+
46+
color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
47+
color_palette = displayio.Palette(1)
48+
color_palette[0] = 0xFFFFFF # White
49+
50+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
51+
splash.append(bg_sprite)
52+
53+
# Draw a smaller inner rectangle in black
54+
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
55+
inner_palette = displayio.Palette(1)
56+
inner_palette[0] = 0x000000 # Black
57+
inner_sprite = displayio.TileGrid(
58+
inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
59+
)
60+
splash.append(inner_sprite)
61+
62+
# Draw some white squares
63+
small_bitmap = displayio.Bitmap(8, 8, 1)
64+
small_square = displayio.TileGrid(small_bitmap, pixel_shader=color_palette, x=58, y=17)
65+
splash.append(small_square)
66+
67+
medium_bitmap = displayio.Bitmap(16, 16, 1)
68+
medium_square = displayio.TileGrid(
69+
medium_bitmap, pixel_shader=color_palette, x=71, y=15
70+
)
71+
splash.append(medium_square)
72+
73+
large_bitmap = displayio.Bitmap(32, 32, 1)
74+
large_square = displayio.TileGrid(large_bitmap, pixel_shader=color_palette, x=91, y=28)
75+
splash.append(large_square)
76+
77+
bottom_bitmap = displayio.Bitmap(110, 50, 1)
78+
bottom_rectangle = displayio.TileGrid(
79+
bottom_bitmap, pixel_shader=color_palette, x=10, y=69
80+
)
81+
splash.append(bottom_rectangle)
82+
83+
# Draw some label text
84+
name_text = "Monochrome 1.12in"
85+
name_text_area = label.Label(terminalio.FONT, text=name_text, color=0xFFFFFF, x=8, y=8)
86+
splash.append(name_text_area)
87+
size_text = "128x128"
88+
size_text_area = label.Label(terminalio.FONT, text=size_text, color=0xFFFFFF, x=8, y=25)
89+
splash.append(size_text_area)
90+
oled_text = "OLED"
91+
oled_text_area = label.Label(
92+
terminalio.FONT, text=oled_text, scale=2, color=0xFFFFFF, x=9, y=44
93+
)
94+
splash.append(oled_text_area)
95+
96+
while True:
97+
pass

0 commit comments

Comments
 (0)