Skip to content

Commit b388384

Browse files
authored
Merge pull request #4 from makermelissa/master
Fixed driver issues with 128x64, made more readable
2 parents c925985 + d733147 commit b388384

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

adafruit_ssd1305.py

+29-24
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
Framebuf (non-displayio) driver for SSD1305 displays
2727
28-
* Author(s): Bryan Siepert, Tony DiCola, Michael McWethy
28+
* Author(s): Melissa LeBlanc-Williamns, Bryan Siepert, Tony DiCola, Michael McWethy
2929
3030
Display init commands taken from
3131
https://www.buydisplay.com/download/democode/ER-OLED022-1_I2C_DemoCode.txt
@@ -70,12 +70,16 @@
7070
SET_COL_ADDR = const(0x21)
7171
SET_PAGE_ADDR = const(0x22)
7272
SET_DISP_START_LINE = const(0x40)
73+
SET_LUT = const(0x91)
7374
SET_SEG_REMAP = const(0xa0)
7475
SET_MUX_RATIO = const(0xa8)
76+
SET_MASTER_CONFIG = const(0xad)
7577
SET_COM_OUT_DIR = const(0xc0)
78+
SET_COMSCAN_DEC = const(0xc8)
7679
SET_DISP_OFFSET = const(0xd3)
7780
SET_COM_PIN_CFG = const(0xda)
7881
SET_DISP_CLK_DIV = const(0xd5)
82+
SET_AREA_COLOR = const(0xd8)
7983
SET_PRECHARGE = const(0xd9)
8084
SET_VCOM_DESEL = const(0xdb)
8185
SET_CHARGE_PUMP = const(0x8d)
@@ -95,7 +99,9 @@ def __init__(self, buffer, width, height, *, external_vcc, reset):
9599
if self.reset_pin:
96100
self.reset_pin.switch_to_output(value=0)
97101
self.pages = self.height // 8
98-
self._column_offset = 4 # hardcoded for now...
102+
self._column_offset = 0
103+
if self.height == 32:
104+
self._column_offset = 4 # hardcoded for now...
99105
# Note the subclass must initialize self.framebuf to a framebuffer.
100106
# This is necessary because the underlying data buffer is different
101107
# between I2C and SPI implementations (I2C needs an extra byte).
@@ -105,27 +111,26 @@ def __init__(self, buffer, width, height, *, external_vcc, reset):
105111
def init_display(self):
106112
"""Base class to initialize display"""
107113
for cmd in (
108-
0xae | 0x00, # off
114+
SET_DISP | 0x00, # off
109115
# timing and driving scheme
110-
0xd5, 0x80, #SET_DISP_CLK_DIV
111-
0xa0 | 0x01, # column addr 127 mapped to SEG0 SET_SEG_REMAP
112-
0xa8, self.height - 1, #SET_MUX_RATIO
113-
0xd3, 0x00, #SET_DISP_OFFSET
114-
0xad, 0x8e, #Set Master Configuration
115-
0xd8, 0x05, #Set Area Color Mode On/Off & Low Power Display Mode
116-
0x20, 0x00, # horizontal SET_MEM_ADDR ADD
117-
0x40 | 0x00, #SET_DISP_START_LINE ADD
118-
0xa1, #set segment re-map 128 to 0
119-
0xC8, #Set COM Output Scan Direction 64 to 1
120-
0xda, 0x12, #SET_COM_PIN_CFG
121-
0x91, 0x3f, 0x3f, 0x3f, 0x3f,#Current drive pulse width of BANK0, Color A, Band C.
122-
0x81, 0xff, # maximum SET_CONTRAST to maximum
123-
0xd9, 0xd2, #SET_PRECHARGE orig: 0xd9, 0x22 if self.external_vcc else 0xf1,
124-
0xdb, 0x34, #SET_VCOM_DESEL 0xdb, 0x30, $ 0.83* Vcc
125-
0xa6, # not inverted SET_NORM_INV
126-
0xa4, # output follows RAM contents SET_ENTIRE_ON
127-
0x8d, 0x10 if self.external_vcc else 0x14, #SET_CHARGE_PUMP
128-
0xaf): #//--turn on oled panel
116+
SET_DISP_CLK_DIV, 0x80, #SET_DISP_CLK_DIV
117+
SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 SET_SEG_REMAP
118+
SET_MUX_RATIO, self.height - 1, #SET_MUX_RATIO
119+
SET_DISP_OFFSET, 0x00, #SET_DISP_OFFSET
120+
SET_MASTER_CONFIG, 0x8e, #Set Master Configuration
121+
SET_AREA_COLOR, 0x05, #Set Area Color Mode On/Off & Low Power Display Mode
122+
SET_MEM_ADDR, 0x00, # horizontal SET_MEM_ADDR ADD
123+
SET_DISP_START_LINE | 0x00, 0x2E, #SET_DISP_START_LINE ADD
124+
SET_COMSCAN_DEC, #Set COM Output Scan Direction 64 to 1
125+
SET_COM_PIN_CFG, 0x12, #SET_COM_PIN_CFG
126+
SET_LUT, 0x3f, 0x3f, 0x3f, 0x3f,#Current drive pulse width of BANK0, Color A, B, C
127+
SET_CONTRAST, 0xff, # maximum SET_CONTRAST to maximum
128+
SET_PRECHARGE, 0xd2, #SET_PRECHARGE orig: 0xd9, 0x22 if self.external_vcc else 0xf1,
129+
SET_VCOM_DESEL, 0x34, #SET_VCOM_DESEL 0xdb, 0x30, $ 0.83* Vcc
130+
SET_NORM_INV, # not inverted SET_NORM_INV
131+
SET_ENTIRE_ON, # output follows RAM contents SET_ENTIRE_ON
132+
SET_CHARGE_PUMP, 0x10 if self.external_vcc else 0x14, #SET_CHARGE_PUMP
133+
SET_DISP | 0x01): #//--turn on oled panel
129134
self.write_cmd(cmd)
130135
self.fill(0)
131136
self.show()
@@ -171,8 +176,8 @@ def show(self):
171176
xpos0 += 32
172177
xpos1 += 32
173178
self.write_cmd(SET_COL_ADDR)
174-
self.write_cmd(xpos0+self._column_offset)
175-
self.write_cmd(xpos1+self._column_offset)
179+
self.write_cmd(xpos0 + self._column_offset)
180+
self.write_cmd(xpos1 + self._column_offset)
176181
self.write_cmd(SET_PAGE_ADDR)
177182
self.write_cmd(0)
178183
self.write_cmd(self.pages - 1)

0 commit comments

Comments
 (0)