TTGO ESP32 OLED

Hallo,

Ich bin gerade dabei, das auf dem verlinkten Tutorial gezeigte Display (TTGO ESP32 OLED) mit Adafruit library zum laufen zu bekommen.
Ich habe die Anleitung soweit umgesetzt, nur bekomme ich den folgenden Teil des Tutorials nicht ganz umgesetzt:

"But that’s not going to give us any chance to change the pins. So, instead of passing &Wire as a parameter, let’s create our own I2C object and pass that instead."
"TwoWire twi = TwoWire(1); // our own TwoWire instance on bus 1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);"

Ich bin mir ziemlich sicher, dass in meinem Code etwas ergänzt werden muss, nur weiss ich nicht so recht was genau.

Ich wäre für eure Unterstützung sehr dankbar!

Tutorial: TTGO ESP32 board with OLED display and Adafruit library - Machina Speculatrix

Folgender Fehler wird mir als erstes ausgegeben:

"error: 'adafruit_SSD1306' does not name a type
adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);
^"

LG

P.s. Mein Code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 16
Adafruit_SSD1306 display(OLED_RESET);

TwoWire twi = TwoWire(1); // our own TwoWire instance on bus 1
adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

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

  twi.begin(4,15);  // Needs to come before display.begin is used
    if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
        Serial.println(F("SSD1306 allocation failed"));
        for(;;); // Don't proceed, loop forever
    }

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done

...

ph1lloops:
"But that’s not going to give us any chance to change the pins. So, instead of passing &Wire as a parameter, let’s create our own I2C object and pass that instead."
"TwoWire twi = TwoWire(1); // our own TwoWire instance on bus 1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);"
....

"error: 'adafruit_SSD1306' does not name a type
adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);
^"

Groß- und Kleinschreibung macht einen Unterschied.

Vielen Dank für deine Antwort. Ich habe den Code wie folgt abgeändert, leider erscheint folgende Fehlermeldung:

"error: 'SCREEN_WIDTH' was not declared in this scope
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);"

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 16
//Adafruit_SSD1306 display(OLED_RESET);

TwoWire twi = TwoWire(1); // our own TwoWire instance on bus 1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

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

  twi.begin(4,15);  // Needs to come before display.begin is used
    if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
        Serial.println(F("SSD1306 allocation failed"));
        for(;;); // Don't proceed, loop forever
    }

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done

...

ph1lloops:
"error: 'SCREEN_WIDTH' was not declared in this scope
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);"

Wo hast du SCREEN_WIDTH und SCREEN_HEIGHT denn definiert?

Ich denke, das ist genau meine Frage, wie / bzw. wo definiere ich das?
Eigentlich definiere ich doch die Displaygröße in der Adafruit_SSD1306.h indem ich die richtige Zeile aktiviere:

#define SSD1306_128_64

deswegen verstehe ich in dem Tutorial diese beiden Zeilen nicht ganz:

TwoWire twi = TwoWire(1); // our own TwoWire instance on bus 1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);

Lösche ich das "SCREEN_WIDTH, SCREEN_HEIGHT," raus, erscheint folgende Fehlermeldung:

error: no matching function for call to 'Adafruit_SSD1306::Adafruit_SSD1306(TwoWire*, int)'
Adafruit_SSD1306 display(&twi, OLED_RESET);

Normalerweise definiert man das vor der ersten Benutzung, und zur Definition nimmt man C++.

Z.B.

const int SCREEN_WIDTH = 768;
const int SCREEN_HEIGHT = 432;

Wie groß dein Display ist wirst du ja vielleicht selbst wissen.

Ich denke für dich wäre ein einführendes C++ Tutorial sinnvoll.

In der Adafruit_SSD1306.h habe ich nochmal nachgesehen, hier habe ich das richtige Display aktiviert. Irgendwie scheine ich noch etwas ändern zu müssen, was der Autor des Tutorials für selbsterklärend sieht, im Bezug auf den Teil:

