ESP32 - SSD1309 OLED Display 128x64 | 2.42 inch I2C OLED Handleiding

Een OLED (Organic Light-Emitting Diode) display bevat zelflichtgevende pixels die diepe zwarttinten, hoog contrast en brede kijkhoeken bieden — waardoor het een uitstekende upgrade is ten opzichte van traditionele LCD’s. De SSD1309 is de driver IC die vaak wordt gebruikt op 2.42-inch (soms aangeduid als 2.4-inch) 128×64 I2C OLED modules.

ESP32 SSD1309 2.42-inch OLED

In deze stapsgewijze handleiding leert u hoe u het SSD1309 OLED 128×64 display aansluit en programmeert met een ESP32 board, gebruikmakend van de DIYables_OLED_SSD1309 bibliotheek. We behandelen specifiek:

Hardware Benodigd

1×ESP32 ESP-WROOM-32 Ontwikkelingsmodule
1×USB-kabel Type-C
1×SSD1309 I2C OLED Display 128x64 (2.42 inch)
1×Breadboard (experimenteerprint)
1×Jumper wires
1×(Optioneel) DC Power Jack
1×(Aanbevolen) Schroefklem Uitbreidingsboard voor ESP32
1×(Aanbevolen) Breakout Expansion Board for ESP32
1×(Aanbevolen) Stromsplitter voor ESP32

Of u kunt de volgende kits kopen:

1×DIYables Sensorkit (30 sensoren/displays)
1×DIYables Sensorkit (18 sensoren/displays)
Openbaarmaking: Sommige van de links in deze sectie zijn Amazon-affiliate links. We kunnen een commissie ontvangen voor aankopen die via deze links worden gedaan, zonder extra kosten voor u. We waarderen uw steun.

Over het SSD1309 2.42-Inch OLED Display

De SSD1309 is een single-chip CMOS OLED driver IC ontworpen voor 128×64 dot-matrixpanelen. Het is register-compatible met de veelgebruikte SSD1306, waardoor veel bestaande codevoorbeelden met minimale aanpassingen bruikbaar zijn. De belangrijkste hardwareverschillen zijn:

  • Geen ingebouwde charge pump — de SSD1309 vereist een externe VCC voeding, hoewel vrijwel alle breakout boards (inclusief de 2.42-inch en 2.4-inch modules) worden geleverd met een on-board boost converter, wat dit voor u transparant maakt.
  • Hogere spanningsacceptatie — de SSD1309 accepteert tot 16 V VCC, terwijl de SSD1306 beperkt is tot ongeveer 4,2 V.

Het 2.42 inch (2.4 inch) OLED module gebruikt doorgaans de SSD1309 driver en heeft een resolutie van 128×64 pixels met een I2C-interface. De achtergrondkleur (wit, blauw, geel, groen of dual-zone) wordt bepaald door het fysieke OLED materiaal en is niet softwarematig te beïnvloeden.

Deze handleiding communiceert met het display via de I2C-bus, die slechts twee signaaldraadjes (SDA en SCL) nodig heeft en gedeeld kan worden met andere I2C randapparatuur.

SSD1309 OLED Pinout (I2C Module)

Het typische 2.42-inch SSD1309 I2C OLED module heeft vier pinnen:

  • GND pin: moet verbonden worden met de massa (ground) van de ESP32
  • VCC pin: moet verbonden worden met de 3.3V of 5V pin van de ESP32 (controleer de specificaties van uw module)
  • SCL pin: is de I2C klokpin. Verbind met GPIO 22 (standaard SCL)
  • SDA pin: is de I2C datapin. Verbind met GPIO 21 (standaard SDA)
SSD1309 OLED Pinout

※ Notiz:

De pinvolgorde kan per fabrikant verschillen. Controleer altijd de labels die op uw OLED-module gedrukt staan.

Bedradingsschema

  • Hoe ESP32 te verbinden met SSD1309 OLED 128x64 display met behulp van een breadboard
ESP32 SSD1309 OLED 128x64 bedrading schema

This image is created using Fritzing. Click to enlarge image

