Arduino OLED Display Tutorial (Wiring & Code)
Overview
If you want to add a user interface, display sensor data, or create custom animations, an OLED Arduino display is one of the most popular and versatile components you can use.
In this guide, I’ll walk you through everything you need to know about setting up an OLED display with an Arduino, including how to draw basic text, geometric shapes, and scrolling animations. For the complete visual walkthrough and advanced bitmap image rendering, be sure to check out the accompanying video above!
Understanding Your OLED Arduino Display
Before wiring anything, it’s important to understand the hardware you are working with. There are a few common points of confusion:
- 3.3V vs 5V Logic: Most of these displays can tolerate both 3.3V and 5V, so powering them is usually straightforward.
- I2C vs SPI Communication: Check the pins on your display. If your OLED has
SCLandSDApins, it uses I2C. If you see pins labeledDCorCS, it uses SPI. In this tutorial, we are focusing on the highly popular I2C version. - SSD1306 vs SH1106 Drivers: Displays might look identical but use different drivers. I am using an SH1106 driver, but it runs perfectly fine using the standard SSD1306 library. Just keep in mind that the SH1106 has a 132-column wide RAM, while the SSD1306 is 128 columns wide. For basic text, it doesn’t matter, but it’s worth noting for precise animations.
Wiring the OLED Display to your Arduino
For this project, I am using an Arduino Nano 33 BLE Sense, but the wiring is exactly the same for the classic Arduino Uno or standard Arduino Nano.
Here is the standard I2C wiring pinout:
- VCC → Connect to 3.3V (or 5V depending on your board/display specs)
- GND → Connect to Ground
- SCL (Serial Clock) → Connect to Arduino A5
- SDA (Serial Data) → Connect to Arduino A4
(Note: On standard Arduinos like the Uno and Nano, A4 and A5 are the dedicated I2C pins).
Arduino OLED Code: Displaying Basic Text
To get the display running, you first need to install two core libraries in your Arduino IDE:
Adafruit GFX LibraryAdafruit SSD1306
Once installed, here is the basic code snippet to initialize the display and print your first text:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
// 0x3C is default i2c adress in some cases MAY be different
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10, 10);
display.println("Subscribe");
display.display();
}
void loop() {
}
Advanced: Scrolling, Shapes, and Custom Bitmaps
The Adafruit_GFX library makes it incredibly easy to do much more than just print text:
- Scrolling: You can trigger built-in hardware scrolling using methods like
display.startscrollright(0x00, 0x0F). - Shapes: Drawing triangles, circles, and lines only takes a single function call (e.g.,
display.drawTriangle(...)). - Custom Images: You can display your own logos and graphics by converting normal photos into 1-bit monochrome byte arrays.
I wrote a custom Python script that easily converts any image into a C-array that the Arduino can render using display.drawBitmap().
Want to see exactly how to code the animations, draw complex shapes, and use the Python image converter? Watch the video at the top of the page for the full demonstration!
You can also find all the advanced code snippets in the project repository here.