🛠 Afficheur OLED I2C SSD1306

GD32F103 (GigaDevice) — chip + Blue-Pill-compatible boards · intermediaire · Schéma : IMG-gd32f103-intermediaire-3-i2c-oled-ssd1306.svg — module OLED SSD1306 0,91 pouce en I2C sur le bus du GD32F103C8 : SCL, SDA avec résistances de pull-up, VCC 3,3 V, adresse 0x3C

Objectives

Control a 128x64 SSD1306 OLED display via I2C from the GD32F103C8, which features 2 I2C peripherals. This is the "canonical" demo of the GD32 community ecosystem: the CommunityGD32Cores repositories (gd32-pio-projects and the Arduino core demos) specifically showcase an SSD1306 (often paired with a DHT11). You will learn about bus wiring, the role of pull-up resistors, and address diagnostics.

Hardware

Complete Code

// oled_i2c.ino — GD32F103C8 + SSD1306 I2C 0x3C
// Bibliothèques : Adafruit GFX + Adafruit SSD1306 (gestionnaire de librairies).
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define ADRESSE_OLED 0x3C
Adafruit_SSD1306 ecran(128, 64, &Wire, -1);
uint8_t tour = 0;

void setup {
  Serial.begin(115200);
  Wire.begin;   // bus I2C par défaut du core GD32
  if (!ecran.begin(SSD1306_SWITCHCAPVCC, ADRESSE_OLED)) {
    Serial.println("OLED absent : verifier 3.3V, SCL/SDA, adresse 0x3C");
    while (true) { delay(100); }
  }
  ecran.clearDisplay;
  ecran.setTextColor(SSD1306_WHITE);
  ecran.setCursor(0, 0);
  ecran.println("Bonjour GD32F103!");
  ecran.display;
}

void loop {
  ecran.fillRect(0, 20, 128, 12, SSD1306_BLACK);
  ecran.setCursor(0, 20);
  ecran.print("Compteur : ");
  ecran.println(tour++);
  ecran.display;
  delay(1000);
}

Expected Verification

The screen displays "Bonjour GD32F103!" followed by a counter that increments every second. If begin fails, the error message appears on the USART0 serial console. An I2C scan ("I2C scanner" sketch) must list address 0x3C when the module is connected.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials