Eigene Zeichen am LCD-Display
Arduino-Bastelprojekt: Eigene Zeichen und Symbole auf einem LCD-Display anzeigen.
Standard-LCD-Displays (z. B. 20×4 Zeichen) können neben den vordefinierten Zeichen bis zu acht eigene Symbole anzeigen. Jedes Zeichen besteht aus 5×8 Pixeln, die als Byte-Array definiert werden. So lassen sich Logos, kleine Grafiken oder Piktogramme darstellen – in diesem Projekt ein „Veit“-Logo über 80 benutzerdefinierte Zeichen.
Materialien
- Arduino (Uno oder kompatibel)
- I2C LCD-Display (20×4, Adresse typisch 0x27 oder 0x3F)
Pinbelegung
| LCD | Arduino |
|---|---|
| SDA | A4 (Uno/Nano) bzw. SDA |
| SCL | A5 (Uno/Nano) bzw. SCL |
| VCC, GND | 5V, GND |
Funktionsweise
Da nur 8 Zeichen-Slots gleichzeitig nutzbar sind, wird das Bild in Blöcke zu 7 Zeichen aufgeteilt. Für jeden Block wird createChar(0, _char) aufgerufen, das Zeichen an die aktuelle Cursor-Position geschrieben und mit dem nächsten Block fortgefahren. Die Pixel-Daten liegen als Hex-Werte im Array data[] – jedes Byte beschreibt eine Zeile (5 Bit breit, 3 Bit ungenutzt).
#include <Wire.h> // I2C-Library (Display) #include <LiquidCrystal_I2C.h> // LCD-Display-Library LiquidCrystal_I2C lcd(0x3F, 20,4); // I2C adress, Cols, Rows void setup() { lcd.begin(); //Display initialisieren lcd.backlight(); // backlight anlassen writeGraphic(); } void loop() { } void writeGraphic(void){ const uint8_t data[] = { 0x50, 0x70, 0x10, 0x18, 0x90, 0x10, 0xb0, 0xb8, 0x38, 0x10, 0x78, 0x78, 0x99, 0x1b, 0xf8, 0x7c, 0x5c, 0x1c, 0x9c, 0x98, 0x18, 0x1c, 0x18, 0x10, 0x10, 0x10, 0x30, 0x70, 0x9d, 0x1d, 0x1d, 0xff, 0x9d, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1d, 0x1d, 0x1d, 0x9d, 0x9d, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0x9d, 0x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 0x9d, 0x9d, 0x9d, 0xdd, 0x9d, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0x9d, 0x9d, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0x9d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1d, 0xff, 0x1d, 0x1d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0x7f, 0x7f, 0x7f, 0x3f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x1f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0x1f, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x99, 0x58, 0x78, 0x78, 0x78, 0x38, 0x18, 0x38, 0x3c, 0x3c, 0xfc, 0x1c, 0x18, 0xf8, 0xf8, 0xfc, 0x1c, 0xfc, 0x1c, 0x9c, 0x1c, 0x1c, 0xfc, 0xd8, }; uint8_t _char[8], p, i; for(p=0; p<80; p++){ for(i=0;i<7;i++) { _char[i] = data[7*p+i]; } lcd.createChar(0, _char); lcd.setCursor(p%20,floor(p/20)); lcd.print((char)0); delay(100); } /*int chars = 80, p = 0; byte cols = 20, rows=4, n=0, i=0; uint8_t _char[8]; for(p=0;p<chars;){ for(n=0;n<8;n++){ for(i=0;i<7;i++){ _char[i] = data[8*p+i]; } p++; lcd.createChar(n, _char); } lcd.setCursor((p-8)%cols,floor((p-8)/cols)); for(n=0;n<8;n++){ lcd.print((char)n); } }*/ return; }
Weitere Artikel
Gefällt dir die Webseite? Unterstütz die werbefreie Seite mit einer Spende.

Kommentare