Arduino - OLED

Der OLED-Bildschirm (Organische Leuchtdiode) ist eine Alternative zum LCD-Display. Das OLED ist ultraleicht, nahezu papierdünn, flexibel und erzeugt ein helleres und schärferes Bild.

In diesem Tutorial werden wir lernen:

Erforderliche Hardware

1×Arduino Uno R3
1×USB 2.0 Kabel Typ A/B (für USB-A PC)
1×USB 2.0 Kabel Typ C/B (für USB-C PC)
1×SSD1306 I2C OLED-Display 128x64
1×SSD1306 I2C OLED-Display 128x32
1×Verbindungskabel
1×(Empfohlen) Schraubklemmenblock-Shield für Arduino Uno
1×(Empfohlen) Breadboard-Shield für Arduino Uno
1×(Empfohlen) Gehäuse für Arduino Uno
1×(Empfohlen) Prototyping-Grundplatte & Breadboard-Kit für Arduino Uno

Oder Sie können die folgenden Kits kaufen:

1×DIYables STEM V3 Starter-Kit (Arduino enthalten)
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 OLED-Display

Es gibt viele Arten von OLED-Displays. Sie unterscheiden sich voneinander in der Kommunikationsschnittstelle, in den Größen und in den Farben:

  • Kommunikationsschnittstelle: I2C, SPI
  • Größe: 128×64, 128×32...
  • Farbe: weiß, blau, zweifarbig...
Arduino-OLED-Display

SPI ist im Allgemeinen schneller als I2C, erfordert jedoch mehr Arduino-Pins. Während I2C nur zwei Pins benötigt und mit anderen I2C-Peripheriegeräten geteilt werden kann. Es ist ein Kompromiss zwischen Pins und Übertragungsgeschwindigkeit. Die Wahl liegt bei Ihnen. Für OLEDs mit I2C-Schnittstelle gibt es mehrere Treiber, wie SSD1306- und SH1106-Treiber. Dieses Tutorial verwendet das SSD1306 I2C OLED-Display 128x64 und 128x32.

Pinbelegung des I2C-OLED-Displays

  • GND-Pin: sollte mit der Masse des Arduino verbunden werden.
  • VCC-Pin: ist die Stromversorgung für das Display, mit der wir den 5-Volt-Pin am Arduino verbinden.
  • SCL-Pin: ist ein serieller Taktpin für die I2C-Schnittstelle.
  • SDA-Pin: ist ein serieller Datenpin für die I2C-Schnittstelle.
OLED-Pinbelegung

※ Notiz:

  • Die Reihenfolge der Pins des OLED-Moduls kann zwischen Herstellern und Modultypen variieren. VERWENDEN SIE IMMER die auf dem OLED-Modul aufgedruckten Bezeichnungen. Schauen Sie genau hin!
  • Dieses Tutorial verwendet ein OLED-Display, das den SSD1306 I2C-Treiber nutzt. Wir haben es mit dem OLED-Display von DIYables getestet. Es funktioniert ohne Probleme.

Verdrahtungsdiagramm

  • Verdrahtungsdiagramm zwischen Arduino und OLED 128x64
Arduino OLED 128x64 Verdrahtungsschema

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

  • Verdrahtungsdiagramm zwischen Arduino und OLED 128x32
Arduino OLED 128×32 Verdrahtungsdiagramm

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

  • Der echte Schaltplan zwischen Arduino und OLED 128x64
Arduino OLED 128x64 Schaltplan

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

  • Der tatsächliche Schaltplan zwischen Arduino und OLED 128x32
Arduino OLED 128x32 Schaltplan

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

Wenn Sie andere Arduino-Modelle als den Uno verwenden, sind die Pins unterschiedlich. Siehe untenstehende Tabelle für andere Arduino-Modelle.

OLED Module Arduino Uno, Nano Arduino Mega
Vin 5V 5V
GND GND GND
SDA A4 20
SCL A5 21

Wie man OLED mit Arduino verwendet

SSD1306 OLED-Bibliothek installieren

  • Navigieren Sie zum Bibliotheken-Symbol in der linken Leiste der Arduino-IDE.
  • Suchen Sie „SSD1306“, dann finden Sie die SSD1306-Bibliothek von Adafruit
  • Klicken Sie auf die Schaltfläche Installieren, um die Bibliothek zu installieren.
