Einfachstes OLED Programm - was geht nicht?

Hallo,
ich wollte einen mit meinem Display funtionierenden Demo-Sketch auf das Wesentliche zusammenschrumpfen, nur um die Funktion des Displays kennen zu lernen, doch das Display bleibt nun schwarz.
Kann mir jemand helfen, was an dem Mini-Sketch nicht stimmt?

#include "SH1106Wire.h"  

SH1106Wire display(0x3c, SDA, SCL);     // ADDRESS, SDA, SCL


void setup() {
  
  display.init();
  display.setFont(ArialMT_Plain_10);

}

void drawFontFaceDemo() {
    // Font Demo1
    // create more fonts at http://oleddisplay.squix.ch/
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.setFont(ArialMT_Plain_10);
    display.drawString(0, 0, "Hello world");
    display.setFont(ArialMT_Plain_16);
    display.drawString(0, 10, "Hello world");
    display.setFont(ArialMT_Plain_24);
    display.drawString(0, 26, "Hello world");
}


void loop() {
  // clear the display
  display.clear();
  
drawFontFaceDemo;
  
delay (10);
}

#include <Wire.h> vergessen?
[edit]
hmm... wird wohl nur bei der IDE 1.6.5 und früher benötigt :frowning:
[/edit]

wie sah denn der Beispielsketch aus, den du abgewandelt hast?

arduling:
Kann mir jemand helfen, was an dem Mini-Sketch nicht stimmt?

Ich nicht, da ich die von Dir verwendete Bibliothek und Deine Hardware nicht kenne.

Ich habe gute Erfahrungen mit U8g2 von Oli Kraus gemacht, allerdings verwende ich SSD1306 an UNO oder ESP32.

Dies "drawFontFaceDemo;" sollte so

drawFontFaceDemo();

aussehen.

Normal müsstest du Fehler beim compilieren sehen.

HotSystems:
Dies "drawFontFaceDemo;" sollte so

drawFontFaceDemo();

aussehen.

Normal müsstest du Fehler beim compilieren sehen.

() Habe ich geändert, leider keine Besserung.
Beim compilieren gibt es keine Fehlermeldung.
Könnte man eigentlich auch die Anweisungen

display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.setFont(ArialMT_Plain_10);
    display.drawString(0, 0, "Hello world");
    display.setFont(ArialMT_Plain_16);
    display.drawString(0, 10, "Hello world");
    display.setFont(ArialMT_Plain_24);
    display.drawString(0, 26, "Hello world");

direkt in void loop packen oder muss das über vorheriges Definieren einer Funktion (name drawFontFaceDemo()) gemacht werden?

arduling:
() Habe ich geändert, leider keine Besserung.
Beim compilieren gibt es keine Fehlermeldung.
Könnte man eigentlich auch die Anweisungen

Du solltest doch den kompletten Beispiel-Sketch posten.

Und ja, könnte man machen, wird dann aber unübersichtlicher.

Und immer auch den geänderten Sketch posten, dann sehen wir auch deine neuen Fehler.

o.k., hier ist der originale sketch, der funktioniert:

// Include the correct display library

// For a connection via I2C using the Arduino Wire include:
#include <Wire.h>               // Only needed for Arduino 1.6.5 and earlier
#include "SH1106Wire.h"   // legacy: #include "SH1106.h"

// Optionally include custom images
#include "images.h"


// Initialize the OLED display using Arduino Wire:
   SH1106Wire display(0x3c, SDA, SCL);     // ADDRESS, SDA, SCL

#define DEMO_DURATION 3000
typedef void (*Demo)(void);

int demoMode = 0;
int counter = 1;

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println();


  // Initialising the UI will init the display too.
  display.init();

  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_10);

}

void drawFontFaceDemo() {
    // Font Demo1
    // create more fonts at http://oleddisplay.squix.ch/
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.setFont(ArialMT_Plain_10);
    display.drawString(0, 0, "Hello world");
    display.setFont(ArialMT_Plain_16);
    display.drawString(0, 10, "Hello world");
    display.setFont(ArialMT_Plain_24);
    display.drawString(0, 26, "Hello world");
}

