Skip to content

Tutorial

MicroPython SSD1306 OLED on ESP32: Wiring, Text, Graphics and Sensors

Drive a 0.96 inch SSD1306 OLED from an ESP32 in MicroPython: wiring, driver install, text and drawing, a live sensor screen, SPI and SH1106 variants and fixes.

  • 5 min read
  • Updated November 7, 2026
MicroPython SSD1306 OLED on ESP32: Wiring, Text, Graphics and Sensors

Quick answer: to use an SSD1306 OLED with MicroPython on an ESP32, wire VCC → 3.3 V, GND → GND, SCL → GPIO22, SDA → GPIO21. Install the driver with import mip; mip.install("ssd1306") (or copy ssd1306.py to the board), then:

main.py
from machine import Pin, I2C
import ssd1306

i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)      # default address 0x3C
oled.text("Hello SolderHub", 0, 0)
oled.show()

Nothing appears until you call oled.show(). If the screen stays blank, run i2c.scan(): you should see [60] (0x3C) or [61] (0x3D). This guide covers wiring, drawing, live sensor screens, 128×32 modules, the SH1106 look-alike that needs a different driver, and a fix table.

What you needNotes
ESP32 with MicroPythonInstall MicroPython on ESP32
0.96" SSD1306 OLED, 128×64, I2C (4 pins)128×32 0.91" modules work too; 7-pin modules are SPI
4 jumper wiresShort wires help at 400 kHz
Optional: DHT22 or BME280For the live sensor screen

How the SSD1306 works (and why show() matters)

The SSD1306 is a controller chip with its own 1 KB of display memory: one bit per pixel, 128 × 64 = 8,192 pixels. The MicroPython driver keeps a copy of that memory in the ESP32's RAM (a frame buffer). Every drawing call (text(), line(), fill()) only changes the copy, and show() sends the whole buffer to the screen in one I2C transfer.

That design has three practical consequences:

  • Draw everything, then call show() once. Calling it after every line is slow and flickers.
  • fill(0) before redrawing, or old text stays underneath new text.
  • Bus speed matters. At the default 100 kHz a full refresh takes about 100 ms; at 400 kHz about 25 ms. Most modules run happily at 400 kHz on short wires.
SpecTypical 0.96" module
Resolution128 × 64 pixels (monochrome)
InterfaceI2C (4-pin) or SPI (7-pin)
I2C address0x3C (default) or 0x3D
Supply3.3–5 V (on-board regulator)
CurrentRoughly 10–20 mA, depending on how many pixels are lit

Designing a readable status screen

  • Keep one idea per line and no more than about 4 lines of data; tiny text from across a room is useless.
  • Put the most important value biggest, or alone on the line under the title.
  • Always show a status when a reading fails ("Sensor error", "Wi-Fi lost") instead of keeping the last value, which looks valid but isn't.
  • Add an update indicator: a blinking pixel in a corner, or the seconds since the last reading, so you can tell the screen hasn't frozen.
  • Turn the screen off at night with oled.poweroff() to save power and avoid burn-in.

1. Wire the OLED

OLED pinESP32 pin
VCC (or VDD)3.3 V
GNDGND
SCL (or SCK)GPIO22
SDAGPIO21

Most 4-pin modules have their own regulator and pull-up resistors, so no extra parts are needed. Check the pin order printed on your module: some boards swap VCC and GND, and reversing them can kill the display. On the ESP32 any GPIO can be used for I2C; 21/22 are just the common defaults (see ESP32 I2C pins).

2. Check the bus, then install the driver

Run this in the Thonny shell (REPL) first:

main.py
from machine import Pin, I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
print([hex(a) for a in i2c.scan()])      # expect ['0x3c'] or ['0x3d']

An empty list means wiring or power; fix that before anything else (MicroPython I2C scan guide).

The SSD1306 driver isn't part of the standard ESP32 firmware. Install it once, with the board connected to Wi-Fi:

main.py
import mip
mip.install("ssd1306")

Without Wi-Fi on the board, run mpremote mip install ssd1306 from your computer, or download ssd1306.py from the micropython-lib repository and save it to the board with Thonny (File → Save as → MicroPython device, inside /lib).

3. Show text

main.py
from machine import Pin, I2C
import ssd1306
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)
oled.fill(0)
# clear the buffer (0 = black)
oled.text("SolderHub", 0, 0)
# x, y in pixels
oled.text("ESP32 + OLED", 0, 16)
oled.text("MicroPython", 0, 32)
oled.show()
# send the buffer to the screen

The built-in font is 8×8 pixels, so a 128×64 screen fits 16 characters × 8 lines (y = 0, 8, 16 … 56). On many two-colour modules the top 16 rows are yellow and the rest blue: put a title on lines 0–8 and data below.

4. Drawing cheat sheet

The driver is built on MicroPython's framebuf, so you get these methods:

