Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize display cmd #76

Open
TimonPeng opened this issue Sep 7, 2022 · 2 comments
Open

Initialize display cmd #76

TimonPeng opened this issue Sep 7, 2022 · 2 comments
Labels

Comments

@TimonPeng
Copy link

TimonPeng commented Sep 7, 2022

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

# 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

# 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

  // 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
@TimonPeng
Copy link
Author

TimonPeng commented Sep 7, 2022

Theoretically the ssd1309 is partially compatible with the ssd1306, but the different drivers above show different results and I would like to know what the standard is..

@markbirss
Copy link

@TimonPeng

I found and used this other driver with my SDD1309 Display
https://github.com/smittytone/SSD1306OLED-Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants