Skip to content

OLED Library for 3+ displays

ss_oled (Small Simple OLED library)

Note

ss_oled library works on a board connected in I2C network as Secondary. For Example, Master board just send “1” by wire.write, each Secandary board can controll OLED by ss_oled. No need to controll OLED from Master. Secondary will do.

Note

ss_oled uses 2 GPOI pins for one OLED, can use 2 OLEDs or more. OLED normally has 1 or 2 I2C address. but different contents for each OLED more than 3!!

  • Supports any number of simultaneous displays of any type (mix and match)
  • Optionally detect the display address and type (I2C only)
  • Supports 72x40, 96x16, 64x32, 128x32, 128x64, 128x128 (SH1107) and 132x64 (SH1106) display sizes
  • Drive displays from I2C, SPI or any 2 GPIO pins (virtual I2C)
  • 5 sizes of fixed fonts (6x8, 8x8, 12x16, 16x16, 16x32)
  • a function to load a Windows BMP file
  • Light enough to run on an ATtiny85 (8KB MCU)
  • This code depends on the BitBang_I2C library

Example

Master

1
2
3
4
5
Wire.beginTransmission(9) ; // Secondary address is 9
Wire.write("1", strlen("1")); // Send 1 to secondary
Wire.endTransmission();
Serial.print("sent "); Serial.println("3");
delay(500);

Secandary

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <Wire.h>
int x = 0;

#include <ss_oled.h>
#define SDA_PIN 8
#define SCL_PIN 9
#define RESET_PIN -1  //connected to the reset
#define OLED_ADDR -1  // let ss_oled figure out the display address
#define FLIP180 0  // don't rotate the display
#define INVERT 0  // don't invert the display
#define USE_HW_I2C 0// Bit-Bang the I2C bus
#define MY_OLED OLED_128x32

SSOLED ssoled;
int rc;

void setup() {
  Wire.begin(9);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);


  //rc = oledInit(&ssoled, MY_OLED,   OLED_ADDR, FLIP180, INVERT, USE_HW_I2C, SDA_PIN, SCL_PIN, RESET_PIN, 400000L); // use standard I2C bus at 400Khz
  rc = oledInit(&ssoled, OLED_128x32, 0x3C,      0,       0,      0,            SDA_PIN, SCL_PIN, -1,        400000L); // use standard I2C bus at 400Khz

} /* setup() */

void receiveEvent(int bytes) { // Interrupt Service Routine 割り込み
  x = Wire.read(); // read e from Master
  Serial.print("received -------------" ); Serial.println((char)x);// "1" is ASCII code 49
}


void loop() {

  //OLED
  if (x != '1') {
    Serial.println("OLED Matte");
    oledFill(&ssoled, 0, 1);
    oledSetTextWrap(&ssoled, 1);
    //oledWriteString(SSOLED *pOLED, int iScrollX, int x, int y, char *szMsg, int iSize, int bInvert, int bRender);
    oledWriteString(&ssoled,                    5,     5,     0, (char *)"Matte", FONT_STRETCHED, 0, 1);
  } else if (x == '1') {
    Serial.println("OLED DOZO");
    oledFill(&ssoled, 0, 1);
    oledSetTextWrap(&ssoled, 1);
    //oledWriteString(SSOLED *pOLED, int iScrollX, int x, int y, char *szMsg, int iSize, int bInvert, int bRender);
    oledWriteString(&ssoled,                    5,     5,     0, (char *)"DOZO!!", FONT_STRETCHED, 0, 1);
    x = '0';
  }
  delay(3000);

} /* loop() */


Last update: September 20, 2021