Arduino Nano - SSD1309 OLED Display 128x64 | 2,42 Zoll I2C OLED Tutorial

Ein OLED (Organic Light-Emitting Diode) Display bietet selbstleuchtende Pixel, die tiefe Schwarztöne, hohen Kontrast und weite Betrachtungswinkel liefern — was es zu einem großartigen Upgrade gegenüber herkömmlichen LCDs macht. Der SSD1309 ist der Treiber-IC, der häufig auf 2,42-Zoll (manchmal als 2,4-Zoll bezeichnet) 128×64 I2C OLED Modulen zu finden ist.

In diesem Schritt-für-Schritt Leitfaden lernen Sie, wie Sie das SSD1309 OLED 128×64 mit einem Arduino Nano Board über die DIYables_OLED_SSD1309 Bibliothek verbinden und programmieren. Konkret behandeln wir:

Benötigte Hardware

1×Official Arduino Nano
1×Alternativ: DIYables ATMEGA328P Nano Development Board
1×USB A auf Mini-B USB Kabel
1×SSD1309 I2C OLED Display 128x64 (2,42 Zoll)
1×Jumper Kabel
1×(Empfohlen) Schraubklemmen-Erweiterungsboard für Arduino Nano
1×(Empfohlen) Breakout-Erweiterungsboard für Arduino Nano
1×(Empfohlen) Stromverteiler für Arduino Nano

Oder Sie können die folgenden Kits kaufen:

1×DIYables Sensor-Kit (30 Sensoren/Displays)
1×DIYables Sensor-Kit (18 Sensoren/Displays)
Offenlegung: Einige der in diesem Abschnitt bereitgestellten Links sind Amazon-Affiliate-Links. Wir können eine Provision für Käufe erhalten, die über diese Links getätigt werden, ohne zusätzliche Kosten für Sie. Wir schätzen Ihre Unterstützung.

Über das SSD1309 2,42-Zoll OLED Display

Der SSD1309 ist ein Single-Chip CMOS OLED Treiber-IC, der für 128×64 Punkt-Matrix-Panels entwickelt wurde. Er ist registerkompatibel mit dem weit verbreiteten SSD1306, sodass viele bestehende Code-Beispiele mit minimalen Änderungen übertragbar sind. Die wichtigsten Hardware-Unterschiede sind:

  • Keine eingebaute Ladungspumpe — der SSD1309 benötigt eine externe VCC-Versorgung, obwohl praktisch alle Breakout-Boards (einschließlich 2,42-Zoll und 2,4-Zoll Module) mit einem integrierten Boost-Konverter geliefert werden, sodass dies für Sie transparent ist.
  • Höhere Spannungstoleranz — der SSD1309 akzeptiert bis zu 16 V VCC, während der SSD1306 auf etwa 4,2 V begrenzt ist.

Das 2,42 Zoll (2,4 Zoll) OLED Modul verwendet üblicherweise den SSD1309 Treiber und verfügt über eine 128×64 Pixel Auflösung mit I2C Schnittstelle. Die Panel-Farbe (weiß, blau, gelb, grün oder zweifarbig) wird durch das physische OLED-Material bestimmt und ist nicht softwaresteuerbar.

Dieses Tutorial kommuniziert mit dem Display über den I2C Bus, der nur zwei Signalleitungen (SDA und SCL) benötigt und den Bus mit anderen I2C Peripheriegeräten teilen kann.

SSD1309 OLED Pinout (I2C Modul)

  • GND Pin: Dieser sollte mit der Masse des Arduino Nano verbunden werden.
  • VCC Pin: Dies ist die Stromversorgung für das Display, die mit 5V verbunden werden sollte.
  • SCL Pin: Dies ist ein serieller Taktpin für die I2C Schnittstelle. Mit A5 verbinden.
  • SDA Pin: Dies ist ein serieller Datenpin für die I2C Schnittstelle. Mit A4 verbinden.
SSD1309 OLED Pinout

※ Notiz:

  • Die Pins des OLED Moduls können je nach Hersteller und Typ unterschiedlich sein. Bitte verwenden Sie die auf dem OLED Modul aufgedruckten Bezeichnungen. Bitte schauen Sie genau hin!
  • Dieses Tutorial verwendet das OLED Display, das vom SSD1309 I2C Treiber angesteuert wird. Wir haben es mit dem OLED Display von DIYables getestet und es funktioniert einwandfrei.

Schaltplan

  • Schaltplan zwischen Arduino Nano und SSD1309 OLED 128x64
Arduino Nano SSD1309 OLED Schaltplan

Dieses Bild wurde mit Fritzing erstellt. Klicken Sie, um das Bild zu vergrößern.

Siehe Der beste Weg, den Arduino Nano und andere Komponenten mit Strom zu versorgen.

Die Verkabelungstabelle zwischen Arduino Nano und SSD1309 OLED Display:

