datasith / Ai_Ardulib_SSD1306

Library for using SSD1306-powered OLED displays in the Arduino IDE.
MIT License
56 stars 22 forks source link

128x32 screen support #7

Closed matt199x closed 5 years ago

matt199x commented 6 years ago

I am trying to get this to work on a 128x32 ssd1306 screen. The text makes it to the screen but is not displayed correctly. I'm assuming something in the .cpp file needs to be changed because I changed `#define SSD1306_Max_X 127

define SSD1306_Max_Y 63 `

to `#define SSD1306_Max_X 127

define SSD1306_Max_Y 31 ` in the .h file and it did the same thing. Any help would be appreciated.

hugovangalen commented 5 years ago

@matt199x This code works for me. I admit it could be done more elegantly but I haven't got the time but figured I'd share this.

void ACROBOTIC_SSD1306::init(void)
{
  sendCommand(0xAE);            //display off
  sendCommand(0xA6);            //Set Normal Display (default)
  sendCommand(0xAE);            //DISPLAYOFF
  sendCommand(0xD5);            //SETDISPLAYCLOCKDIV
  sendCommand(0x80);            // the suggested ratio 0x80

  sendCommand(0xA8);            //SSD1306_SETMULTIPLEX
    sendCommand( SSD1306_Max_Y ); // 32 - 1

  sendCommand( 0xD3 );
    sendCommand( 0x00 );

  //sendCommand(0x3F);
  sendCommand(0xD3);            //SETDISPLAYOFFSET
  sendCommand(0x0);             //no offset
  sendCommand(0x40|0x0);        //SETSTARTLINE
  sendCommand(0x8D);            //CHARGEPUMP
  sendCommand(0x14);
  sendCommand(0x20);            //MEMORYMODE
  sendCommand(0x00);            //0x0 act like ks0108
  sendCommand(0xA1);            //SEGREMAP   Mirror screen horizontally (A0)
  sendCommand(0xC8);            //COMSCANDEC Rotate screen vertically (C0)
  sendCommand(0x12);            //COMSCANDEC
  sendCommand(0xDA);            //0xDA
  sendCommand(0x02);
  sendCommand(0x81);            //SETCONTRAST
  sendCommand(0x8F);
  sendCommand(0xd9);            //SETPRECHARGE 
  sendCommand(0xF1); 
  sendCommand(0xDB);            //SETVCOMDETECT                
  sendCommand(0x40);
  sendCommand(0xA4);            //DISPLAYALLON_RESUME        
  sendCommand(0xA6);            //NORMALDISPLAY             
  clearDisplay();
  sendCommand(0x2E);            //Stop scroll
  sendCommand(0x20);            //Set Memory Addressing Mode
  sendCommand(0x00);            //Set Memory Addressing Mode ab Horizontal addressing mode
  setFont(font8x8);
}
datasith commented 5 years ago

Thanks for the help! I've added a more general implementation where the default size is assumed to be 128x64, but can be overridden from the sketch by using a #define SSD1306_128_32 statement.

matt199x commented 5 years ago

Thank you guys!