🛠 Afficheur OLED I2C SSD1306
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
- GD32F103C8T6 / CBT6 Blue Pill compatible board
- 0.91" or 0.96" SSD1306 OLED module in I2C mode (address 0x3C in general)
- I2C pins: SCL on PB6, SDA on PB7 (default mapping for I2C0 on LQFP48) >
- 4.7 kΩ pull-up resistors to 3.3 V on SCL and SDA (often integrated into the OLED module)
- Module VCC at 3.3 V only (2.6-3.6 V for the GD32 pins)
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
- Address 0x3C vs 0x3D: some modules are set to 0x3D (strap on the module); perform an I2C scan before blaming the bus.
- SCL/SDA swapped: the display never responds; swap the two wires (the bus cannot be damaged by this swap, but it also causes no harm).
- Missing pull-ups: without pull-up resistors, the bus never releases the line; check if your module includes them (very often yes).
- VCC at 5 V: some modules accept 5 V on VCC but output a 5 V logic level, which is outside the GD32's guaranteed range; power it with 3.3 V.
- Wrong I2C port: the GD32 has 2 I2C interfaces; if the core maps Wire to I2C0 and you wired the pins for I2C1 (or the remap PB8/PB9), the bus remains silent. >
- Screen flickering at the bottom: the 0.91" SSD1306 is sometimes 128x32; use the appropriate size (Adafruit_SSD1306 128x32).
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinopotentiometre.inoArduinopont-uart.inoArduinooled-i2c.inoArduino