OLED Modul Arduino Nano
VCC 5V
GND GND
SDA A4
SCL A5

Arduino Nano für SSD1309 OLED programmieren

Die DIYables_OLED_SSD1309 Bibliothek installieren

Die DIYables_OLED_SSD1309 Bibliothek ist speziell für SSD1309 Displays entwickelt und erweitert Adafruit_GFX für erweiterte Grafikunterstützung.

  • Klicken Sie auf das Libraries Symbol in der linken Leiste der Arduino IDE.
  • Suchen Sie nach DIYables_OLED_SSD1309 und suchen Sie dann die DIYables OLED SSD1309 Bibliothek von DIYables
  • Klicken Sie auf Install um die DIYables_OLED_SSD1309 Bibliothek zu installieren.
Arduino Nano SSD1309 OLED Bibliothek
  • Sie werden aufgefordert, Abhängigkeiten für die Bibliothek zu installieren
  • Installieren Sie alle Abhängigkeiten, indem Sie auf Install All klicken.
Arduino Nano Adafruit GFX Bibliothek

Programmierungsschritte

  1. Die erforderlichen Bibliotheken einbinden
#include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h>
  1. Die Bildschirmabmessungen definieren
#define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64
  1. Das Display-Objekt deklarieren
#define OLED_RESET -1 // Reset Pin wird bei den meisten I2C Modulen nicht verwendet #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  1. Das OLED in setup() initialisieren
if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 Allokation fehlgeschlagen")); for (;;); // anhalten }
  1. Inhalt anzeigen
display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 20); display.println(F("Hallo Nano")); display.display(); // Puffer auf Bildschirm übertragen

Arduino Nano Code — Hello World auf SSD1309 OLED

Der einfachste Ausgangspunkt: einige Textzeilen in verschiedenen Größen ausgeben.

/* * Dieser Arduino Nano Code wurde von newbiely.de entwickelt * Dieser Arduino Nano Code wird der Öffentlichkeit ohne jegliche Einschränkung zur Verfügung gestellt. * Für vollständige Anleitungen und Schaltpläne besuchen Sie bitte: * https://newbiely.de/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Hello World * Prints text in two sizes on the 2.42 inch 128x64 I2C OLED with Arduino Nano. */ #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(9600); 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() { }

Arduino Nano Code — Text auf SSD1309 OLED anzeigen

Das folgende Beispiel demonstriert erweiterte Textfunktionen — mehrere Größen, Zahlenformatierung und das F() Makro zur RAM-Einsparung.

/* * Dieser Arduino Nano Code wurde von newbiely.de entwickelt * Dieser Arduino Nano Code wird der Öffentlichkeit ohne jegliche Einschränkung zur Verfügung gestellt. * Für vollständige Anleitungen und Schaltpläne besuchen Sie bitte: * https://newbiely.de/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Display Text * Displays text in various sizes and formats on the 2.42" SSD1309 OLED with Arduino Nano. */ #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(9600); 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() { }

Nützliche Display-Funktionen Referenz

Unten finden Sie eine Kurzreferenz der am häufigsten verwendeten Funktionen bei der Arbeit mit dem SSD1309 OLED über die DIYables Bibliothek:

  • oled.clearDisplay() — löscht den Framepuffer (alle Pixel aus).
  • oled.display() — überträgt den Puffer auf das OLED, damit Änderungen sichtbar werden.
  • oled.drawPixel(x, y, color) — setzt oder löscht einen einzelnen Pixel.
  • oled.setTextSize(n) — skaliert die Schrift um Faktor *n* (1 = 6×8, 2 = 12×16, …, bis zu 8).
  • oled.setCursor(x, y) — bewegt den Textcursor zu den Pixelkoordinaten *(x, y)*.
  • oled.setTextColor(SSD1309_PIXEL_ON) — nur Text-Vordergrund (Hintergrund ist transparent).
  • oled.setTextColor(SSD1309_PIXEL_OFF, SSD1309_PIXEL_ON) — Text mit expliziter Hintergrundfarbe.
  • oled.println("nachricht") — gibt einen String aus und geht zur nächsten Zeile.
  • oled.println(number) — gibt eine Ganzzahl dezimal aus.
  • oled.println(number, HEX) — gibt eine Ganzzahl hexadezimal aus.
  • oled.startscrollright(start, stop) — Hardware-Scroll nach rechts zwischen Seite *start* und Seite *stop*.
  • oled.startscrollleft(start, stop) — Hardware-Scroll nach links.
  • oled.startscrolldiagright(start, stop) — Hardware-Scroll diagonal nach rechts.
  • oled.startscrolldiagleft(start, stop) — Hardware-Scroll diagonal nach links.
  • oled.stopscroll() — stoppt jeden aktiven Hardware-Scroll.
  • oled.setContrast(value) — passt die Display-Helligkeit an (0–255).
  • oled.dim(true/false) — dimmt das Display schnell auf Minimum oder stellt den vorherigen Kontrast wieder her.
  • oled.invertDisplay(true/false) — Hardware-Level Farbinversion (an-Pixel ↔ aus-Pixel).

