ESP32 - U8G2 and SD1306

Hello:

Does anyone have any tutorials or advice in using a Esp32 with the U8G2 library and a SD1306 display. Seems a lot of the tutorials or sample code are years old. Would have thought there would have been a simpler approach.

Have a project currently using the U8g2 library and display on a Uno but running out of memory, wanted to port the whole project over to a ESP32, but stumped on how to get the display working.

Surely most U8g2 examples will just run out of the box.

Please quote which example(s) do not work e.g. example name + constructor statement.

David.

Edit. I just built and ran GraphicsTest_u8g2 with this constructor:

U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

Which board did you use, not sure how a ESP32 board would work without the modifications required in the link I posted. Issue is it refers to creating directories and modifications, but I don't see how one does that in the Arduino IDE environment.

I actually used a Wemos/TTGO D1 R32 which is a Uno format board.
The IDE was set for "ESP32 Dev Module"
The IDE was v1.8.12

I ran example fresh from U8g2lib.

No, I have not studied your GitHub link but I did notice that it is over 2 years old.
ESP32 Core may have been using an old version.
U8g2lib may have been using an old version.

Please report which IDE, Core and library version.
It is not essential to run the "very latest" versions but it is wise to keep reasonably up to date.

Mind you, I am pretty certain that U8g2lib has been working 100% on ESP32, ESP8266, ... for several years.

I suspect that you can look up GitHub history for ESP32 Core, U8g2lib, ... to see what historic problems have arisen and if and when they were fixed.

David.

Oops, I suppose the reason there is not much out there with U8G2 and ESP32 lately is because it works. Just saw this in the reference manual. Just assumed it didn't work. Will get breadboarding it and see what happens.

U8g2 is much more portable than U8glib. It is expected, that U8g2 will work with almost all current and upcoming boards. The following table is my personal experience with boards tested by this project. Many other boards may also work.

Basically all boards with a (more or less) up to date Arduino API will be supported by U8g2. I have feedback that the following systems work with U8g2:

  • Aruino Zero, Uno, Mega, Due, 101, MKR Zero and probably all other official Arduino boards.
  • Feather M0, ESP32 and 32u4
  • STM32 based boards supported by the Arduino IDE
  • ESP8266 and ESP32 boards supported by the Arduino IDE
  • Probably all other boards, which are supported by the Arduino IDE

Oliver's supported target board list was posted almost 3 years ago (Feb 2018)

I would be very confident that all his examples will work out of the box.
Mind you, sh*t happens. If you have a problem:

Please quote which example(s) do not work e.g. example name + constructor statement.

together with IDE version, ESP Core version, u8g2lib version number.

Readers here can replicate. If a valid problem, readers can raise an Issue or offer a PullRequest on Oliver's U8g2lib GitHub.
That is how Public Forums operate and Open Source Software is maintained.

David.

Hi Bryanpl, David

I created for a WROOM ESP32 wired to a SSD1306 12864 i2c OLED breakout (four pins) a sketch using U8G2 that is an animation of 6 frames 9662 pixels of a dinosaur (Velociraptor) performing a welcoming gesture. Code starts as follows (board DOITESP32 DEVKITV1)

// WROOM_SSD_1306_OLED_raptor_nn

