Skip to main content

How to Connect a 0.96-Inch OLED Display to ESP32 (I2C) – Beginner Guide with Wokwi

ESP32 OLED Display Tutorial – SSD1306 with MicroPython | MakeMindz
▶ Open Wokwi
🖥️ Summer Class — ESP32 + MicroPython

Display Text on OLED
with ESP32 & MicroPython

Connect a 0.96-inch SSD1306 OLED to ESP32 using I2C, write two lines of MicroPython, and see "Hello, Wokwi!" light up in minutes — all in your browser!

🟢 Beginner ⚡ ESP32 🖥️ SSD1306 OLED 🐍 MicroPython 📡 I2C ⏱ 15 min
SSD1306 128×64
Hello, Wokwi!
ESP32 · MicroPython
I2C · GPIO 21/22 addr 0x3C

What You'll Build

A working OLED display showing custom text — your first step toward IoT dashboards, weather monitors, and smart devices.

⏱️
~15
Minutes to build
Easy
Beginner level
🖥️
Free
Wokwi simulator
📐
128×64
OLED resolution
💡
Zero hardware needed! Everything runs in Wokwi's free browser simulator. The MicroPython firmware v1.21.0 is pre-loaded on the virtual ESP32 — no setup required.

What You Need

Only 2 virtual components — the simplest ESP32 display project you'll find!

ESP32 DevKit v1 (C4)
SSD1306 128×64 I2C OLED
4 × Jumper Wires (virtual)
MicroPython v1.21.0 firmware
🐍
No library installation needed! MicroPython's built-in ssd1306 module is included with the firmware. Just import it and start drawing.

Understanding the SSD1306 OLED

The SSD1306 is the most popular OLED driver chip — used in everything from smartwatches to maker projects.

📐
128×64 pixels
8,192 individually controlled pixels
📡
I2C protocol
Only 2 data wires (SDA + SCL)
Low power
~20mA at full brightness
🔆
High contrast
Self-emitting — no backlight needed
📌

OLED Pin Description

OLED PinFunctionDescription
VCCPower Supply3.3V from ESP32 — not 5V!
GNDGroundCommon ground reference
SCLI2C ClockSynchronises data transfer timing
SDAI2C DataCarries display commands and pixel data

ESP32 Default I2C Pins

The ESP32 DevKit uses GPIO 22 for SCL and GPIO 21 for SDA by default — just 4 wires total!

3V3
OLED VCC
3.3V power — not 5V!
GND
OLED GND
Common ground
GPIO 22
OLED SCL
I2C clock line
GPIO 21
OLED SDA
I2C data line
🔌

Full Connection Table

OLED PinESP32 PinWire Color
VCC3V3🔴 Red
GNDGND⬛ Black
SCLGPIO 22🟢 Green
SDAGPIO 21🔵 Blue
⚠️
Use 3.3V, not 5V! The SSD1306 OLED operates at 3.3V logic. Connecting VCC to 5V can damage the display permanently on real hardware.

Step-by-Step Guide

6 simple steps from zero to "Hello, Wokwi!" on your OLED.

  1. Open the Wokwi Simulation

    Click wokwi.com/projects/305568836183130690 to open the pre-built project, or go to wokwi.com → New Project → ESP32 to start from scratch.

  2. Select MicroPython as the language

    In Wokwi, the board board-esp32-devkit-c-v4 has a env attribute set to micropython-20231005-v1.21.0. This is already configured in the diagram.json — pasting it sets MicroPython automatically.

  3. Paste the diagram.json

    Click the diagram.json tab in Wokwi, select all, and paste the JSON from the Diagram JSON section below. This auto-places the ESP32 and OLED with all 4 wires connected.

  4. Add the MicroPython code

    Open the main.py tab and paste the code from the Code section below. Just 6 lines of Python — that's all it takes!

  5. Click ▶ Start Simulation

    Press the green play button. The virtual ESP32 boots MicroPython, initialises the I2C bus on GPIO 21/22, and sends the text to the OLED. The display should light up with "Hello, Wokwi!" within 1–2 seconds.

    Expected result: OLED shows white text "Hello, Wokwi!" at position (10, 10). No errors in the Serial Monitor console.
  6. Customise and experiment!

    Try changing the text string, coordinates, or add more oled.text() lines to display multiple rows. Use oled.fill(0) to clear the screen between updates.


🖥️ See It Running Live

Open the Wokwi simulation and watch "Hello, Wokwi!" appear on the virtual OLED — instantly, in your browser.

Open Live Simulation

Wokwi diagram.json

Paste this into the diagram.json tab. It configures MicroPython firmware on the ESP32 and wires the OLED with correct routed paths.

