From 43acfb8d609b2a4f94630a95ddcc4aa56747bca7 Mon Sep 17 00:00:00 2001 From: Aleksandar Mitev Date: Fri, 26 Jun 2015 14:40:12 +0300 Subject: [PATCH 1/2] Ported library for SH1106 display controller Scrolling doesn't work --- Adafruit_SSD1306.cpp | 26 ++++++++++++++++++++++++++ Adafruit_SSD1306.h | 15 ++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Adafruit_SSD1306.cpp b/Adafruit_SSD1306.cpp index 6febbada..d9ac8e72 100644 --- a/Adafruit_SSD1306.cpp +++ b/Adafruit_SSD1306.cpp @@ -474,6 +474,30 @@ void Adafruit_SSD1306::ssd1306_data(uint8_t c) { } void Adafruit_SSD1306::display(void) { + +#if defined SH1106_128_64 + for (int index = 0; index < 8; index++) { + ssd1306_command(SH1106_SETSTARTPAGE + index); + /* for some reason display is shifted by 2 columns + * on 1.3" displays from ebay + */ + ssd1306_command(SSD1306_SETLOWCOLUMN + 2); // low column start address + ssd1306_command(SSD1306_SETHIGHCOLUMN); // high column start address + + for (int pixel = 0; pixel < SSD1306_LCDWIDTH; pixel++) { + Wire.beginTransmission(_i2caddr); + WIRE_WRITE(0x40); + // input buffer doesn't accept all bytes at once + for (uint8_t x=0; x<16; x++) { + WIRE_WRITE(buffer[index * SSD1306_LCDWIDTH + pixel]); + ++pixel; + } + --pixel; + Wire.endTransmission(); + } + } +#else + ssd1306_command(SSD1306_COLUMNADDR); ssd1306_command(0); // Column start address (0 = reset) ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset) @@ -530,6 +554,8 @@ void Adafruit_SSD1306::display(void) { TWBR = twbrbackup; #endif } + +#endif } // clear everything diff --git a/Adafruit_SSD1306.h b/Adafruit_SSD1306.h index c7ddc76c..baf1167e 100644 --- a/Adafruit_SSD1306.h +++ b/Adafruit_SSD1306.h @@ -57,19 +57,26 @@ All text above, and the splash screen must be included in any redistribution SSD1306_96_16 -----------------------------------------------------------------------*/ - #define SSD1306_128_64 + #define SH1106_128_64 +// #define SSD1306_128_64 // #define SSD1306_128_32 // #define SSD1306_96_16 /*=========================================================================*/ + +#if defined SSD1306_128_64 && defined SH1106_128_64 + #error "Select either SH1106 or SSD1306 display type in SSD1306.h" +#endif + #if defined SSD1306_128_64 && defined SSD1306_128_32 #error "Only one SSD1306 display can be specified at once in SSD1306.h" #endif -#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 +#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && \ + !defined SSD1306_96_16 && !defined SH1106_128_64 #error "At least one SSD1306 display must be specified in SSD1306.h" #endif -#if defined SSD1306_128_64 +#if defined SSD1306_128_64 || defined SH1106_128_64 #define SSD1306_LCDWIDTH 128 #define SSD1306_LCDHEIGHT 64 #endif @@ -119,6 +126,8 @@ All text above, and the splash screen must be included in any redistribution #define SSD1306_EXTERNALVCC 0x1 #define SSD1306_SWITCHCAPVCC 0x2 +#define SH1106_SETSTARTPAGE 0xB0 + // Scrolling #defines #define SSD1306_ACTIVATE_SCROLL 0x2F #define SSD1306_DEACTIVATE_SCROLL 0x2E From 9577d4db52dd9ac621eb0123872487b629866ce1 Mon Sep 17 00:00:00 2001 From: Aleksandar Date: Fri, 26 Jun 2015 15:09:11 +0300 Subject: [PATCH 2/2] Updated README --- README.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 420cc153..dbaa2be2 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,5 @@ +>> Also has support for a SH1106 display driver driven by I2C. << + This is a library for our Monochrome OLEDs based on SSD1306 drivers Pick one up today in the adafruit shop! @@ -21,4 +23,4 @@ Place the Adafruit_SSD1306 library folder your /libraries/ You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from https://github.com/adafruit/Adafruit-GFX-Library -and download/install that library as well \ No newline at end of file +and download/install that library as well