🛠 Afficher sur un OLED I2C SSD1306 et déboguer le bus

RP2040 (generic board / chip) · intermediaire · Schéma : IMG-rp2040-generic-intermediaire-1-rp2040-i2c-oled-ssd1306.svg — module OLED 0,96 pouces SSD1306 relié en I2C à une carte RP2040 générique : VCC 3V3, GND, SDA sur GP4, SCL sur GP5, écran affichant température et texte

Objectives

Set up a standalone display on your RP2040 board: the RP2040's I2C (2 controllers, mappable to any GPIO — datasheet) driven by MicroPython, using the classic OLED SSD1306 128×64 module. You will mainly learn how to scan an I2C bus — the skill that saves you when you don't know if the module is dead, miswired, or at address 0x3C or 0x3D.

Hardware

Complete Code

# scan_i2c.py — d'abord, trouver le module
from machine import I2C, Pin
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
print('adresses vues:', i2c.scan)     # attendu: [60] soit 0x3C

# oled_demo.py — afficher température interne + texte
import ssd1306, time
from machine import Temp

oled = ssd1306.I2C(128, 64, device=i2c)  # adresse 0x3C détectée
try:
    temp = Temp                        # capteur interne (MicroPython >= 1.22)
except NameError:
    from machine import ADC
    _a = ADC(4)                          # fallback : canal ADC4 interne
    def read_T:
        mv = _a.read_u16 * 3.3 / 65535
        return 27.0 - (mv - 0.706) / 0.001721
else:
    def read_T:
        return temp.temperature

oled.text('RP2040 generique', 0, 0, 1)
oled.text('I2C 400 kHz OK', 0, 10, 1)
while True:
    oled.text('T: %6.2f C' % read_T, 0, 30, 1)
    oled.show
    time.sleep_ms(500)

Expected Verification

i2c.scan returns [60] (0x3C in decimal — the other possible address for the SSD1306 is 0x3D, set by a jumper on the module). The screen displays text lines and the temperature of the RP2040's internal sensor, which rises when you touch the chip. Disconnect SDA: scan returns [] — the bus is alive, and so is the driver.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials