oled-i2c.py
A 0.96" SSD1306 OLED (128x64) wired in I2C shows text and a counter. The script first scans the bus to confirm the module is present, then uses the ssd1306.py driver shipped with MicroPython.
Hardware
A generic RP2350 (dual Cortex-M33) board programmed with MicroPython. 1 SSD1306 I2C OLED module (4 pins: VCC, GND, SCL, SDA), address usually 0x3C.
Wiring
SDA to GP4, SCL to GP5, VCC to 3V3, common GND. Pull-up resistors are usually already on the module.
How it works
I2C(0, ...) sets up the hardware controller; i2c.scan() lists answering addresses. The driver builds the 128x64 frame in RAM then oled.show() transfers it in one block.
Running it
Flash the « RP2350 » MicroPython build via BOOTSEL (.uf2), then copy the script to the drive. The user LED pin varies by manufacturer: check the board documentation.
Variants
Switch to SPI for faster refresh, or display the internal temperature by combining with the matching ADC script.
oled-i2c.py
# OLED SSD1306 128x64 en I2C avec le pilote ssd1306.py de MicroPython.
from machine import I2C, Pin
import ssd1306
import time
# I2C0 : SDA = GP4, SCL = GP5 (broches arbitraires mais classiques).
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
# Verifier la presence du module (adresse usuelle 0x3C) :
trouves = i2c.scan()
print("Peripheriques I2C :", [hex(a) for a in trouves])
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.fill(0)
oled.text("Bonjour !", 0, 0, 1)
oled.text("I2C 0x3C", 0, 10, 1)
oled.show()
time.sleep(2)
n = 0
while True:
oled.fill(0)
oled.text("Compteur", 0, 0, 1)
oled.text(str(n), 0, 20, 1)
oled.text("RP2 MicroPython", 0, 44, 1)
oled.show() # transfere l'ecran entier
n += 1
time.sleep(1)