// for WROOM ESP32 
// display is a 128*64 OLED with SSD1306 driver and i2c functionality (4-wire)
// SCL (yellow) to pin D22
// SDA (green) to pin D21
// 
// public domain
// Floris Wouterlood
// december 17, 2020

   #include<Arduino.h>
   #include<U8g2lib.h>
 
   #ifdef U8X8_HAVE_HW_SPI
   #include<SPI.h>
   #endif
   #ifdef U8X8_HAVE_HW_I2C
   #include<Wire.h>
   #endif

   int delayTime=100;
 
   U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 22, /* data=*/ 21, /* reset=*/ U8X8_PIN_NONE);   // ESP32 Thing, pure SW emulated I2C

 static const unsigned char dino_018[] PROGMEM = { 

    // ████████████████████████████████████████████████████████████████████████████████████████████████████████████████
    // ███████████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙█████████████████████████
    // █████████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙████████████████████████
    // █████████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙██∙∙∙∙∙██████████████████████
    // ████████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙███∙∙∙∙∙∙████████████████████
    // ████████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙██∙∙∙∙∙∙∙∙███████████████████
    // ███████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████
    // ███████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████
    // ██████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙█∙∙∙∙∙∙∙∙∙∙∙████████████████
    // ██████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙█∙∙∙∙∙∙∙∙∙∙███████████████
    // █████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██∙∙∙∙∙∙████████████████
    // █████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██∙∙∙∙████████████████
    // █████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙████████████████████
    // █████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙████████████████
    // ████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙██∙∙█∙∙∙∙∙∙∙█████████████████
    // ████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // ████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙██████████████████████████████
    // ████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙███████████████████████████████
    // ████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙████████████████████████████████
    // ████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙████████████████████████████████
    // ████████████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙████████████████████████████████
    // █████████████████████████████████████████████████████████████████████∙∙█∙∙∙∙∙∙∙∙████████████████████████████████
    // ██████████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙███████████████████████████████
    // ██████████████████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙███████████████████████████████
    // ████████████████████████████████∙∙∙∙∙∙████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙███████████████████████████████
    // ███████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙███████████████████████████████
    // ████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████████
    // ██████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████████
    // █████████████████████∙∙∙∙∙∙∙∙███████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████████
    // ███████████████████∙∙∙∙∙∙███████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // ██████████████████∙∙∙∙█████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // █████████████████∙∙∙∙████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // ████████████████∙∙∙█████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙████████████████████████████
    // ███████████████∙∙∙████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // ██████████████∙∙████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // █████████████∙∙██████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // ████████████∙∙███████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████████
    // ████████████∙███████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████████
    // ███████████∙∙████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████████
    // ███████████∙█████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙█████████████████████████████
    // ██████████∙██████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙███████████████████████████
    // ██████████∙██████████████████████████████████████████∙∙∙∙∙∙██∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙███████████████████████████
    // █████████∙███████████████████████████████████████████∙∙∙∙∙∙███∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████
    // █████████∙███████████████████████████████████████████∙∙∙∙∙∙████∙∙∙∙∙█∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙∙███████∙████∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙██████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙∙███████████∙∙∙∙∙∙∙∙∙███∙∙∙∙∙██████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙███████████∙∙∙∙∙∙∙∙█████∙∙∙∙∙██████████████████████████
    // ████████████████████████████████████████████████████∙∙∙∙∙███████████∙∙∙∙∙∙███████∙∙∙∙∙██████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙███████████∙∙∙∙∙███████∙∙∙∙∙███████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙███████████∙∙∙∙∙███████∙∙∙∙∙███████████████████████████
    // █████████████████████████████████████████████████████∙∙∙█████████████∙∙∙∙███████∙∙∙∙████████████████████████████
    // █████████████████████████████████████████████████████∙∙∙██████████████∙∙∙███████████████████████████████████████
    // █████████████████████████████████████████████████████∙∙∙██████████████∙∙∙∙██████████████████████████████████████
    // █████████████████████████████████████████████████████∙∙∙██████████████∙∙∙∙██████████████████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙██████████████∙∙∙∙█████████████████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙███∙██████████∙∙∙∙∙████████████████████████████████████
    // █████████████████████████████████████████████████████∙∙∙∙██∙∙∙██████████∙∙∙∙∙███████████████████████████████████
    // ████████████████████████████████████████████████████∙∙∙∙∙∙∙∙████████████∙∙∙∙∙∙∙∙∙∙█∙∙███████████████████████████
    // ███████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙███████████∙∙∙∙∙∙∙∙∙∙∙∙████████████████████████████
    // ██████████████████████████████████████████████████∙∙∙∙∙∙∙∙∙∙∙████████████∙∙∙∙∙∙∙∙∙∙∙████████████████████████████
    // ██████████████████████████████████████████████████∙∙∙∙█∙∙∙∙∙█████████████∙∙██∙∙∙∙∙∙█████████████████████████████
    // ████████████████████████████████████████████████████████████████████████████████████████████████████████████████

and so forth - too long to post here - download the entire sketch from here.
Success, Photoncatcher

Thanks All:

I did see these two constructors in the default list with a comment that they are for ESP32. But I wonder why pins 16/17 (TX2). Your constructor the pins used are GPIO 21 and 22 which appears to the correct pinouts that I see when doing a google search of the ESP32, maybe different variants of boards??

//U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=/ 16, / data=/ 17, / reset=*/ U8X8_PIN_NONE); // ESP32 Thing, pure SW emulated I2C

//U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=/ U8X8_PIN_NONE, / clock=/ 16, / data=*/ 17); // ESP32 Thing, HW I2C with pin remapping

Had a chance to breadboard it tonight and success. Used the Hello world example and the basic constructor

U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

without any pin assignments and it worked fine. Just made sure the display was hooked to pins 22 SDL (GPIO22) and 21 SDA (GPIO21) on the ESP32.

Untitled.png

Untitled.png

I am having trouble with the basic use of the IDE. When I use Sketch-Include Library for U8g2 I get
#include <U8g2lib.h>
#include <U8x8lib.h>
but not
#include <U8g2.h>
which my sketch calls.
If I type in
#include <U8g2.h>
I get an error saying that file can not be found.
What am I doing wrong?

I assume that you installed the u8g2 library either by a download and imported as a library or using the Tools-->Library Manager> searching for U8G2 and downloading the library by this means.

#include <U8g2lib.h> is correct.