Skip to content

Commit 22c64cd

Browse files
kattnitannewt
authored andcommitted
Update to SSD1331 driver (#11)
Resolves issue with display not functioning properly. Tested successfully with SSD1331 display. Thank you to @deshipu for figuring this out!
1 parent 8b5e71b commit 22c64cd

File tree

1 file changed

+49
-34
lines changed

1 file changed

+49
-34
lines changed

adafruit_rgb_display/ssd1331.py

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
"""A simple driver for the SSD1331-based displays."""
12
from adafruit_rgb_display.rgb import DisplaySPI
3+
from micropython import const
4+
5+
__version__ = "0.0.0-auto.0"
6+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
27

38

49
_DRAWLINE = const(0x21)
@@ -37,23 +42,21 @@ class SSD1331(DisplaySPI):
3742
"""
3843
A simple driver for the SSD1331-based displays.
3944
40-
>>> import busio
41-
>>> import digitalio
42-
>>> import board
43-
>>> from adafruit_rgb_display import color565
44-
>>> import adafruit_rgb_display.ssd1331 as ssd1331
45-
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
46-
>>> display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
47-
>>> display.fill(0x7521)
48-
>>> display.pixel(32, 32, 0)
49-
>>>
50-
from machine import Pin, HSPI
51-
import ssd1331
52-
#spi = SPI(mosi=Pin(13), sck=Pin(14), polarity=1, phase=1)
53-
spi = HSPI(polarity=1, phase=1)
54-
display = ssd1331.SSD1331(spi, dc=Pin(2), cs=Pin(15), rst=Pin(16))
55-
display.fill(0x7521)
56-
display.pixel(32, 32, 0)
45+
.. code-block:: python
46+
47+
import busio
48+
import digitalio
49+
import board
50+
from adafruit_rgb_display import color565
51+
import adafruit_rgb_display.ssd1331 as ssd1331
52+
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
53+
display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0),
54+
dc=digitalio.DigitalInOut(board.GPIO15),
55+
rst=digitalio.DigitalInOut(board.GPIO16))
56+
57+
display.fill(0x7521)
58+
display.pixel(32, 32, 0)
59+
5760
"""
5861
_COLUMN_SET = _SETCOLUMN
5962
_PAGE_SET = _SETROW
@@ -62,31 +65,43 @@ class SSD1331(DisplaySPI):
6265
_INIT = (
6366
(_DISPLAYOFF, b''),
6467
(_LOCK, b'\x0b'),
65-
(_SETREMAP, b'\x72'), # RGB Color
68+
(_SETREMAP, b'\x72'), # RGB Color
6669
(_STARTLINE, b'\x00'),
6770
(_DISPLAYOFFSET, b'\x00'),
6871
(_NORMALDISPLAY, b''),
69-
# (_FILL, b'\x01'),
72+
# (_FILL, b'\x01'),
7073

71-
# (_PHASEPERIOD, b'\x31'),
72-
# (_SETMULTIPLEX, b'\x3f'),
73-
# (_SETMASTER, b'\x8e'),
74-
# (_POWERMODE,b'\x0b'),
75-
# (_PRECHARGE, b'\x31'), #;//0x1F - 0x31
76-
# (_CLOCKDIV, b'\xf0'),
77-
# (_VCOMH, b'\x3e'), #;//0x3E - 0x3F
78-
# (_MASTERCURRENT, b'\x06'), # ;//0x06 - 0x0F
79-
# (_PRECHARGEA, b'\x64'),
80-
# (_PRECHARGEB, b'\x78'),
81-
# (_PRECHARGEC, b'\x64'),
82-
# (_PRECHARGELEVEL, b'\x3a'), # 0x3A - 0x00
83-
# (_CONTRASTA, b'\x91'), #//0xEF - 0x91
84-
# (_CONTRASTB, b'\x50'), #;//0x11 - 0x50
85-
# (_CONTRASTC, b'\x7d'), #;//0x48 - 0x7D
74+
(_PHASEPERIOD, b'\x31'),
75+
(_SETMULTIPLEX, b'\x3f'),
76+
(_SETMASTER, b'\x8e'),
77+
(_POWERMODE, b'\x0b'),
78+
(_PRECHARGE, b'\x31'), # ;//0x1F - 0x31
79+
(_CLOCKDIV, b'\xf0'),
80+
(_VCOMH, b'\x3e'), # ;//0x3E - 0x3F
81+
(_MASTERCURRENT, b'\x0c'), # ;//0x06 - 0x0F
82+
(_PRECHARGEA, b'\x64'),
83+
(_PRECHARGEB, b'\x78'),
84+
(_PRECHARGEC, b'\x64'),
85+
(_PRECHARGELEVEL, b'\x3a'), # 0x3A - 0x00
86+
(_CONTRASTA, b'\x91'), # //0xEF - 0x91
87+
(_CONTRASTB, b'\x50'), # ;//0x11 - 0x50
88+
(_CONTRASTC, b'\x7d'), # ;//0x48 - 0x7D
8689
(_DISPLAYON, b''),
8790
)
8891
_ENCODE_PIXEL = ">H"
8992
_ENCODE_POS = ">BB"
9093

94+
# pylint: disable-msg=useless-super-delegation, too-many-arguments
95+
# super required to allow override of default values
96+
# All arguments needed due to driver requiring all the given data to function
9197
def __init__(self, spi, dc, cs, rst=None, width=96, height=64):
9298
super().__init__(spi, dc, cs, rst, width, height)
99+
100+
def write(self, command=None, data=None):
101+
"""write procedure specific to SSD1331"""
102+
self.dc.value = command is None
103+
with self.spi_device as spi:
104+
if command is not None:
105+
spi.write(bytearray([command]))
106+
if data is not None:
107+
spi.write(data)

0 commit comments

Comments
 (0)