Arduino: OLED Display (SSD1306)

The ones I got were 126×64 displays powered by SSD1306 chips. They run over I2C so they are pretty easy to wire up:

DEVICENANO
GNDGround
VCC+5V
SCLA5
SDAA4

You do have to make sure you have the right I2C address in your code. For some reason mine were labeled as using “0x78” but were actually “0x3C”. (Thanks, anonymous Amazon reviewer!)

As far as code, it’s pretty easy to use the Adafruit SSD1306 and Adafruit GFX libraries. But for my purposes it was too resource intensive so I found an ASCII only library.

// Demo of ASCII only OLED library
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

//Configure Screen
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiWire oled;

void setup() {
    Wire.begin();
    oled.begin(&Adafruit128x64, I2C_ADDRESS);
    oled.setFont(System5x7);
    oled.clear();    
}

void loop() {
      oled.setCursor(0, 0);
      oled.print("TEXT GOES HERE");
      delay(1000);      
}

To move text to different parts of the screen use “oled.setCursor(column,row);” My displays have 8 rows (0-7) with the default text size. Each character is approximately 5 pixels wide.

If you want to make the text bigger you can use “oled.set2X();” before your “oled.print” statement.

UPDATE:

If you want to use a 128×32 display use the following portions of code:

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

oled.begin(&Adafruit128x32, I2C_ADDRESS);


This entry was posted in Arduino and tagged . Bookmark the permalink.