Text vertikal und horizontal auf dem SSD1309 OLED zentrieren

Siehe Wie man auf OLED vertikal/horizontal zentriert

Arduino Nano Code — Formen auf SSD1309 OLED zeichnen

Da die DIYables_OLED_SSD1309 Bibliothek Adafruit_GFX erweitert, erhalten Sie einen vollständigen Satz von Form-Zeichen-Primitiven: Pixel, Linien, Rechtecke, gefüllte Rechtecke, Kreise, gefüllte Kreise, Dreiecke, gefüllte Dreiecke und abgerundete Rechtecke. Der folgende Sketch durchläuft alle mit animierten Demos.

/* * Dieser Arduino Nano Code wurde von newbiely.de entwickelt * Dieser Arduino Nano Code wird der Öffentlichkeit ohne jegliche Einschränkung zur Verfügung gestellt. * Für vollständige Anleitungen und Schaltpläne besuchen Sie bitte: * https://newbiely.de/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Draw Shapes * Demonstrates drawing pixels, lines, rectangles, circles, and triangles on the 2.42" OLED with Arduino Nano. */ #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(9600); 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); }

Arduino Nano Code — Hardware Scrolling auf SSD1309 OLED

Der SSD1309 verfügt über eine eingebaute Scrolling-Engine, die den Display-Inhalt ohne CPU-Last verschiebt. Die DIYables Bibliothek stellt vier Scroll-Richtungen zur Verfügung: rechts, links, diagonal-rechts und diagonal-links. Jede nimmt einen Start-Seiten- und Stop-Seiten-Parameter (Seiten sind 8-Pixel-hohe horizontale Streifen nummeriert 0–7 auf einem 64-Pixel-hohen Display).

※ Notiz:

Rufen Sie immer display() auf, um Ihren Inhalt auf das OLED zu übertragen, bevor Sie einen Scroll starten. Vermeiden Sie es, neue Inhalte zu zeichnen, während das Scrolling aktiv ist — rufen Sie zuerst stopscroll() auf.

/* * Dieser Arduino Nano Code wurde von newbiely.de entwickelt * Dieser Arduino Nano Code wird der Öffentlichkeit ohne jegliche Einschränkung zur Verfügung gestellt. * Für vollständige Anleitungen und Schaltpläne besuchen Sie bitte: * https://newbiely.de/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Scroll Text * Demonstrates all four hardware scroll directions on the 2.42" OLED with Arduino Nano. */ #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(9600); 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); }

Arduino Nano Code — Bitmap-Bild auf SSD1309 OLED anzeigen

Um ein Bitmap auf dem SSD1309 OLED anzuzeigen, müssen Sie zuerst Ihr Bild in ein C Byte-Array konvertieren. Verwenden Sie das kostenlose image2cpp Online-Tool für diese Konvertierung:

  1. Laden Sie Ihre Bilddatei hoch (PNG, JPG, BMP, etc.).
  2. Setzen Sie die Canvas-Größe auf 128×64 (oder kleiner).
  3. Wählen Sie Arduino code als Ausgabeformat.
  4. Kopieren Sie das generierte Array in Ihren Sketch.
Bild zu Bitmap Array

Das folgende Beispiel wechselt zwischen einem 16×16 Herz-Symbol und einem vollbreiten DIYables Logo:

/* * Dieser Arduino Nano Code wurde von newbiely.de entwickelt * Dieser Arduino Nano Code wird der Öffentlichkeit ohne jegliche Einschränkung zur Verfügung gestellt. * Für vollständige Anleitungen und Schaltpläne besuchen Sie bitte: * https://newbiely.de/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Display Bitmap Image * Shows a 16x16 heart icon and 128x64 DIYables logo on the 2.42" OLED with Arduino Nano. */ #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, 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e0, 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(9600); 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:

  • Die Bitmap-Abmessungen dürfen die Bildschirmauflösung nicht überschreiten (128×64 für das 2,42 Zoll Modul).

Arduino Nano Code — Kontrast und Dimmen auf SSD1309 OLED

Der SSD1309 unterstützt 256 Kontraststufen (0–255). Die DIYables Bibliothek bietet setContrast() für feinabgestimmte Kontrolle und dim() für einen schnellen Wechsel zwischen minimaler Helligkeit und dem zuvor konfigurierten Level.