Hoe ESP32 te verbinden met SSD1309 OLED

This image is created using Fritzing. Click to enlarge image

Hoe ESP32 te programmeren voor SSD1309 OLED

Installeer de DIYables_OLED_SSD1309 Bibliotheek

De DIYables_OLED_SSD1309 bibliotheek is speciaal afgestemd op SSD1309-displays en breidt Adafruit_GFX uit voor uitgebreidere grafische ondersteuning.

  • Open de Arduino IDE
  • Navigeer naar het Libraries icoon in de linkerzijbalk
  • Zoek naar DIYables_OLED_SSD1309
  • Klik op Install
  • Er verschijnt een afhankelijkheidsmelding — klik op Install All om ook de Adafruit GFX Library te installeren (vereist voor vormtekeningen en lettertypen)
ESP32 SSD1309 OLED bibliotheek

Programmeerstappen

  1. Include de benodigde libraries
#include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h>
  1. Definieer de schermafmetingen
#define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64
  1. Declareer het display object
#define OLED_RESET -1 // Reset pin niet gebruikt op de meeste I2C-modules #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  1. Initialiseer de OLED in setup()
if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocatie mislukt")); for (;;); // pauzeren }
  1. Toon content
display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 20); display.println(F("Hello ESP32")); display.display(); // buffer naar scherm sturen

ESP32 Code — Hello World op SSD1309 OLED

Het eenvoudigste startpunt: druk een paar tekstregels af in verschillende groottes.

