Wiring guide

How to wire an SSD1306 OLED to an Arduino Uno R4

To wire an SSD1306 OLED to an Arduino Uno R4, connect VCC to 5V, GND to GND, SDA to pin A4 and SCL to pin A5. The Arduino Uno R4 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 R4 · 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 R4 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 R4 pinWire colorWhy
VCC5VredThe module has its own regulator and runs from 3.3 or 5 V.
GNDGNDblueCommon ground.
SDApin A4violetArduino Uno R4’s I2C data line, where Wire.begin() puts it.
SCLpin A5cyanArduino Uno R4’s I2C clock line.
Voltage

Power and logic levels for SSD1306 OLED and Arduino Uno R4

Logic level

The Arduino Uno R4’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 R4’s 5 V rail, so the part shares the current the board can supply.

This pair

The Uno R4 keeps the Uno’s layout: I2C is A4 (SDA) and A5 (SCL), also brought out as SDA and SCL beside AREF. The display answers at address 0x3C, the address almost every 0.96 inch module ships with.

Pins to leave alone

An Uno sketch’s source builds for the R4, but a compiled Uno program will not run on it: different chip. The R4’s pins source less current than an Uno’s, about 8 mA each, so do not drive a relay coil or a motor straight from one.

The sketch

The working code for the Arduino Uno R4

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

SSD1306 on Arduino Uno R4 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 R4

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.

Mixing up the 128x32 module

The 128 by 32 OLED uses the same chip and the same address, but the constructor needs 128, 32. Built for 64 rows, everything is drawn half off the panel.

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.