MethodDraws
fill(c)Whole screen black (0) or white (1)
pixel(x, y, c)One pixel
hline(x, y, w, c) / vline(x, y, h, c)Horizontal / vertical line
line(x1, y1, x2, y2, c)Any line
rect(x, y, w, h, c) / fill_rect(...)Outline / filled box
text(s, x, y, c)8×8 text
scroll(dx, dy)Shift the buffer
invert(1)Invert the display (hardware)
contrast(0–255)Brightness
poweroff() / poweron()Screen off/on (saves power and burn-in)

A progress bar, useful for sensor values:

main.py
def bar(oled, x, y, w, h, fraction):
    oled.rect(x, y, w, h, 1)
    oled.fill_rect(x + 2, y + 2, int((w - 4) * max(0, min(1, fraction))), h - 4, 1)

oled.fill(0)
oled.text("Humidity 62%", 0, 0)
bar(oled, 0, 20, 128, 12, 0.62)
oled.show()

5. A live sensor screen (DHT22)

Wire a DHT22 data pin to GPIO4 (see MicroPython DHT22 guide) and run this as main.py:

main.py
from machine import Pin, I2C
import ssd1306, dht, time
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
sensor = dht.DHT22(Pin(4))
while True:
    oled.fill(0)
    oled.text("Room monitor", 0, 0)
    try:
        sensor.measure()
        oled.text("Temp: {:.1f} C".format(sensor.temperature()), 0, 24)
        oled.text("Hum:  {:.1f} %".format(sensor.humidity()), 0, 40)
    except OSError:
        oled.text("Sensor error", 0, 32)
        # show the failure, don't fake a value
        oled.show()
        time.sleep(2)
        # DHT22: at most one reading every 2 s

Only redraw when something changes, or about once a second: each show() sends 1 KB over I2C (roughly 25 ms at 400 kHz).

6. 128×32 screens, SPI modules and SH1106 look-alikes

ModuleWhat to change
0.91" 128×32 I2Cssd1306.SSD1306_I2C(128, 32, i2c), so 4 lines of text
Address jumper set to 0x3Daddr=0x3D
7-pin SPI module (D0, D1, RES, DC, CS)SPI(1, baudrate=8000000, sck=Pin(18), mosi=Pin(23)) and ssd1306.SSD1306_SPI(128, 64, spi, Pin(dc), Pin(res), Pin(cs))
1.3" "OLED" (often SH1106, not SSD1306)Shows garbage or a 2-pixel shifted image with the SSD1306 driver. Install an SH1106 driver (sh1106.py) instead
Two OLEDs on one busSet one to 0x3D (address jumper/resistor on the back), create two objects

Bigger fonts: the built-in font is fixed at 8×8. For large digits, convert a font with micropython-font-to-py and draw it with its writer class, or scale text by drawing each pixel as a 2×2 block.

Memory: the 128×64 buffer uses 1 KB of RAM, which is fine on any ESP32. Long-running scripts that build many strings can fragment memory; call gc.collect() occasionally.

7. Troubleshooting

SymptomLikely causeFix
i2c.scan() returns []SDA/SCL swapped, no power, loose jumperRecheck the four wires; try freq=100000
OSError: [Errno 19] ENODEVWrong address, or display not respondingUse the address scan() reports (addr=0x3D)
ImportError: no module named 'ssd1306'Driver not installedmip.install("ssd1306") or copy ssd1306.py to /lib
Screen stays black but scan worksshow() never called, or contrast 0Call oled.show(); oled.contrast(255)
Random dots or shifted imageIt's an SH1106 moduleUse an SH1106 driver
Only the top half works128×32 settings on a 128×64 module (or vice versa)Match width and height to the module
Text cut off on the rightMore than 16 characters per lineShorten the text or scroll it
FlickerClearing and redrawing in a fast loopRedraw only on change, once a second at most
Display dies after a few secondsBrown-out from a weak supply, or VCC/GND reversedCheck pin order; use a decent USB supply

FAQ

Does SSD1306 need 3.3 V or 5 V? Most modules accept 3.3–5 V on VCC. Power it from the ESP32's 3.3 V so the I2C lines stay at 3.3 V.

Can I show images? Yes: convert a 1-bit bitmap to a bytearray, wrap it in framebuf.FrameBuffer(buf, w, h, framebuf.MONO_HLSB) and oled.blit(fb, x, y).

Will the OLED burn in? OLEDs can burn in if the same pixels stay lit for months. Turn the screen off when idle (oled.poweroff()) or move content occasionally.

Does the same code work on a Raspberry Pi Pico? Yes, with Pico pins: I2C(0, scl=Pin(5), sda=Pin(4)). See the Pico W pinout.

Next steps

Official references: MicroPython framebuf and the SSD1306 datasheet.

Continue learning

Related articles

All articles

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.