How to Use Oled With Esp32 in 5 Minutes "SSD1306 I2C Tutorial + Code"

by ztr0nics in Circuits > Microcontrollers

467 Views, 2 Favorites, 0 Comments

How to Use Oled With Esp32 in 5 Minutes "SSD1306 I2C Tutorial + Code"

I2C-OLED-ESP32.png

In this project, you’ll learn how to use an SSD1306 OLED display with ESP32 using a 0.96” I2C OLED display module. The SSD1306 OLED display is one of the most popular and beginner-friendly displays for ESP32 and Arduino projects thanks to its low power consumption, sharp graphics, and simple 4-wire connection.

With only 4 wires and the I2C protocol, you can display text, animations, graphics, and real-time sensor data on a compact OLED screen. Whether you are building an IoT dashboard, weather station, WiFi monitor, or smart home project, learning how to use OLED with ESP32 is an essential maker skill.

This ESP32 OLED tutorial also works as a great introduction to using an I2C OLED display for DIY electronics projects. After learning how to use the SSD1306 OLED display, you can also build this ESP32 OLED Pac-Man game or Snake Game.

Supplies

how-to-connect-a-0-96”-OLED-display-to-an-ESP32-using-I2C.png

SSD1306 OLED Display Parts Needed


OLED Display 0.96” (SSD1306)

[https://amzn.to/3QZi0xy]

ESP32 Dev Board

[https://amzn.to/41StgOD]

Jumper Wires

[https://amzn.to/4sNeWSA]


⚠️ Some links may be affiliate links. This does not change the price for you.


Tip: Use exactly the same components from the video to avoid compatibility issues.

Video

How to Use OLED with ESP32 (SSD1306 Guide)

If you want to replicate this project, use the exact components listed above to avoid compatibility issues.

ESP32 SSD1306 OLED Code

More examples at GitHub


#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() {
Wire.begin(21, 22);

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED failed");
for(;;);
}

display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);

display.setCursor(0, 10);
display.println("ESP32");
display.setCursor(0, 35);
display.println("OLED");

display.display();
}

void loop() {}

⚡ SSD1306 OLED Display Wiring

  1. OLED ESP32
  2. VCC 3.3V
  3. GND GND
  4. SCL GPIO 22
  5. SDA GPIO 21

Testing the OLED Display

After uploading the code, the OLED should display text clearly.

If you only see a line or nothing:

  1. Check I2C address (0x3C vs 0x3D)
  2. Verify wiring
  3. Make sure you are using 3.3V (not 5V)


WHAT NEXT

You can now:

  1. Add animations
  2. Build ESP32 Oled Game
  3. Display sensor data
  4. Build a mini dashboard
  5. Create IoT projects with ESP32

FAQ

What is an SSD1306 OLED display?

The SSD1306 OLED display is a small low-power monochrome display commonly used with Arduino and ESP32 boards.

Is SSD1306 I2C or SPI?

Most SSD1306 OLED modules support both I2C and SPI communication.

What library is used for SSD1306 on ESP32?

Most projects use the Adafruit SSD1306 library with Adafruit GFX.

FINAL

You'll have your display running in less than 5 minutes!


Follow me for more ESP32 and Arduino projects.