How to use in Wokwi
1. Click diagram.json tab → Select all → Delete
2. Paste the JSON below — ESP32 + OLED appear pre-wired
3. MicroPython v1.21.0 is auto-configured via the env attribute
4. Serial Monitor is also connected via the TX/RX lines
diagram.json — Wokwi
{
  "version": 1,
  "author": "Uri Shaked",
  "editor": "wokwi",
  "parts": [
    {
      "type": "board-esp32-devkit-c-v4",
      "id":   "esp",
      "top":  9.6,
      "left": -100.76,
      "attrs": {
        "env": "micropython-20231005-v1.21.0"
      }
      // ↑ This sets MicroPython firmware automatically
    },
    {
      "type": "board-ssd1306",
      "id":   "oled1",
      "top":  99.14,
      "left": 57.83,
      "attrs": {}
    }
  ],
  "connections": [
    // Serial Monitor connections (for debugging)
    [ "esp:TX",      "$serialMonitor:RX", "",       [] ],
    [ "esp:RX",      "$serialMonitor:TX", "",       [] ],

    // OLED I2C connections
    [ "oled1:SCL",  "esp:22",            "green", ["v0"] ],
    [ "oled1:SDA",  "esp:21",            "blue",  ["v-19.2", "h-124.73"] ],

    // OLED power
    [ "oled1:GND",  "esp:GND.2",         "black", ["v-67.2", "h-96"] ],
    [ "oled1:VCC",  "esp:3V3",           "red",   ["v-28.8", "h0.15", "v-76.8", "h-201.75"] ]
  ],
  "dependencies": {}
}

📋 Connection Reference

ConnectionPurpose
esp:TX → serialMonitor:RXEnables Serial Monitor output for debugging print() statements
oled1:SCL → esp:22I2C clock — GPIO 22 is the default SCL pin on ESP32 DevKit
oled1:SDA → esp:21I2C data — GPIO 21 is the default SDA pin on ESP32 DevKit
oled1:GND → esp:GND.2Ground reference for OLED circuit
oled1:VCC → esp:3V33.3V power — the SSD1306 is a 3.3V device

MicroPython Code

Just 6 lines of Python — paste this into the main.py tab in Wokwi.

main.py — MicroPython
# ESP32 OLED Display — SSD1306 with MicroPython
# MakeMindz Summer Class | makemindz.com
# Simulation: https://wokwi.com/projects/305568836183130690

from machine import Pin, I2C
import ssd1306

# ── I2C setup using ESP32 default pins ──
# GPIO 22 = SCL (clock)   GPIO 21 = SDA (data)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))

# ── OLED dimensions ──
oled_width  = 128
oled_height = 64

# ── Create OLED display object ──
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

# ── Display text ──
# oled.text(string, x, y)  — top-left is (0, 0)
oled.text('Hello, Wokwi!', 10, 10)   # Row 1
oled.text('MakeMindz.com', 10, 30)   # Row 2

# ── Push buffer to screen ──
oled.show()
🧪
Try these extras: Add oled.fill(0) before drawing to clear the screen, or use oled.invert(1) to flip to a black-on-white display. Each pixel position is (x, y) where (0,0) is the top-left corner.

How It Works

📡

I2C Communication

I2C (Inter-Integrated Circuit) is a 2-wire protocol that lets the ESP32 control the OLED using just SDA (data) and SCL (clock). The MicroPython line i2c = I2C(0, scl=Pin(22), sda=Pin(21)) creates an I2C bus on ESP32's hardware I2C bus 0. The SSD1306 listens on I2C address 0x3C by default. Multiple devices can share the same I2C bus as long as they have different addresses.

🖥️

SSD1306 Frame Buffer

The ssd1306.SSD1306_I2C() class maintains a 128×64 pixel frame buffer in ESP32 memory. When you call oled.text(), it writes characters into this buffer — but nothing appears on screen yet. Only when you call oled.show() does the ESP32 transfer the entire buffer to the OLED over I2C. This two-step approach prevents flickering during complex animations.

📐

Text Positioning

oled.text(string, x, y) positions text where x is pixels from the left edge and y is pixels from the top. The built-in font is 8×8 pixels per character, so each row of text is 8 pixels tall. With a 64-pixel height, you can fit up to 8 rows of text. Columns: 128 / 8 = 16 characters per row maximum.


Expected Output

After running the simulation, here's what you should see:

OLED Display Output

Hello, Wokwi!

MakeMindz.com

128×64 px · I2C addr 0x3C · GPIO 21/22

OLED lights up with white text
"Hello, Wokwi!" at position (10, 10)
"MakeMindz.com" at position (10, 30)
No errors in Serial Monitor

What You'll Learn

ESP32 default I2C pin assignments (GPIO 21/22)
I2C protocol — 2-wire multi-device bus
SSD1306 OLED driver and frame buffer concept
MicroPython machine.I2C class usage
Text positioning on pixel displays
Wokwi simulator for ESP32 + MicroPython
IoT display basics — foundation for dashboards
diagram.json structure for multi-component projects

Real-World Applications

Mastering this project unlocks a huge range of IoT and embedded display applications.

📊
IoT Dashboard
🌡️
Weather Monitor
🏠
Smart Home Display
📡
Real-time Sensor Data
📶
WiFi Status Monitor
Digital Clock / Timer
🤖
Robot Control Panel
💊
Medical Monitor UI

Comments

try for free