Arduino-OLED-Bibliothek
  • Sie werden aufgefordert, weitere Bibliotheksabhängigkeiten zu installieren.
  • Klicken Sie auf die Install All-Schaltfläche, um alle Bibliotheksabhängigkeiten zu installieren.
Arduino Adafruit GFX Sensorbibliothek

So programmiert man für OLED

  • Bibliothek einbinden
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h>
  • Bestimme die Bildschirmgröße, falls OLED 123×64
#define SCREEN_WIDTH 128 // OLED-Displaybreite, in Pixeln #define SCREEN_HEIGHT 64 // OLED-Displayhöhe, in Pixeln
  • Definiere die Bildschirmgröße, falls es sich um OLED 128×32 handelt
#define SCREEN_WIDTH 128 // OLED-Display-Breite, in Pixeln #define SCREEN_HEIGHT 32 // OLED-Display-Höhe, in Pixeln
  • Deklariere ein SSD1306-OLED-Objekt
// Deklariere ein SSD1306-Display-Objekt, das über I2C verbunden ist Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
  • In der setup()-Funktion das OLED-Display initialisieren
// Initialisiere OLED-Display mit der Adresse 0x3C für 128x64 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); while (true); }
  • Und dann können Sie Text, Bilder anzeigen, eine Linie zeichnen ...

※ Notiz:

Ab diesem Punkt werden alle Codes für OLED 128x64 bereitgestellt, aber Sie können sie leicht auf OLED 128x32 anpassen, indem Sie die Bildschirmgröße ändern und bei Bedarf die Koordinaten anpassen.

Arduino-Code - Text auf OLED anzeigen

/* * Dieser Arduino Code wurde von newbiely.de entwickelt * Dieser Arduino 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/arduino-oled */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // declare an SSD1306 display object connected to I2C Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void setup() { Serial.begin(9600); // initialize OLED display with address 0x3C for 128x64 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); while (true); } delay(2000); // wait for initializing oled.clearDisplay(); // clear display oled.setTextSize(1); // text size oled.setTextColor(WHITE); // text color oled.setCursor(0, 10); // position to display oled.println("Hello World!"); // text to display oled.display(); // show on OLED } void loop() { }

Die unten aufgeführten Funktionen können verwendet werden, um Text auf dem OLED anzuzeigen:

  • oled.clearDisplay(): alle Pixel sind ausgeschaltet
  • oled.drawPixel(x,y, color): zeichnet einen Pixel an den Koordinaten x,y
  • oled.setTextSize(n): Stellt die Schriftgröße ein, unterstützt Größen von 1 bis 8
  • oled.setCursor(x,y): Legt die Koordinaten fest, an denen Text geschrieben wird
  • oled.setTextColor(WHITE): Setzt die Textfarbe
  • oled.setTextColor(BLACK, WHITE): Setzt die Textfarbe, Hintergrundfarbe
  • oled.println(“Nachricht”): Druckt die Zeichen aus
  • oled.println(number): Druckt eine Zahl aus
  • oled.println(number, HEX): Druckt eine Zahl im HEX-Format aus
  • oled.display(): Rufen Sie diese Methode auf, damit die Änderungen wirksam werden
  • oled.startscrollright(start, stop): Scrollt Text von links nach rechts
  • oled.startscrollleft(start, stop): Scrollt Text von rechts nach links
  • oled.startscrolldiagright(start, stop): Scrollt Text von der linken unteren Ecke zur rechten oberen Ecke
  • oled.startscrolldiagleft(start, stop): Scrollt Text von der rechten unteren Ecke zur linken oberen Ecke
  • oled.stopscroll(): Stoppt das Scrollen

Wie man Text/Zahl vertikal und horizontal auf einem OLED-Display zentriert

Siehe Wie man Text vertikal und horizontal auf dem OLED zentriert

Arduino-Code – Zeichnen auf dem OLED-Display

