Skip to content

Commit d3e4fe2

Browse files
committed
Support for 72x40 0.42in OLEDs
1 parent b4198fd commit d3e4fe2

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

adafruit_ssd1306.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
SET_PAGE_ADDR = const(0x22)
3535
SET_DISP_START_LINE = const(0x40)
3636
SET_SEG_REMAP = const(0xA0)
37+
SET_IREF_SELECT = const(0xAD)
3738
SET_MUX_RATIO = const(0xA8)
3839
SET_COM_OUT_DIR = const(0xC0)
3940
SET_DISP_OFFSET = const(0xD3)
@@ -126,15 +127,14 @@ def init_display(self):
126127
0xFF, # maximum
127128
SET_ENTIRE_ON, # output follows RAM contents
128129
SET_NORM_INV, # not inverted
130+
SET_IREF_SELECT,
131+
0x30, # enable internal IREF during display on
129132
# charge pump
130133
SET_CHARGE_PUMP,
131134
0x10 if self.external_vcc else 0x14,
132135
SET_DISP | 0x01,
133136
): # on
134137
self.write_cmd(cmd)
135-
if self.width == 72:
136-
self.write_cmd(0xAD)
137-
self.write_cmd(0x30)
138138
self.fill(0)
139139
self.show()
140140

@@ -177,14 +177,11 @@ def show(self):
177177
if not self.page_addressing:
178178
xpos0 = 0
179179
xpos1 = self.width - 1
180-
if self.width == 64:
181-
# displays with width of 64 pixels are shifted by 32
182-
xpos0 += 32
183-
xpos1 += 32
184-
if self.width == 72:
185-
# displays with width of 72 pixels are shifted by 28
186-
xpos0 += 28
187-
xpos1 += 28
180+
if self.width != 128:
181+
# narrow displays use centered columns
182+
col_offset = (128 - self.width) // 2
183+
xpos0 += col_offset
184+
xpos1 += col_offset
188185
self.write_cmd(SET_COL_ADDR)
189186
self.write_cmd(xpos0)
190187
self.write_cmd(xpos1)

0 commit comments

Comments
 (0)