Built-in project · Raspberry Pi Pico

CircuitPython OLED text on a Pico

CircuitPython on a Raspberry Pi Pico: displayio and Adafruit’s display_text draw a title and a counter on an SSD1306 OLED over I2C. The whole build, a Raspberry Pi Pico and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

The parts retail for about $8. On Mokxi they're free.

CircuitPython OLED text on a Pico · Raspberry Pi Picolive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.

code.py · Raspberry Pi Pico
# CircuitPython on a Raspberry Pi Pico: text on an SSD1306 OLED.
# I2C0 on GP5 (SCL) and GP4 (SDA). displayio draws a label with the built-in
# terminalio font; adafruit_displayio_ssd1306 and adafruit_display_text go
# into lib/ for you.
import board
import busio
import displayio
import i2cdisplaybus
import terminalio
import time
import adafruit_displayio_ssd1306
from adafruit_display_text import label

displayio.release_displays()
i2c = busio.I2C(board.GP5, board.GP4)
bus = i2cdisplaybus.I2CDisplayBus(i2c, device_address=0x3C)
display = adafruit_displayio_ssd1306.SSD1306(bus, width=128, height=64)

group = displayio.Group()
title = label.Label(terminalio.FONT, text="Hello, Pico!", x=4, y=8)
counter = label.Label(terminalio.FONT, text="", x=4, y=32, scale=2)
group.append(title)
group.append(counter)
display.root_group = group

n = 0
while True:
    counter.text = str(n)
    print("count", n)
    n += 1
    time.sleep(1)

Parts list

2 parts, plus the jumper wires. They retail for about $8; on Mokxi they're free.

How it is wired

4 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: Raspberry Pi Pico pin GND; OLED display, 128x64 pin GND
  • Raspberry Pi Pico pin GP4; OLED display, 128x64 pin SDA
  • Raspberry Pi Pico pin GP5; OLED display, 128x64 pin SCL
  • Raspberry Pi Pico pin 3V3; OLED display, 128x64 pin VCC

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.