TwoWire twi = TwoWire(1); // our own TwoWire instance on bus 1
Adafruit_SSD1306 display(&twi, OLED_RESET);

Sehr nett, dass der Autor direkt geantwortet hat. "Leider" poppte der nächste Error auf:

error: no matching function for call to 'Adafruit_SSD1306::Adafruit_SSD1306(int, int, TwoWire*, int)'
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET);
^
In file included from /Users/philipphubert/Dokumente/Arduino/Urknalle/ESP32_Oled_0.96_Adafruit_BETA/ESP32_Oled_0.96_Adafruit_BETA.ino:22:0:
/Users/philipphubert/Dokumente/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:148:3: note: candidate: Adafruit_SSD1306::Adafruit_SSD1306(int8_t)
Adafruit_SSD1306(int8_t RST = -1);
^
/Users/philipphubert/Dokumente/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:148:3: note: candidate expects 1 argument, 4 provided
/Users/philipphubert/Dokumente/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:147:3: note: candidate: Adafruit_SSD1306::Adafruit_SSD1306(int8_t, int8_t, int8_t)
Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS);

Which board do you have selected in: Tools -> Board ?

Thanks again, really! Ok I am a step further now. The display shows up and I can write lines on it (I had to update the adafruit library). But something is wrong with the resolution/rotation.
In the new Adafruit_SSD1306.h I uncommented the line:

"Hashtag"define SSD1306_128_64 ///< DEPRECTAED: old way to specify 128x64 screen

The rest oft the Adafruit_SSD1306.h is untouched, I didn't change anything.

In the sketch I used your code:

// --- OLED DISPLAY -----------------------------------------------------------------------
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     16 // Reset pin - changed to 16 for TTGO board
TwoWire twi = TwoWire(1); // create our own TwoWire instance
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET); // passing our TwoWire instance as param

I made a picture of the screen, I think you know the solution in a second :-). Thanks from Germany!

Here is the full code:

/**************************************************************************
 Based on the Adafruit_SSD1306 example: ssd1306_128x64_i2c
 This is for the TTGO ESP32 OLED module
 **************************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// --- OLED DISPLAY -----------------------------------------------------------------------
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     16 // Reset pin - changed to 16 for TTGO board
TwoWire twi = TwoWire(1); // create our own TwoWire instance
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &twi, OLED_RESET); // passing our TwoWire instance as param

// ***************************************************************************************
// ***  SETUP                                                                          ***
// ***************************************************************************************
void setup() {
  Serial.begin(115200);
  twi.begin(4,15);  // Needs to come before display.begin() is used
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
}

// ***************************************************************************************
// ***  LOOP                                                                           ***
// ***************************************************************************************

void loop() {

display.clearDisplay();
display.drawLine(1, 1, 128, 1, WHITE);
display.display();   
delay(1000);

display.clearDisplay();
display.drawLine(1, 4, 128, 4, WHITE);
display.display();
delay(1000);  
}

Hmm, I'm not sure uncommenting deprecated lines in a library is a good idea. :wink:

For displaying text on the screen, I used the Adafruit_GFX library. Unfortunately, the one program I wrote using this board (which prompted the blog post) is incomplete. It runs fine, but it has a lot of extraneous code in it from another project. It might be more confusing than helpful. But I've tried to cut out some of the junk and have updated the file at:

This is incomplete code and IT WON'T RUN. In particular, it grabs wifi credentials from my personal library (which doesn't get shared on GitHub!). But it might give you an idea of what I did. Beyond that, I'm running out of ideas, to be honest. I've only done that one (unfinished) project on this board!

Ok i got it to work.

  1. I had to update the Adafruit library
  2. I reinstalled the ESP32 board

Works like it is supposed to.

Thanks again!

Glad it worked out.

Yes :-).
When I want to use the board to use it with an termistor to measure the temperature. Usually I connect that termistor with an 100K resistor to A0 on my Arduino Nano.
I was reading a tutorial about the pinout of the ESP32 boards and when I understand everything right, I can use GPIO34 and use it as an analog input. Is that correct?

Thanks!