Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » ESP32 & Adafruit_GFX

Author: Mistercoenkel
18/09/2022 06:47:35
Hi,

I have a problem with my OLED SSD1306 display.

Usually I use the u8g2 library but it doesn't work with my current ESP32-PICO-D4 , only the Adafruit library works.

So in TcMenu Designer I have correctly declared my screen:

- AdaFruit_GFX with manual declaration and configuration
- Display variable name: gfx
- Display variable type: Adafruit_SSD1306

Then in my sketch I declared :

#include "myMenu_menu.h"

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32

Adafruit_SSD1306 gfx(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  
  Serial.begin(9600);
  
  Wire.begin(15, 33);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!gfx.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  gfx.display();
  
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  gfx.clearDisplay();
    
  setupMenu();
  
}

void loop() {
  
  taskManager.runLoop();

}


My display works, I see the Adafruit logo but my menu does not appear and then my display is black.

I not find a tcMenu example with the Adafruit library.

My project is attached, if you can help me or if you have an example that would be nice.

Thanks

Filename myMenu.rar
Description No description given
Filesize 8 Kbytes
Downloaded 154 time(s)
[Disk] Download


Author: davetcc
18/09/2022 17:54:14
If you are using an OLED display, in AdafruitGFX library this is a memory buffered display, you need to ensure the "Library is memory buffered" option is ticked in the Code Generator display options. Without this, the display would never render anything.

Author: Mistercoenkel
19/09/2022 05:21:59
 
davetcc wrote:If you are using an OLED display, in AdafruitGFX library this is a memory buffered display, you need to ensure the "Library is memory buffered" option is ticked in the Code Generator display options. Without this, the display would never render anything.


I forgot to specify that I had tried with and without the "Library is memory buffered" option.

Same result, only the adafruit logo is visible then it remains blocked on it as if the screen was not updating. I tried to use "gfx.clearDisplay();" before "setupMenu();" but nothing worked.

and the example gived on this link: "https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-plugins/adafruit_gfx-renderer-plugin/" use the u8g2 library and not Adafruit.

Using the menu library with OLED SSD1306

The library for this display is both memory buffered and monochrome. Again there is a complete example menu packaged with tcMenu. This example was tested on both ESP32 and ESP8266, but the concepts are generally applicable to any processor. Link below takes you to the source on github.

[https://github.com/davetcc/tcMenuLib/tree/master/examples/esp8266WifiOled]
 

Author: davetcc
19/09/2022 14:45:21
To be honest, we nearly always use U8G2 with OLED displays. Is there a reason that you use the Adafruit library instead? I'll need to test it myself to see if there is an issue as I don't think many use this combination (Adafruit with OLED).

I have an ESP32 board with an OLED somewhere, I'll try your example on that but it may take me a day or two.

Author: Mistercoenkel
19/09/2022 15:55:03
 
davetcc wrote:To be honest, we nearly always use U8G2 with OLED displays. Is there a reason that you use the Adafruit library instead? I'll need to test it myself to see if there is an issue as I don't think many use this combination (Adafruit with OLED).

I have an ESP32 board with an OLED somewhere, I'll try your example on that but it may take me a day or two.


Well the u8g2 library does not work with my ESP32-PICO-D4 (SMD) card and I don't know why, I have already talk with the developer of the u8g2 library and we have not been able to find the problem . (https://github.com/olikraus/u8g2/issues/1955)

Only the Adafruit library works.

Edit: The menu now appears when I use the code
display.display();

in the loop but it seems strange to me to have to refresh the screen all the time even when there is no activity. i'm right ?

If you do test, let me know. Thanks

Author: davetcc
20/09/2022 06:29:16
 
Edit: The menu now appears when I use the code
display.display();

in the loop but it seems strange to me to have to refresh the screen all the time even when there is no activity. i'm right ?


I think there is a bug in the Adafruit plugin, I'll put in a fix for the next version, if you open the adafruit plugin header file that gets put into your project I think it will work:

Find this line:

#define DISPLAY_HAS_MEMBUFFER false


In the file within your project: tcMenuAdaFruitGfx.h

and change false to true

Author: Mistercoenkel
20/09/2022 08:12:20
 
davetcc wrote:
Edit: The menu now appears when I use the code
display.display();

in the loop but it seems strange to me to have to refresh the screen all the time even when there is no activity. i'm right ?


I think there is a bug in the Adafruit plugin, I'll put in a fix for the next version, if you open the adafruit plugin header file that gets put into your project I think it will work:

Find this line:

#define DISPLAY_HAS_MEMBUFFER false


In the file within your project: tcMenuAdaFruitGfx.h

and change false to true


It works perfectly now.

Thanks

Author: davetcc
20/09/2022 11:44:28
I’ve confirmed this as a bug in the plug-in variable substitution code. It affects the Ethernet plugin as well.

It will be fixed in the next version and I’ll ensure that unit tests capture that case too.

Author: Mistercoenkel
20/09/2022 12:16:46
 
davetcc wrote:I’ve confirmed this as a bug in the plug-in variable substitution code. It affects the Ethernet plugin as well.

It will be fixed in the next version and I’ll ensure that unit tests capture that case too.


Well I'm happy that my problem is helped to fix a bug. You may also add an example on github with the Adafruit library. smilie




Register / Login  |  Desktop view  |  Jump to top of page