/* * Deze ESP32 code is ontwikkeld door newbiely.nl * Deze ESP32 code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/esp32/esp32-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Hello World * Prints text in two sizes on the 2.42 inch 128x64 I2C OLED with ESP32. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(115200); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.setTextSize(1); // 6x8 pixels per character display.setTextColor(SSD1309_PIXEL_ON); // turn pixels on display.setCursor(0, 0); display.println(F("Hello, World!")); display.println(); display.setTextSize(2); // 12x16 pixels per character display.println(F("DIYables")); display.setTextSize(1); display.println(); display.println(F("SSD1309 OLED 128x64")); display.display(); // push buffer to screen } void loop() { }

ESP32 Code — Tekst weergeven op SSD1309 OLED

Het volgende voorbeeld laat meer tekstfuncties zien — meerdere formaten, nummeropmaak en de F() macro voor RAM-besparing.

/* * Deze ESP32 code is ontwikkeld door newbiely.nl * Deze ESP32 code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/esp32/esp32-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Display Text * Displays text in various sizes and formats on the 2.42" SSD1309 OLED with ESP32. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(115200); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); // Various text sizes display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 0); display.println(F("Size 1 - DIYables")); display.setTextSize(2); display.println(F("Size 2")); display.setTextSize(3); display.println(F("Sz3")); display.display(); delay(3000); // Number formatting display.clearDisplay(); display.setTextSize(1); display.setCursor(0, 0); int value = 42; float pi = 3.14159; display.print(F("Integer: ")); display.println(value); display.print(F("Float: ")); display.println(pi, 2); // 2 decimal places display.print(F("Hex: 0x")); display.println(value, HEX); display.print(F("Binary: 0b")); display.println(value, BIN); display.display(); } void loop() { }

Nuttige Display Functies Referentie

Hieronder een lijst van meest gebruikte functies bij het werken met de SSD1309 OLED via de DIYables bibliotheek:

  • oled.clearDisplay() — wist de frame buffer (alle pixels uit).
  • oled.display() — stuurt de buffer naar de OLED zodat aanpassingen zichtbaar worden.
  • oled.drawPixel(x, y, color) — zet of wist een individuele pixel.
  • oled.setTextSize(n) — schaalt het lettertype met factor *n* (1 = 6×8, 2 = 12×16, …, tot 8).
  • oled.setCursor(x, y) — verplaatst de tekstcursor naar pixellocatie *(x, y)*.
  • oled.setTextColor(SSD1309_PIXEL_ON) — tekst met alleen voorgrondkleur (achtergrond is transparant).
  • oled.setTextColor(SSD1309_PIXEL_OFF, SSD1309_PIXEL_ON) — tekst met expliciete achtergrondkleur.
  • oled.println("message") — print een tekststring en gaat door naar volgende regel.
  • oled.println(number) — print een geheel getal in decimaal formaat.
  • oled.println(number, HEX) — print een geheel getal in hexadecimaal.
  • oled.startscrollright(start, stop) — hardware-scroll rechts tussen pagina’s *start* en *stop*.
  • oled.startscrollleft(start, stop) — hardware-scroll links.
  • oled.startscrolldiagright(start, stop) — hardware-scroll diagonaal rechts.
  • oled.startscrolldiagleft(start, stop) — hardware-scroll diagonaal links.
  • oled.stopscroll() — stopt actieve hardware-scroll.
  • oled.setContrast(value) — regelt schermhelderheid (0–255).
  • oled.dim(true/false) — zet snel dimmen aan of uit, schakelt naar minimum of vorige helderheid.
  • oled.invertDisplay(true/false) — keert pixels om (aan ↔ uit).

Hoe tekst verticaal en horizontaal centreren op de SSD1309 OLED

Zie How to vertical/horizontal center on OLED

ESP32 Code — Teken vormen op SSD1309 OLED

Omdat de DIYables_OLED_SSD1309 bibliotheek Adafruit_GFX uitbreidt, krijgt u een complete set vorm-tekenfuncties: pixels, lijnen, rechthoeken, gevulde rechthoeken, cirkels, gevulde cirkels, driehoeken, gevulde driehoeken en afgeronde rechthoeken. Onderstaand voorbeeld toont ze allemaal met geanimeerde demo’s.

/* * Deze ESP32 code is ontwikkeld door newbiely.nl * Deze ESP32 code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/esp32/esp32-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Draw Shapes * Demonstrates drawing pixels, lines, rectangles, circles, and triangles on the 2.42" OLED with ESP32. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(115200); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.display(); } void loop() { // Draw pixels display.clearDisplay(); for (int i = 0; i < 20; i++) { display.drawPixel(random(SCREEN_WIDTH), random(SCREEN_HEIGHT), SSD1309_PIXEL_ON); } display.display(); delay(2000); // Draw lines display.clearDisplay(); for (int y = 0; y < SCREEN_HEIGHT; y += 8) { display.drawLine(0, 0, SCREEN_WIDTH - 1, y, SSD1309_PIXEL_ON); } display.display(); delay(2000); // Draw rectangles display.clearDisplay(); display.drawRect(10, 10, 40, 30, SSD1309_PIXEL_ON); // outline display.fillRect(60, 10, 40, 30, SSD1309_PIXEL_ON); // filled display.drawRoundRect(10, 45, 40, 15, 5, SSD1309_PIXEL_ON); // rounded corners display.display(); delay(2000); // Draw circles display.clearDisplay(); display.drawCircle(32, 32, 20, SSD1309_PIXEL_ON); // outline display.fillCircle(96, 32, 20, SSD1309_PIXEL_ON); // filled display.display(); delay(2000); // Draw triangles display.clearDisplay(); display.drawTriangle(20, 10, 10, 50, 30, 50, SSD1309_PIXEL_ON); // outline display.fillTriangle(90, 10, 70, 50, 110, 50, SSD1309_PIXEL_ON); // filled display.display(); delay(2000); }

ESP32 Code — Hardware Scrollen op SSD1309 OLED

De SSD1309 heeft een ingebouwde scrollmotor die de scherminhoud verschuift zonder CPU-belasting. De DIYables bibliotheek ondersteunt vier scrollrichtingen: rechts, links, diagonaal-rechts en diagonaal-links. Elke functie neemt een start- en stop-pagina parameter (pagina’s zijn 8-pixel hoge horizontale stroken genummerd 0–7 op een 64-pixels hoog scherm).

※ Notiz:

Roep altijd display() aan om de inhoud naar het OLED scherm te sturen voordat u begint met scrollen. Vermijd tekenen van nieuwe inhoud terwijl scrollen actief is — roep eerst stopscroll() aan.

/* * Deze ESP32 code is ontwikkeld door newbiely.nl * Deze ESP32 code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/esp32/esp32-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Scroll Text * Demonstrates all four hardware scroll directions on the 2.42" OLED with ESP32. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(115200); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(10, 24); display.println(F("DIYables")); display.display(); delay(2000); } void loop() { // Scroll right across all pages display.startscrollright(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); // Scroll left display.startscrollleft(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); // Diagonal scroll right display.startscrolldiagright(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); // Diagonal scroll left display.startscrolldiagleft(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); }

ESP32 Code — Bitmap afbeelding weergeven op SSD1309 OLED

Om een bitmap te tonen op het SSD1309 OLED moet u eerst de afbeelding converteren naar een C byte array. Gebruik de gratis image2cpp online tool voor deze conversie:

  1. Upload uw afbeeldingsbestand (PNG, JPG, BMP, etc.).
  2. Stel de canvasgrootte in op 128×64 (of kleiner).
  3. Kies Arduino code als uitvoerformaat.
  4. Kopieer de gegenereerde array in uw sketch.
image to bitmap array

Het voorbeeld hieronder wisselt tussen een 16×16 hart icoon en een full-width DIYables logo:

/* * Deze ESP32 code is ontwikkeld door newbiely.nl * Deze ESP32 code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/esp32/esp32-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Display Bitmap Image * Shows a 16x16 heart icon and 128x64 DIYables logo on the 2.42" OLED with ESP32. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // 16x16 heart icon bitmap const unsigned char heart_icon[] PROGMEM = { 0x00, 0x00, 0x0c, 0x30, 0x1e, 0x78, 0x3f, 0xfc, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0x3f, 0xfc, 0x1f, 0xf8, 0x0f, 0xf0, 0x03, 0xc0, 0x00, 0x00 }; // 128x64 DIYables logo bitmap const unsigned char diyables_logo[] PROGMEM = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x07, 0xff, 0xc1, 0xff, 0xe0, 0x7f, 0xf0, 0x1f, 0xfc, 0x03, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xff, 0xf7, 0xff, 0xf9, 0xff, 0xfc, 0x7f, 0xff, 0x0f, 0x80, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xfe, 0xff, 0xff, 0x9f, 0xc0, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x7f, 0x80, 0xff, 0x00, 0x7f, 0xc0, 0x3f, 0xf0, 0x0f, 0xfc, 0x00, 0x1f, 0xff, 0xff, 0xf0, 0x00, 0xfe, 0x00, 0x7f, 0x00, 0x3f, 0x80, 0x1f, 0xe0, 0x07, 0xf8, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x01, 0xfc, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x03, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x07, 0xff, 0xff, 0xc0, 0x07, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x0f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x03, 0xff, 0xff, 0x80, 0x0f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x01, 0xff, 0xff, 0x80, 0x1f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x01, 0xff, 0xff, 0x00, 0x3f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xff, 0x00, 0x3f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x7f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x7f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x00, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x00, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x01, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xf8, 0x01, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xf8, 0x03, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xf0, 0x03, 0xff, 0xfc, 0x00, 0x7e, 0x00, 0x1f, 0x80, 0x1f, 0xe0, 0x07, 0xf8, 0x00, 0x00, 0xff, 0xf0, 0x07, 0xff, 0x7f, 0x80, 0xff, 0x00, 0x7f, 0xc0, 0x3f, 0xf0, 0x0f, 0xfc, 0x00, 0x00, 0xff, 0xf0, 0x07, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xfe, 0xff, 0xff, 0x9f, 0xc0, 0x00, 0xff, 0xe0, 0x0f, 0xfc, 0x1f, 0xff, 0xf7, 0xff, 0xf9, 0xff, 0xfc, 0x7f, 0xff, 0x0f, 0x80, 0x00, 0xff, 0xe0, 0x0f, 0xf8, 0x07, 0xff, 0xc1, 0xff, 0xe0, 0x7f, 0xf0, 0x1f, 0xfc, 0x03, 0x00, 0x00, 0xff, 0xe0, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x7f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x7f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xfe, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x0f, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3e, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x7c, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xf8, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; void setup() { Serial.begin(115200); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.display(); } void loop() { // Display small heart icon centered display.clearDisplay(); display.drawBitmap((SCREEN_WIDTH - 16) / 2, (SCREEN_HEIGHT - 16) / 2, heart_icon, 16, 16, SSD1309_PIXEL_ON); display.display(); delay(3000); // Display full-screen DIYables logo display.clearDisplay(); display.drawBitmap(0, 0, diyables_logo, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1309_PIXEL_ON); display.display(); delay(3000); // Invert display display.invertDisplay(true); delay(2000); display.invertDisplay(false); delay(1000); }

※ Notiz:

  • De bitmapafmetingen mogen de schermresolutie niet overschrijden (128×64 voor het 2.42 inch module).

ESP32 Code — Contrast en Dimbaarheid op SSD1309 OLED

De SSD1309 ondersteunt 256 contrastniveaus (0–255). De DIYables bibliotheek biedt setContrast() voor fijne regeling en dim() voor een snelle wissel tussen minimum helderheid en de eerder ingestelde waarde.

/* * Deze ESP32 code is ontwikkeld door newbiely.nl * Deze ESP32 code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/esp32/esp32-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Contrast & Dim * Sweeps contrast from 0→255→0 then toggles dim mode on the 2.42" OLED with ESP32. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(115200); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } // Draw a test pattern so the contrast changes are visible display.clearDisplay(); display.fillRect(0, 0, 64, 32, SSD1309_PIXEL_ON); display.fillRect(64, 32, 64, 32, SSD1309_PIXEL_ON); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_INVERSE); display.setCursor(16, 28); display.println(F("Contrast Demo")); display.display(); delay(2000); } void loop() { // Ramp up for (int c = 0; c <= 255; c += 5) { display.setContrast((uint8_t)c); delay(30); } delay(1000); // Ramp down for (int c = 255; c >= 0; c -= 5) { display.setContrast((uint8_t)c); delay(30); } delay(1000); // Quick dim toggle display.dim(true); // minimum brightness delay(2000); display.dim(false); // restore delay(2000); }

ESP32 Code — Aangepaste Externe Lettertypen op SSD1309 OLED

De Adafruit GFX bibliotheek levert tientallen schaalbare FreeFont lettertypes (Serif, Sans, Mono — elk in Regular, Bold, Italic en vier formaten). U activeert ze op het SSD1309 display door de juiste header toe te voegen en setFont() op te roepen.

※ Notiz:

  • Wanneer een extern lettertype actief is, verwijst de Y-coördinaat van de cursor naar de tekst baseline, niet naar de linkerbovenhoek. Dit wijkt af van het ingebouwde 5×7 font.
  • Externe lettertypen worden opgeslagen in flash geheugen (PROGMEM). De ESP32 heeft ruim flash geheugen, dus het gebruik van meerdere fontbestanden in uw project is prima mogelijk.
/* * Deze ESP32 code is ontwikkeld door newbiely.nl * Deze ESP32 code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/esp32/esp32-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – External Fonts * Cycles through three FreeFont typefaces on the 2.42" SSD1309 OLED with ESP32. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #include <Fonts/FreeSerif9pt7b.h> #include <Fonts/FreeSansBold12pt7b.h> #include <Fonts/FreeMono9pt7b.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(115200); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.display(); } void loop() { // ── Built-in 5×7 font ── display.clearDisplay(); display.setFont(NULL); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 0); display.println(F("Built-in 5x7 font")); display.println(); display.setTextSize(2); display.println(F("DIYables")); display.display(); delay(3000); // ── FreeSerif 9pt ── display.clearDisplay(); display.setFont(&FreeSerif9pt7b); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 14); // Y = baseline display.println(F("FreeSerif 9pt")); display.setCursor(0, 38); display.println(F("DIYables OLED")); display.setCursor(0, 58); display.println(F("Hello World!")); display.display(); delay(3000); // ── FreeSansBold 12pt ── display.clearDisplay(); display.setFont(&FreeSansBold12pt7b); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 20); display.println(F("SansBold")); display.setCursor(0, 52); display.println(F("DIYables")); display.display(); delay(3000); // ── FreeMono 9pt ── display.clearDisplay(); display.setFont(&FreeMono9pt7b); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 14); display.println(F("FreeMono 9pt")); display.setCursor(0, 34); display.println(F("0123456789")); display.setCursor(0, 54); display.println(F("!@#$%^&*()")); display.display(); delay(3000); }

SSD1309 OLED Problemen oplossen met ESP32

Als er niets verschijnt op het 2.42 inch SSD1309 OLED nadat u uw sketch hebt geüpload, doorloop dan de volgende controles:

  • Controleer de bekabeling — bevestig dat SDA, SCL, VCC en GND correct zijn aangesloten op de juiste ESP32-pinnen.
  • Bevestig de driverchip — deze bibliotheek is ontworpen voor de SSD1309. Als uw module een andere controller gebruikt (bijv. SH1106), werkt deze niet correct.
  • Controleer het I2C-adres — de meeste SSD1309 modules gebruiken standaard 0x3C, maar sommigen gebruiken 0x3D. Gebruik de onderstaande I2C scanner sketch om het werkelijke adres te detecteren:
// I2C-adres scanner — toont elk gedetecteerd apparaat in de Serial Monitor #include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); Serial.println("I2C Scanner"); } void loop() { byte error, address; int nDevices = 0; Serial.println("Scanning..."); for (address = 1; address < 127; address++) { Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address < 16) Serial.print("0"); Serial.print(address, HEX); Serial.println(" !"); nDevices++; } else if (error == 4) { Serial.print("Onbekende fout bij adres 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); } } if (nDevices == 0) Serial.println("Geen I2C apparaten gevonden"); else Serial.println("klaar"); delay(5000); }

Verwachte output in Serial Monitor wanneer de SSD1309 wordt gedetecteerd:

COM6
Send
Scanning... I2C device found at address 0x3C ! done
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Zorg dat display() wordt aangeroepen — de SSD1309 gebruikt een framebuffer. Tekentaken wijzigen alleen de buffer in RAM; niets verschijnt op het scherm zolang u oled.display() niet oproept.
  • Controleer de voeding — het 2.42 inch module trekt meer stroom dan kleinere OLED’s. Zorg dat uw voedingsbron voldoende stroom levert (meestal 20–40 mA bij volle helderheid). Bij gebruik van USB-voeding is dit meestal geen probleem met ESP32.
  • Aangepaste I2C-pinnen (optioneel) — als u niet-standaard I2C-pinconfiguraties wilt gebruiken, initialiseer dan Wire met Wire.begin(SDA_PIN, SCL_PIN) vóór het aanroepen van display.begin().

Afsluiting

Deze handleiding heeft alle essentiële aspecten behandeld voor het gebruik van het 2.42-inch SSD1309 OLED display (128×64) met ESP32, inclusief:

  • Hardware connecties en I2C bedrading
  • Tekst en cijfers weergeven in meerdere formaten
  • Vormen tekenen (rechthoeken, cirkels, driehoeken)
  • Bitmap afbeeldingen tonen
  • Hardware scrollen in vier richtingen
  • Contrast- en helderheidsregeling
  • Aangepaste externe lettertypen

De DIYables_OLED_SSD1309 bibliotheek vereenvoudigt SSD1309-programmering met hoog-niveau functies voor tekst, grafiek en schermbesturing, terwijl het Adafruit GFX benut voor uitgebreide tekenmogelijkheden.

Voor meer ESP32 projecten en tutorials, bezoek esp32io.com

※ ONZE BERICHTEN

  • U bent welkom om de link naar deze tutorial te delen. Gebruik onze inhoud echter niet op andere websites. We hebben veel moeite en tijd gestoken in het maken van de inhoud, respecteer alstublieft ons werk!