oled-i2c.ino
The SSD1306 OLED is the universal I2C display: two wires, no proprietary library. The sketch writes a framebuffer then pushes it with a single display() — the right discipline against flicker.
Hardware required
A classic ESP32 board (ESP32-WROOM-32 module, dual-core Xtensa 240 MHz, Wi-Fi + Bluetooth) such as a DevKitC / DOIT V1, powered over micro-USB. 1 I2C SSD1306 128×64 OLED module (4 pins).
Wiring
VCC 3.3 V, GND, SDA/SCL on the SoC default I2C pins (often GPIO21/22; check your board). Address 0x3C (sometimes 0x78 → jumper).
How it works
Wire drives the bus; Adafruit_SSD1306 keeps a RAM framebuffer and copies it in one shot on display(). begin() detects a missing chip and the serial monitor does the debugging. In the Arduino IDE, install the « esp32 » board package, pick « Dev Module », the port, then Upload (hold BOOT if detection fails). GPIO34-39 are input-only; avoid GPIO6-11 and GPIO12.
Going further
Add the DHT22 readings from the previous sketch, or scroll a message when the buffer exceeds 64 pixels of height.
oled-i2c.ino
// OLED SSD1306 128x64 en I2C (0x3C) — Adafruit SSD1306 + GFX.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define ADRESSE 0x3C
#define RAZ -1
Adafruit_SSD1306 oled(128, 64, &Wire, RAZ);
void setup() {
Serial.begin(115200);
Wire.begin(); // SDA/SCL par defaut du SoC
if (!oled.begin(SSD1306_SWITCHCAPVCC, ADRESSE)) {
Serial.println("OLED absent : scanner 0x3C ?");
for (;;);
}
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(1);
}
void loop() {
oled.clearDisplay();
oled.setCursor(0, 0);
oled.println(F("Carte "));
oled.setTextSize(2);
oled.printf("%lu ms\n", millis());
oled.setTextSize(1);
oled.printf("Heap : %u o\n", ESP.getFreeHeap());
oled.printf("Rssi : %d dBm\n", WiFi.Rssi());
oled.display(); // envoie le framebuffer
delay(250);
}