Der Code basiert auf einem UNO R3 ATmega328p Board und der C++-Sprache unter Verwendung der Arduino IDE App. Benötigte Bibliotheken: - Adafruit GFX Library (von Adafruit) - Adafruit PCD8544 Library (von Adafruit) Code: /* * Nokia 5110 LCD Display Modul 84x48 – Blaues Backlight * Board: Arduino UNO R3 (ATmega328p) * * Pinbelegung: * - VCC -> 3.3V (Wichtig! Nicht 5V verwenden!) * - GND -> GND * - SCE -> Pin 7 (Chip Enable) * - RST -> Pin 6 (Reset) * - D/C -> Pin 5 (Data/Command) * - MOSI -> Pin 4 (Master Out Slave In) * - SCK -> Pin 3 (Serial Clock) * - LED -> Pin 2 (Backlight – optional, über PWM dimmbar) * * Hinweis: Das Display benötigt 3.3V Logikpegel! * Bei 5V kann das Display beschädigt werden. * Verwende einen Spannungsteiler oder Pegelwandler für die Datenleitungen. */ #include #include // Pins für das Nokia 5110 Display #define SCE_PIN 7 #define RST_PIN 6 #define D_C_PIN 5 #define MOSI_PIN 4 #define SCK_PIN 3 #define LED_PIN 2 // Backlight // Display-Objekt erstellen Adafruit_PCD8544 display = Adafruit_PCD8544(SCK_PIN, MOSI_PIN, D_C_PIN, RST_PIN, SCE_PIN); void setup() { // Serielle Kommunikation starten Serial.begin(9600); // Backlight-Pin als Ausgang pinMode(LED_PIN, OUTPUT); // Display initialisieren display.begin(); // Kontrast einstellen (0-127, typisch 40-60) display.setContrast(50); // Display löschen display.clearDisplay(); // Textgröße und -farbe einstellen display.setTextSize(1); display.setTextColor(BLACK); // Begrüßungstext anzeigen display.setCursor(10, 10); display.println("Nokia 5110"); display.setCursor(5, 25); display.println("Test Display"); display.setCursor(15, 40); display.println("v1.0"); display.display(); Serial.println("Nokia 5110 Display initialisiert"); Serial.println("-----------------------------------"); // Backlight einschalten analogWrite(LED_PIN, 255); // Volle Helligkeit delay(2000); } void loop() { // Display löschen display.clearDisplay(); // 1. Text anzeigen (groß) display.setTextSize(2); display.setTextColor(BLACK); display.setCursor(0, 0); display.println("Hallo!"); display.setTextSize(1); display.setCursor(0, 25); display.println("Arduino UNO R3"); display.setCursor(0, 35); display.println("Nokia 5110 Test"); display.display(); delay(2000); // 2. Rechteck zeichnen display.clearDisplay(); display.drawRect(10, 5, 64, 38, BLACK); display.setCursor(18, 18); display.setTextSize(1); display.println("Rechteck"); display.display(); delay(2000); // 3. Kreis zeichnen display.clearDisplay(); display.drawCircle(42, 24, 20, BLACK); display.setCursor(28, 18); display.setTextSize(1); display.println("Kreis"); display.display(); delay(2000); // 4. Dreieck zeichnen display.clearDisplay(); display.drawTriangle(42, 5, 15, 40, 69, 40, BLACK); display.setCursor(30, 30); display.setTextSize(1); display.println("Dreieck"); display.display(); delay(2000); // 5. Bitmap (einfacher Smiley) display.clearDisplay(); // Smiley-Bitmap (14x14 Pixel) static const unsigned char PROGMEM smiley[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; display.drawBitmap(35, 15, smiley, 14, 14, BLACK); display.display(); delay(2000); // 6. Backlight dimmen (PWM) for (int helligkeit = 255; helligkeit >= 0; helligkeit -= 5) { analogWrite(LED_PIN, helligkeit); delay(20); } for (int helligkeit = 0; helligkeit <= 255; helligkeit += 5) { analogWrite(LED_PIN, helligkeit); delay(20); } // 7. Text scrollen display.clearDisplay(); display.setTextSize(1); display.setCursor(0, 20); String scrollText = "Nokia 5110 Display Test mit Arduino UNO R3 "; for (int i = 0; i < scrollText.length() * 6; i++) { display.clearDisplay(); display.setCursor(-i + 84, 20); display.print(scrollText); display.display(); delay(80); } delay(1000); // 8. Ränder anzeigen display.clearDisplay(); display.drawRect(0, 0, 84, 48, BLACK); display.setCursor(10, 20); display.setTextSize(1); display.println("Display Rand"); display.display(); delay(3000); }