Register / Login | Desktop view |
#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();
}
Filename | myMenu.rar |
Description | No description given |
Filesize | 8 Kbytes |
Downloaded | 154 time(s) |
Download |
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.
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]
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.
display.display();
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 ?
#define DISPLAY_HAS_MEMBUFFER false
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
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.