adafruit / adafruit/Adafruit_CircuitPython_SSD1306
Initialize display cmd
- Dominant language
- Python
- Stars
- 325
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Why initialize display cmd is big difference from with the previous repo and u8g2 too. Where does it come from?
https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/blob/main/adafruit_ssd1306.py#L116
```python
# self.poweron
0xAE | 0x01
# self.init_display
0xAE, # off
# address setting
0x20,
0x10 # Page Addressing Mode
if self.page_addressing
else 0x00, # Horizontal Addressing Mode
# resolution and layout
0x40,
0xA0 | 0x01, # column addr 127 mapped to SEG0
0xA8,
self.height - 1,
0xC0 | 0x08, # scan from COM[N] to COM0
0xD3,
0x00,
0xDA,
0x02 if self.width > 2 * self.height else 0x12,
# timing and driving scheme
0xD5,
0x80,
0xD9,
0x22 if self.external_vcc else 0xF1,
0xDB,
0x30, # 0.83*Vcc # n.b. specs for ssd1306 64x32 oled screens imply this should be 0x40
# display
0x81,
0xFF, # maximum
0xA4, # output follows RAM contents
0xA6, # not inverted
0xAD,
0x30, # enable internal IREF during display on
# charge pump
0x8D,
0x10 if self.external_vcc else 0x14,
0xAE | 0x01, # display on
```
https://github.com/adafruit/micropython-adafruit-ssd1306/blob/master/ssd1306.py#L40
```python
# self.init_display
0xAE | 0x00, # off
# address setting
0x20, 0x00, # horizontal
# resolution and layout
0x40 | 0x00,
0xA0 | 0x01, # column addr 127 mapped to SEG0
0xA8, self.height - 1,
0xC0 | 0x08, # scan from COM[N] to COM0
0xD3, 0x00,
0xDA, 0x02 if self.height == 32 else 0x12,
# timing and driving scheme
0xD5, 0x80,
0xD9, 0x22 if self.external_vcc else 0xF1,
0xDB, 0x30, # 0.83*Vcc
# display
0x81, 0xFF, # maximum
0xA4, # output follows RAM contents
0xA6, # not inverted
# charge pump
0x8D, 0x10 if self.external_vcc else 0x14,
0xAE | 0x01 # on
```
https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306/blob/main/adafruit_displayio_ssd1306.py#L43
```
_INIT_SEQUENCE = (
b"\xAE\x00" # DISPLAY_OFF
b"\x20\x01\x00" # Set memory addressing to horizontal mode.
b"\x81\x01\xcf" # set contrast control
b"\xA1\x00" # Column 127 is segment 0
b"\xA6\x00" # Normal display
b"\xc8\x00" # Normal display
b"\xA8\x01\x3f" # Mux ratio is 1/64
b"\xd5\x01\x80" # Set divide ratio
b"\xd9\x01\xf1" # Set pre-charge period
b"\xda\x01\x12" # Set com configuration
b"\xdb\x01\x40" # Set vcom configuration
b"\x8d\x01\x14" # Enable charge pump
b"\xAF\x00" # DISPLAY_ON
)
```
https://github.com/adafruit/Adafruit_SSD1306/blob/master/Adafruit_SSD1306.cpp#L564
```c++
// Init sequence
static const uint8_t PROGMEM init1[] = {SSD1306_DISPLAYOFF, // 0xAE
SSD1306_SETDISPLAYCLOCKDIV, // 0xD5
0x80, // the suggested ratio 0x80
SSD1306_SETMULTIPLEX}; // 0xA8
ssd1306_commandList(init1, sizeof(init1));
ssd1306_command1(HEIGHT - 1);
static const uint8_t PROGMEM init2[] = {SSD1306_SETDISPLAYOFFSET, // 0xD3
0x0, // no offset
SSD1306_SETSTARTLINE | 0x0, // line #0
SSD1306_CHARGEPUMP}; // 0x8D
ssd1306_commandList(init2, sizeof(init2));
ssd1306_command1((vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0x14);
static const uint8_t PROGMEM init3[] = {SSD1306_MEMORYMODE, // 0x20
0x00, // 0x0 act like ks0108
SSD1306_SEGREMAP | 0x1,
SSD1306_COMSCANDEC};
ssd1306_commandList(init3, sizeof(init3));
uint8_t comPins = 0x02;
contrast = 0x8F;
if ((WIDTH == 128) && (HEIGHT == 32)) {
comPins = 0x02;
contrast = 0x8F;
} else if ((WIDTH == 128) && (HEIGHT == 64)) {
comPins = 0x12;
contrast = (vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF;
} else if ((WIDTH == 96) && (HEIGHT == 16)) {
comPins = 0x2; // ada x12
contrast = (vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0xAF;
} else {
// Other screen varieties -- TBD
}
ssd1306_command1(SSD1306_SETCOMPINS);
ssd1306_command1(comPins);
ssd1306_command1(SSD1306_SETCONTRAST);
ssd1306_command1(contrast);
ssd1306_command1(SSD1306_SETPRECHARGE); // 0xd9
ssd1306_command1((vccstate == SSD1306_EXTERNALVCC) ? 0x22 : 0xF1);
static const uint8_t PROGMEM init5[] = {
SSD1306_SETVCOMDETECT, // 0xDB
0x40,
SSD1306_DISPLAYALLON_RESUME, // 0xA4
SSD1306_NORMALDISPLAY, // 0xA6
SSD1306_DEACTIVATE_SCROLL,
SSD1306_DISPLAYON}; // Main screen turn on
ssd1306_commandList(init5, sizeof(init5));
TRANSACTION_END
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading adafruit_ssd1306.py around line 116 and compare its initialization sequence with the linked MicroPython, DisplayIO, and Arduino SSD1306 implementations. Trace which command differences depend on display dimensions or external VCC, then determine whether the current sequence is intentional or needs a documented change; the issue is done when that conclusion and its supporting tests or reproduction are recorded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100