/* * Dieser Arduino Nano Code wurde von newbiely.de entwickelt * Dieser Arduino Nano Code wird der Öffentlichkeit ohne jegliche Einschränkung zur Verfügung gestellt. * Für vollständige Anleitungen und Schaltpläne besuchen Sie bitte: * https://newbiely.de/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Contrast & Dim * Sweeps contrast from 0→255→0 then toggles dim mode on the 2.42" OLED with Arduino Nano. */ #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(9600); 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); }

Arduino Nano Code — Benutzerdefinierte externe Schriftarten auf SSD1309 OLED

Die Adafruit GFX Bibliothek wird mit Dutzenden skalierbarer FreeFont Schriftarten geliefert (Serif, Sans, Mono — jeweils in Regular, Bold, Italic und vier Größen). Sie können jede davon auf dem SSD1309 Display aktivieren, indem Sie den entsprechenden Header einbinden und setFont() aufrufen.

※ Notiz:

  • Wenn eine externe Schriftart aktiv ist, bezieht sich die Cursor Y-Koordinate auf die Text-Grundlinie, nicht auf die obere linke Ecke. Dies unterscheidet sich von der eingebauten 5×7 Schrift.
  • Externe Schriftarten werden im Flash (PROGMEM) gespeichert. Auf speicherlimitierten AVR Boards (Arduino Nano = 32 KB Flash) verwenden Sie sie sparsam.
/* * Dieser Arduino Nano Code wurde von newbiely.de entwickelt * Dieser Arduino Nano Code wird der Öffentlichkeit ohne jegliche Einschränkung zur Verfügung gestellt. * Für vollständige Anleitungen und Schaltpläne besuchen Sie bitte: * https://newbiely.de/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – External Fonts * Cycles through three FreeFont typefaces on the 2.42" SSD1309 OLED with Arduino Nano. */ #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(9600); 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 Fehlerbehebung mit Arduino Nano

Wenn nach dem Hochladen Ihres Sketches nichts auf dem 2,42 Zoll SSD1309 OLED erscheint, arbeiten Sie diese Überprüfungen durch:

  • Verkabelung überprüfen — bestätigen Sie, dass SDA, SCL, VCC und GND mit den korrekten Arduino Nano Pins verbunden sind.
  • Treiber-Chip bestätigen — diese Bibliothek ist für den SSD1309 entwickelt. Wenn Ihr Modul einen anderen Controller verwendet (z.B. SH1106), wird es nicht korrekt reagieren.
  • I2C Adresse überprüfen — die meisten SSD1309 Module verwenden standardmäßig 0x3C, aber einige verwenden 0x3D. Führen Sie den I2C Scanner Sketch unten aus, um die tatsächliche Adresse zu erkennen:
// I2C Adress-Scanner — gibt jedes erkannte Gerät auf dem Serial Monitor aus #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("Unknown error at address 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); } } if (nDevices == 0) Serial.println("No I2C devices found"); else Serial.println("done"); delay(5000); }

Erwartete Serial Monitor Ausgabe wenn der SSD1309 erkannt wird:

COM6
Send
Scanning... I2C device found at address 0x3C ! done
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Sicherstellen, dass display() aufgerufen wird — der SSD1309 verwendet einen Framepuffer. Zeichenfunktionen modifizieren nur den Puffer im RAM; nichts erscheint auf dem Bildschirm, bis Sie oled.display() aufrufen.
  • Stromversorgung überprüfen — das 2,42 Zoll Modul zieht mehr Strom als kleinere OLEDs. Stellen Sie sicher, dass Ihre Stromquelle ausreichend Strom liefern kann (typischerweise 20–40 mA bei voller Helligkeit).

Video Tutorial

Zusammenfassung

Dieser Leitfaden hat alle wesentlichen Punkte für die Verwendung des 2,42-Zoll SSD1309 OLED Displays (128×64) mit Arduino Nano abgedeckt, einschließlich:

  • Hardware-Verbindungen und I2C Verkabelung
  • Text- und Zahlenanzeige mit mehreren Größen
  • Formen zeichnen (Rechtecke, Kreise, Dreiecke)
  • Bitmap-Bilder rendern
  • Hardware-Scrolling in vier Richtungen
  • Kontrast- und Helligkeitskontrolle
  • Benutzerdefinierte externe Schriftarten

Die DIYables_OLED_SSD1309 Bibliothek vereinfacht die SSD1309 Programmierung, indem sie hochrangige Funktionen für Text, Grafiken und Display-Kontrolle bereitstellt, während sie Adafruit GFX für erweiterte Zeichenmöglichkeiten nutzt.

Für weitere Arduino Nano Projekte und Tutorials besuchen Sie arduinogetstarted.com

※ UNSERE NACHRICHTEN

  • Sie können gerne den Link zu diesem Tutorial teilen. Bitte verwenden Sie jedoch unsere Inhalte nicht auf anderen Websites. Wir haben viel Mühe und Zeit in die Erstellung der Inhalte investiert, bitte respektieren Sie unsere Arbeit!