Arduino is still the default in many schools, but the Raspberry Pi Pico + MicroPython combo is easier when your students already know Python. The Pico has far more RAM than an Uno, so you're not fighting a PROGMEM puzzle anymore. Your OLED animation is just a normal bytearray loop.
Here you'll get I2C wiring, the official-style ssd1306 driver with framebuf, text, shapes and a multi-frame animation. There are no photos. It's just pins, code and the mistakes that waste a lab period.
What you need
- A Raspberry Pi Pico or Pico W
- The MicroPython UF2, already flashed on your board
- A 0.96" I2C SSD1306 (3.3V-friendly, and Pico IO is 3.3V)
- Thonny, or another MicroPython IDE you like
- The
ssd1306.pydriver on your Pico's filesystem (see below)
Wiring (the Pico I2C0 defaults we'll use)
| OLED | Pico | Notes |
|---|---|---|
| VCC | 3V3 | Don't use VBUS 5V unless the module is clearly 5V-tolerant and level-safe |
| GND | GND | Common ground |
| SDA | GP4 (pin 6) | I2C0 SDA |
| SCL | GP5 (pin 7) | I2C0 SCL |
You can move to other I2C-capable pins. Just change the constructor. If your screen stays blank, run an I2C scan in MicroPython before you blame the driver.
I2C scanner (MicroPython)
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
print("Devices:", [hex(a) for a in i2c.scan()])
You should see 0x3c (sometimes 0x3d). If you get an empty list, it's wiring or power, so fix that first.
Driver file: ssd1306.py
MicroPython firmware for the Pico does not include the SSD1306 driver, so import ssd1306 fails until you add
ssd1306.py to the board. The official file now lives in the
micropython-lib repository
at micropython/drivers/display/ssd1306/ssd1306.py (older guides point to drivers/display/ in the main MicroPython repo, which is where it used to be).
Three ways to install ssd1306.py
- From your PC with mpremote: plug in the Pico and run
mpremote mip install ssd1306. It downloads the driver from micropython-lib and copies it to the board. - On a Pico W that is on WiFi: connect to your network, then at the REPL run
import mipandmip.install("ssd1306"). - By hand in Thonny: open
ssd1306.pyfrom the micropython-lib link above, paste it into a new Thonny file, and use File → Save as → Raspberry Pi Pico with the namessd1306.py(in the root, next tomain.py).
Check it worked by running import ssd1306 at the REPL. No error means the driver is on the board. If you see
ImportError: no module named 'ssd1306', the file is missing or saved under another name or folder.
ssd1306.py cheat sheet
The driver has two classes. SSD1306_I2C(width, height, i2c, addr=0x3C, external_vcc=False) is the one this guide uses;
SSD1306_SPI(width, height, spi, dc, res, cs) is for 7-pin SPI modules. Both subclass
framebuf.FrameBuffer, so every framebuf drawing call works on the display object.
| Call | What it does |
|---|---|
oled.fill(0) / oled.fill(1) | Clear the buffer to black, or fill it white |
oled.pixel(x, y, 1) | Set one pixel |
oled.text("Hi", x, y) | Draw 8×8 text |
oled.hline, vline, line, rect, fill_rect | Lines and boxes |
oled.blit(fb, x, y) | Copy another FrameBuffer (a sprite or animation frame) onto the screen |
oled.scroll(dx, dy) | Shift the buffer contents |
oled.show() | Send the buffer to the panel. Nothing appears until you call it. |
oled.contrast(0–255) | Brightness |
oled.invert(1) | Swap black and white on the panel |
oled.rotate(True) | Flip the picture 180° when the module is mounted upside down |
oled.poweroff() / poweron() | Turn the panel off to save battery, and back on |
Hello World
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import time
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)
oled.fill(0)
oled.text("Hello Pico", 0, 0)
oled.text("SSD1306 OK", 0, 16)
oled.show()
while True:
time.sleep(1)
Always call oled.show() after you draw. It's the same idea as Arduino's display.display().
Shapes and a simple HUD
oled.fill(0)
oled.rect(0, 0, 128, 64, 1) # border
oled.fill_rect(4, 4, 40, 10, 1) # header bar
oled.text("TEMP", 6, 5) # note: text on filled bar needs inverse trick
# easier: text outside fill
oled.fill(0)
oled.rect(0, 0, 128, 64, 1)
oled.text("Temp C", 4, 4)
oled.text("24.6", 4, 24)
oled.hline(4, 40, 120, 1)
oled.fill_rect(4, 44, 72, 8, 1) # fake bar
oled.show()
MicroPython's built-in font is 8×8. If you want bigger digits, you can either scale by drawing blocks or blit a custom framebuffer glyph.
Multi-frame animation with bytearrays
Each 128×64 monochrome frame is 1024 bytes (MVLSB layout used by the driver). On a Pico you can keep many frames in RAM. Here's an example with three tiny programmatic frames (no external files):
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf
import time
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
def make_ball_frame(x):
buf = bytearray(1024)
fb = framebuf.FrameBuffer(buf, 128, 64, framebuf.MONO_VLSB)
fb.fill(0)
fb.text("Pico OLED", 0, 0)
fb.fill_rect(x, 28, 12, 12, 1)
return buf
frames = [make_ball_frame(x) for x in (10, 40, 70, 100, 70, 40)]
while True:
for buf in frames:
oled.blit(framebuf.FrameBuffer(buf, 128, 64, framebuf.MONO_VLSB), 0, 0)
# Faster path: copy into oled buffer then show
oled.show()
time.sleep_ms(80)
There's a cleaner pattern. Draw directly into oled each frame instead of prebuilding buffers, unless you need to play back imported GIF frames.
Playing exported animation frames
If you export MicroPython / framebuf data from oledanimationmaker.com, you'll typically get a list of bytearray literals, or a flat bytes object plus a frame count. Here's a skeleton:
# frames_data = [ bytes([...]), bytes([...]), ... ] # from exporter
FRAME_W, FRAME_H = 128, 64
FRAME_SIZE = FRAME_W * FRAME_H // 8
while True:
for raw in frames_data:
fb = framebuf.FrameBuffer(bytearray(raw), FRAME_W, FRAME_H, framebuf.MONO_VLSB)
oled.fill(0)
oled.blit(fb, 0, 0)
oled.show()
time.sleep_ms(100)
Confirm the exporter's bit order matches MONO_VLSB. If your image looks sliced or mirrored, check width and height first, because a wrong size is the usual culprit. Try the other mono formats only after that.
Partial updates and speed
oled.show()sends the whole buffer over I2C, and that's fine for 128×64.- Raise your I2C
freqto 400000 (shown above). Some modules tolerate 1_000_000, but not all do. - Don't
print()every frame to USB, because it stalls your animation in Thonny. - Sleep with
time.sleep_ms. Don't use busy loops.
Pico vs Arduino Uno for OLED animation
| Uno + Arduino C++ | Pico + MicroPython | |
|---|---|---|
| RAM | 2 KB (tight) | 264 KB (comfortable) |
| Flash for frames | PROGMEM juggling | Normal arrays / files |
| Language | C++ sketches | Python |
| Startup | Upload sketch | Paste/run or main.py |
| Classroom fit | Classic electronics courses | CS / Python courses |
Using main.py so it runs on power-up
Save your animation as main.py on the Pico, and it auto-runs on reset. Keep a way to recover if an infinite loop locks USB (hold BOOTSEL, reflash, or interrupt in Thonny). It's rare, but you should show your students the escape hatch.
Troubleshooting
- OSError on construct: you've got the wrong addr or no ACK, so run the scanner.
- ImportError ssd1306: the file isn't on your device, or the name or case is wrong.
- Garbled image: you've got an SH1106 module, or the wrong framebuffer format.
- Works in REPL once, fails as main.py: an exception at import. Wrap your setup in try/except and show the error text on the OLED if you want self-debug.
- Brownout when powering OLED from 3V3 pin with other loads: power your OLED from a solid 3.3V supply and share GND.
Complete minimal animation project
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import time
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
x, dir_ = 0, 1
while True:
oled.fill(0)
oled.text("MicroPython", 0, 0)
oled.fill_rect(x, 28, 16, 16, 1)
oled.show()
x += dir_ * 4
if x < 0 or x > 112:
dir_ = -dir_
time.sleep_ms(40)
FAQ
Where do I download ssd1306.py for MicroPython?
From the official micropython-lib repository, at micropython/drivers/display/ssd1306/ssd1306.py. The quickest install is mpremote mip install ssd1306 from your PC, or mip.install("ssd1306") on a board with WiFi. See the install steps above.
Can I use CircuitPython instead?
Yes, you can, but the APIs differ slightly (displayio). This article targets MicroPython's ssd1306 + framebuf path.
Does a Pico W change anything for my OLED?
The same I2C pins work. WiFi uses power, so you'll want to watch for brownouts on weak USB hubs.
Can I load frames from the filesystem?
Yes. Store raw 1024-byte files or a single blob and read them with open(). It's good for longer animations, since you won't end up with huge main.py files.
The guide uses GP4 and GP5, but my scanner is empty. Should I try GP0?
Only if your Dupont wires are really on GP0 and GP1. This article's examples construct I2C(0, sda=Pin(4), scl=Pin(5)). A script written for GP0/GP1 won't see a display wired to GP4/GP5. Match the constructor to your pins, then you should see 0x3c or 0x3d.
Why is my animation smooth in Thonny and jerky from main.py?
A print() every frame waits on USB when Thonny's open, and an exception before oled.show() leaves your panel black when USB isn't attached. Print a frame count every 30 frames, and draw an error string on the OLED inside except, so you can see a bad import without the REPL.
Can I clock this I2C bus at 1 MHz for more FPS?
Some SSD1306 modules tolerate freq=1000000, but you can't count on it. Many clones ACK at 400 kHz and then paint garbage or stay black at 1 MHz. Keep 400000 unless you've tested that exact panel. One 128×64 frame is 1024 bytes, which is already a short transfer at 400 kHz.
My sprite looks sliced or shifted two columns. Is framebuf wrong?
Check your width and height first. The buffer must be 1024 bytes for 128×64 MONO_VLSB. If the size is right and the whole image is shifted, your module is often an SH1106 (132×64 RAM with a column offset), not a bad bytearray. The MicroPython ssd1306 driver won't apply that offset for you.
A bounded sprite with a real frame clock
The tiny loop earlier on this page proves your panel works. This one is what I leave running on a demo Pico: the box stays on screen, the period is measured with ticks_ms, and USB prints don't stall every frame. Wiring stays on the pins you've already used above: SDA GP4, SCL GP5, VCC on 3V3, address 0x3c.
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import time
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3C)
x, step = 0, 4
last = time.ticks_ms()
frames = 0
t_report = last
while True:
now = time.ticks_ms()
if time.ticks_diff(now, last) < 33:
continue
last = now
oled.fill(0)
oled.text("Pico 33ms", 0, 0)
oled.fill_rect(x, 26, 16, 16, 1)
oled.show()
x += step
if x > 112 or x < 0:
step = -step
x += step
frames += 1
if time.ticks_diff(now, t_report) >= 1000:
# one number per second, not one print per frame
print("fps", frames)
frames = 0
t_report = now
ticks_diff is the safe subtraction on a Pico, and a plain now - last will mis-fire after the millisecond counter wraps. The 16×16 box uses x from 0 through 112 so it never draws past column 127. oled.show() pushes the whole framebuffer, 1024 bytes for 128×64, which is the same idea as Arduino's display.display(). If you skip show(), the previous picture stays up and it looks like a frozen animation.
If you blit exported frames later, keep them as MONO_VLSB and don't convert them to a second RAM copy "just in case" unless you've measured a stall. The Pico has the RAM (264 KB) that an Uno doesn't, so a few dozen 1024-byte frames are fine. Hundreds of frames belong in files, not in a giant main.py that Thonny times out on while you're saving.
Symptoms that look like a bad animation
i2c.scan()returns[]. Your wires are on different pins thanPin(4)andPin(5), SDA and SCL are swapped, or VCC is on VBUS (5 V) into a module that isn't happy there. Move VCC to 3V3 (physical pin 36) and keep GND common. A blank list means wiring, and the frame loop can't fix it.- Scan prints
0x3c, constructor raisesOSError. Youraddr=argument doesn't match, or a second device is sitting on the same address. Passaddr=0x3cexplicitly.0x3dis the other common module. You can't set the address resistor from inside MicroPython. - Scan works,
show()runs, glass stays black. It's contrast or the wrong controller. Try a fulloled.fill(1)thenoled.show(). If your panel is still black, power and ACK are fine and the init sequence is wrong, often an SH1106 sold as SSD1306. If the white field is only a bright strip, it's the same diagnosis. - Picture tears or the Pico resets when Wi-Fi starts. On a Pico W the radio current dips a weak USB hub. Your animation didn't overflow. Use a powered hub or a short cable, and don't start the CYW43 stack in the middle of a tight
show()loop until the 3V3 rail is solid. ImportError: no module named 'ssd1306'only after reboot. You saved the file to your PC, not to the Pico, or you named itSSD1306.py. MicroPython imports are case-sensitive. Save it as/ssd1306.pyon the device.- FPS prints 30 in the REPL and the motion looks like 8. You're printing every frame as well as counting. USB text is slower than the OLED transfer, so keep the once-per-second print from the example above.
Pico, Pico W, and a port to ESP32
Stay on GP4 and GP5 for every sketch in this article unless you move the wires and the constructor together. GP0 and GP1 are a valid I2C0 pair on the Pico pin mux, but they're the wrong pair if your OLED is already plugged into pins 6 and 7 (GP4 and GP5). I2C1 is a different peripheral, and I2C(0, ...) won't drive it.
| Board | SDA / SCL in this project | What changes |
|---|---|---|
| Pico | GP4 / GP5, 3V3 | Baseline. 264 KB RAM, so frame lists are ordinary bytearrays |
| Pico W | Same GP4 / GP5 | Same OLED code. Wi-Fi adds current; a cheap hub browns out show() |
| ESP32 running MicroPython | Not GP4. Use GPIO21 / GPIO22 | New Pin numbers, same ssd1306.py and 1024-byte frames. Power the module from 3.3 V |
An Arduino Uno port is a library change, not a frame-size change. You still have 1024 bytes per 128×64 image, but you don't have 264 KB of RAM, so those frames move to PROGMEM and your loop becomes drawBitmap plus display(). SPI instead of I2C is only worth it if you need a higher frame rate than this 33 ms loop. At 400 kHz, I2C already keeps up with a 30 fps demo on the Pico.
Reset on these 4-pin modules isn't a Pico GPIO. If your breakout brings RES out and you've grounded it, the scanner can still be empty, or the panel can ACK and stay black. Leave RES to the module's own pull-up.
Related guides you might like
Export MicroPython-friendly frames
Build your animation visually, then adapt the byte arrays into the blit loop above.
Open the free tool →Free tools: OLED Animation Maker for your SSD1306 and SH1106 animations, Assemble Studio for your name and logo animations, the Shadow Box Lamp Generator for your 3D-printed shadow lamps, Text to STL for your 3D-printed names and keychains, and 3MF to Web to show your 3D prints on any website. New: the Image to Byte Array converter, the OLED Robot Eyes generator and the Lithophane Maker. See all tools.