void drawTextFlowDemo() {
    display.setFont(ArialMT_Plain_10);
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.drawStringMaxWidth(0, 0, 128,
      "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );
}

void drawTextAlignmentDemo() {
    // Text alignment demo
  display.setFont(ArialMT_Plain_10);

  // The coordinates define the left starting point of the text
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(0, 10, "Left aligned (0,10)");

  // The coordinates define the center of the text
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.drawString(64, 22, "Center aligned (64,22)");

  // The coordinates define the right end of the text
  display.setTextAlignment(TEXT_ALIGN_RIGHT);
  display.drawString(128, 33, "Right aligned (128,33)");
}

void drawRectDemo() {
      // Draw a pixel at given position
    for (int i = 0; i < 10; i++) {
      display.setPixel(i, i);
      display.setPixel(10 - i, i);
    }
    display.drawRect(12, 12, 20, 20);

    // Fill the rectangle
    display.fillRect(14, 14, 17, 17);

    // Draw a line horizontally
    display.drawHorizontalLine(0, 40, 20);

    // Draw a line horizontally
    display.drawVerticalLine(40, 0, 20);
}

void drawCircleDemo() {
  for (int i=1; i < 8; i++) {
    display.setColor(WHITE);
    display.drawCircle(32, 32, i*3);
    if (i % 2 == 0) {
      display.setColor(BLACK);
    }
    display.fillCircle(96, 32, 32 - i* 3);
  }
}

void drawProgressBarDemo() {
  int progress = (counter / 5) % 100;
  // draw the progress bar
  display.drawProgressBar(0, 32, 120, 10, progress);

  // draw the percentage as String
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.drawString(64, 15, String(progress) + "%");
}

void drawImageDemo() {
    // see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
    // on how to create xbm files
    display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
}

Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo};
int demoLength = (sizeof(demos) / sizeof(Demo));
long timeSinceLastModeSwitch = 0;

void loop() {
  // clear the display
  display.clear();
  // draw the current demo method
  demos[demoMode]();

  display.setTextAlignment(TEXT_ALIGN_RIGHT);
  display.drawString(10, 128, String(millis()));
  // write the buffer to the display
  display.display();

  if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) {
    demoMode = (demoMode + 1)  % demoLength;
    timeSinceLastModeSwitch = millis();
  }
  counter++;
  delay(10);
}

und eben so hab ich das eingedampft, in der Hoffnung dass ich rausbekomme, wie ich ganz normal das Display ansprechen kann:

#include "SH1106Wire.h"  

SH1106Wire display(0x3c, SDA, SCL);     // ADDRESS, SDA, SCL


void setup() {
  
  display.init();
  display.setFont(ArialMT_Plain_10);

}

void drawFontFaceDemo() {
    // Font Demo1
    // create more fonts at http://oleddisplay.squix.ch/
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.setFont(ArialMT_Plain_10);
    display.drawString(0, 0, "Hello world");
    display.setFont(ArialMT_Plain_16);
    display.drawString(0, 10, "Hello world");
    display.setFont(ArialMT_Plain_24);
    display.drawString(0, 26, "Hello world");
}


void loop() {
  // clear the display
  display.clear();
  
drawFontFaceDemo();
  
delay (10);
}

Ein Teil wurde dir doch schon in Post #1 genannt.

Edit:
Das mit der wire.h kann ich aktuell nicht verstehen.

Nimm den originalen Sketch und rufe darin die Funktion auf, die du nutzen möchtest.
Wenn es funktioniert dann kommentierst (//) du die Teile nacheinander raus, die du nicht brauchst.

display.display() fehlt, bis dahin malst du nur im RAM-Abbild rum. Und der Lib-Header fängt wahrscheinlich mit#include <Wire.h> an, daher kann man sich das im Programm sparen, genauso wie bei SD SPI.

arduling:
() Habe ich geändert, leider keine Besserung.
Beim compilieren gibt es keine Fehlermeldung.

Das it auch erst mal kein Compiler Fehler. Aber es kommt eine Warnung wenn man die aktiviert (was man unbedingt tun sollte)

HTML-Fan:
display.display() fehlt, bis dahin malst du nur im RAM-Abbild rum. Und der Lib-Header fängt wahrscheinlich mit#include <Wire.h> an, daher kann man sich das im Programm sparen, genauso wie bei SD SPI.

Perfekt, DAS war`s!
Danke!

Gerne doch! :slight_smile:

#include <Wire.h>
hatte ich weggelassen, s. Kommentar: // Only needed for Arduino 1.6.5 and earlier