/* * Dieser Arduino Code wurde von newbiely.de entwickelt * Dieser Arduino 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/arduino-oled */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // declare an SSD1306 display object connected to I2C Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void setup() { Serial.begin(9600); // initialize OLED display with address 0x3C for 128x64 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); while (true); } delay(2000); // wait for initializing oled.setCursor(0, 0); } void loop() { // draw rectangle oled.clearDisplay(); oled.drawRect(0, 15, 60, 40, WHITE); oled.display(); delay(2000); // fill rectangle oled.clearDisplay(); oled.fillRect(0, 15, 60, 40, WHITE); oled.display(); delay(2000); // draw the round rectangle oled.clearDisplay(); oled.drawRoundRect(0, 15, 60, 40, 8, WHITE); oled.display(); delay(2000); // fill the round rectangle oled.clearDisplay(); oled.fillRoundRect(0, 15, 60, 40, 8, WHITE); oled.display(); delay(2000); // draw circle oled.clearDisplay(); oled.drawCircle(20, 35, 20, WHITE); oled.display(); delay(2000); // fill circle oled.clearDisplay(); oled.fillCircle(20, 35, 20, WHITE); oled.display(); delay(2000); // draw triangle oled.clearDisplay(); oled.drawTriangle(30, 15, 0, 60, 60, 60, WHITE); oled.display(); delay(2000); // fill triangle oled.clearDisplay(); oled.fillTriangle(30, 15, 0, 60, 60, 60, WHITE); oled.display(); delay(2000); }

Arduino-Code – Bild anzeigen

Um ein Bild auf dem OLED-Display darzustellen, müssen wir das Bild (in jedem Format) zuerst in ein Bitmap-Array konvertieren. Die Umwandlung kann mit diesem Online-Tool durchgeführt werden: https://javl.github.io/image2cpp/. Bitte sehen Sie sich im unten gezeigten Bild an, wie man ein Bild in ein Bitmap-Array konvertiert. Ich habe das Arduino-Symbol in ein Bitmap-Array konvertiert.

Bild in Bitmap-Array

Nach der Konvertierung kopieren Sie den Array-Code und aktualisieren Sie ihn im ArduinoIcon-Array im untenstehenden Code.

/* * Dieser Arduino Code wurde von newbiely.de entwickelt * Dieser Arduino 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/arduino-oled */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // declare an SSD1306 display object connected to I2C Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // bitmap of arduino-icon image const unsigned char ArduinoIcon [] PROGMEM = { // 'arduino-icon', 128x64px 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x0f, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x7f, 0xf0, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x1f, 0xe0, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x00, 0x7f, 0xf0, 0x00, 0x7f, 0xff, 0xff, 0xe0, 0x00, 0x0f, 0xc0, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x07, 0x80, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x03, 0x80, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x1f, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x07, 0xff, 0xf0, 0x7f, 0xff, 0x00, 0x0f, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x0f, 0x80, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x1f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x07, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x7f, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x01, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x7f, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x07, 0x80, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x1f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x07, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x80, 0x0f, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0xe0, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x1f, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x07, 0x80, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xe0, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x00, 0x0f, 0xc0, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xe0, 0x00, 0x1f, 0xe0, 0x00, 0x1f, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xf8, 0x00, 0x1f, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xe0, 0x00, 0x07, 0xff, 0xff, 0xe0, 0x00, 0x7f, 0xf8, 0x00, 0x0f, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x7f, 0xfc, 0x00, 0x03, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; void setup() { Serial.begin(9600); // initialize OLED display with address 0x3C for 128x64 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); while (true); } delay(2000); // wait for initializing oled.setCursor(0, 0); } void loop() { oled.clearDisplay(); // display bitmap oled.drawBitmap(0, 0, ArduinoIcon, 128, 64, WHITE); oled.display(); delay(2000); // invert display oled.invertDisplay(1); delay(2000); }

※ Notiz:

  • Die Bildgröße sollte kleiner oder gleich der Bildschirmgröße sein.
  • Wenn Sie den obigen Code für OLED-Auflösung 128×32 anpassen möchten, müssen Sie das Bild neu skalieren und Breite und Höhe in der Funktion oled.drawBitmap(); ändern.

OLED-Fehlerbehebung

Wenn das OLED nichts anzeigt, führen Sie bitte die folgende Checkliste durch:

  • Stellen Sie sicher, dass Ihre Verkabelung korrekt ist.
  • Stellen Sie sicher, dass Ihr I2C-OLED den SSD1306-Treiber verwendet.
  • Überprüfen Sie die I2C-Adresse des OLEDs, indem Sie den untenstehenden I2C-Adressen-Scanner-Code auf dem Arduino ausführen.
// I2C-Adressen-Scanner-Programm #include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); Serial.println("I2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; 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); // Warte 5 Sekunden auf den nächsten Scan }

Das Ergebnis auf dem seriellen Monitor:

COM6
Send
Scanning... I2C device found at address 0x3C ! done Scanning... I2C device found at address 0x3C ! done
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ 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!