Wiring guide

How to wire an SSD1306 OLED to an Arduino Uno

To wire an SSD1306 OLED to an Arduino Uno, connect VCC to 5V, GND to GND, SDA to pin A4 and SCL to pin A5. The Arduino Uno is a 5 V board and the module has its own regulator, so it runs from 5 V and the bus stays at the board’s level. The sketch below uses the Adafruit SSD1306 and Adafruit GFX (Adafruit_SSD1306.h) library. It draws the board name, a box and a counter of the seconds since power-up.

  • 5 V logic
  • Library: Adafruit_SSD1306.h
  • 4 wires
Arduino Uno · SSD1306 OLEDlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

SSD1306 OLED to Arduino Uno wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

SSD1306 OLED pinArduino Uno pinWire colorWhy
VCC5VredThe module has its own regulator and runs from 3.3 or 5 V.
GNDGNDblueCommon ground.
SDApin A4violetArduino Uno’s I2C data line, where Wire.begin() puts it.
SCLpin A5cyanArduino Uno’s I2C clock line.
Voltage

Power and logic levels for SSD1306 OLED and Arduino Uno

Logic level

The Arduino Uno’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

Supply

The SSD1306 OLED takes 5 V from 5V. That is the Arduino Uno’s 5 V rail, so the part shares the current the board can supply.

This pair

On an Uno the I2C bus is A4 (SDA) and A5 (SCL). The SDA and SCL pins beside AREF are the same two wires, so either pair works. The display answers at address 0x3C, the address almost every 0.96 inch module ships with.

Pins to leave alone

Pins 0 and 1 are the USB serial port on a real Uno, so anything wired there fights the upload and the serial monitor. Pin 13 carries the onboard LED.

The sketch

The working code for the Arduino Uno

Library: Adafruit SSD1306 and Adafruit GFX (Adafruit_SSD1306.h). This is the sketch the circuit above runs.

SSD1306 on Arduino Uno I2C
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// 128 x 64 pixels, on the I2C bus: SDA pin A4, SCL pin A5
Adafruit_SSD1306 display(128, 64, &Wire, -1);

void setup() {
  Serial.begin(9600);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("No SSD1306 at 0x3C");
    for (;;) {}
  }
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(2);
  display.setCursor(0, 0);
  display.println("HELLO");
  display.setTextSize(1);
  display.println("SSD1306 OLED");
  display.drawRect(0, 40, 128, 24, SSD1306_WHITE);
  display.display();
  Serial.println("OLED ready");
}

void loop() {
  // A counter in the box, redrawn twice a second.
  display.fillRect(2, 42, 124, 20, SSD1306_BLACK);
  display.setCursor(8, 48);
  display.print("Up for ");
  display.print(millis() / 1000);
  display.print(" s");
  display.display();
  delay(500);
}
Output

What you should see

The panel shows HELLO in large letters, SSD1306 OLED below it, and a box with Up for followed by a number of seconds that counts up. The serial monitor, at 9600 baud, prints OLED ready once.

If the monitor prints No SSD1306 at 0x3C instead, nothing answered on the bus: check SDA and SCL first. The font in the simulator has capitals only, so lower case prints as capitals.

The serial monitor prints this, recorded from the circuit above running:

OLED ready
Pitfalls

Common mistakes wiring an SSD1306 OLED to an Arduino Uno

Forgetting display()

Every call before display() only changes the copy in RAM. A sketch that draws and never calls display() leaves the screen black, and that is the most common "my OLED does not work" there is.

Trying address 0x3D first

Adafruit’s own example uses 0x3D, the address of their 128 by 64 board with the jumper changed. The cheap blue and yellow modules answer at 0x3C. If begin() fails, the address is the first thing to check.

Running out of RAM

The display’s buffer takes 1 KB of the ATmega328P’s 2 KB. Add a few long strings and begin() fails because malloc() could not find room. Wrap fixed text in F("...") to keep it in flash.

Build your own SSD1306 OLED project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.