How to wire an SSD1306 OLED to an Arduino Nano
To wire an SSD1306 OLED to an Arduino Nano, connect VCC to 5V, GND to GND, SDA to pin A4 and SCL to pin A5. The Arduino Nano 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
SSD1306 OLED to Arduino Nano 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 pin | Arduino Nano pin | Wire color | Why |
|---|---|---|---|
| VCC | 5V | red | The module has its own regulator and runs from 3.3 or 5 V. |
| GND | GND | blue | Common ground. |
| SDA | pin A4 | violet | Arduino Nano’s I2C data line, where Wire.begin() puts it. |
| SCL | pin A5 | cyan | Arduino Nano’s I2C clock line. |
Power and logic levels for SSD1306 OLED and Arduino Nano
Logic level
The Arduino Nano’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 Nano’s 5 V rail, so the part shares the current the board can supply.
This pair
The Nano has the Uno’s chip, so I2C is A4 (SDA) and A5 (SCL), on the analog side of the board next to A6 and A7. The display answers at address 0x3C, the address almost every 0.96 inch module ships with.
Pins to leave alone
A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.
The working code for the Arduino Nano
Library: Adafruit SSD1306 and Adafruit GFX (Adafruit_SSD1306.h). This is the sketch the circuit above runs.
#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);
}
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 readyCommon mistakes wiring an SSD1306 OLED to an Arduino Nano
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.