Skip to content

Commit 11a9b9e

Browse files
authored
Merge pull request #31 from dglaude/0.49''-64-x-32
Add support for 0.49'' 64 x 32
2 parents 95d9bb7 + 0eccec4 commit 11a9b9e

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

adafruit_displayio_ssd1306.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* `Monochrome 0.96" 128x64 OLED graphic display <https://www.adafruit.com/product/326>`_
2222
* `Monochrome 128x32 SPI OLED graphic display <https://www.adafruit.com/product/661>`_
2323
* `Adafruit FeatherWing OLED - 128x32 OLED <https://www.adafruit.com/product/2900>`_
24+
* Monochrome 0.49" 64x32 I2C OLED graphic display
25+
* Might work on other sub-128 width display: Dots 72x40, 64x48, 96x16
2426
2527
**Software and Dependencies:**
2628
@@ -73,15 +75,24 @@ def __init__(
7375
# Patch the init sequence for 32 pixel high displays.
7476
init_sequence = bytearray(_INIT_SEQUENCE)
7577
height = kwargs["height"]
78+
width = kwargs["width"]
7679
if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
7780
height = kwargs["width"]
81+
width = kwargs["height"]
7882
init_sequence[16] = height - 1 # patch mux ratio
79-
if kwargs["height"] == 32:
83+
if height == 32 and width == 64: # Make sure this only apply to that resolution
84+
init_sequence[16] = 64 - 1 # FORCED for 64x32 because it fail with formula
85+
if height in (32, 16) and width != 64:
8086
init_sequence[25] = 0x02 # patch com configuration
87+
col_offset = (
88+
0 if width == 128 else (128 - width) // 2
89+
) # https://github.com/micropython/micropython/pull/7411
8190
super().__init__(
8291
bus,
8392
init_sequence,
8493
**kwargs,
94+
colstart=col_offset,
95+
rowstart=col_offset,
8596
color_depth=1,
8697
grayscale=True,
8798
pixels_in_byte_share_row=False,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: 2022 David Glaude (based on 2021 ladyada for Adafruit Industries)
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This test will initialize the display using displayio and draw a solid white
6+
background, a smaller black rectangle, and some white text.
7+
Customized version of displayio_ssd1306_simpletest.py for 64x32
8+
"""
9+
10+
import board
11+
import displayio
12+
import terminalio
13+
from adafruit_display_text import label
14+
import adafruit_displayio_ssd1306
15+
16+
displayio.release_displays()
17+
18+
i2c = board.I2C() # uses board.SCL and board.SDA
19+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
20+
21+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
22+
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=64, height=32)
23+
24+
# Make the display context
25+
splash = displayio.Group()
26+
display.show(splash)
27+
28+
color_bitmap = displayio.Bitmap(64, 32, 1)
29+
color_palette = displayio.Palette(1)
30+
color_palette[0] = 0xFFFFFF # White
31+
32+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
33+
splash.append(bg_sprite)
34+
35+
## Draw a smaller inner rectangle
36+
inner_bitmap = displayio.Bitmap(62, 30, 1)
37+
inner_palette = displayio.Palette(1)
38+
inner_palette[0] = 0x000000 # Black
39+
40+
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=1, y=1)
41+
splash.append(inner_sprite)
42+
43+
TEXT1 = "Hello"
44+
text_area = label.Label(terminalio.FONT, text=TEXT1, color=0xFFFFFF, x=2, y=6)
45+
splash.append(text_area)
46+
47+
TEXT2 = "World"
48+
text_area = label.Label(terminalio.FONT, text=TEXT2, color=0xFFFFFF, x=32, y=15)
49+
splash.append(text_area)
50+
51+
TEXT3 = "9876543210"
52+
text_area = label.Label(terminalio.FONT, text=TEXT3, color=0xFFFFFF, x=2, y=24)
53+
splash.append(text_area)
54+
55+
while True:
56+
pass

0 commit comments

Comments
 (0)