2

I have this ESP8266 Heltec NodeMCU board with OLED. The pins are described here.

I have the following problem. The both OLED (with u8g2) and Wifi work fine individually. There is a problem getting them working together.

In particular, the following code works (and shows Hello World, blanks the screen and then repeats):

#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
void setup() {
 u8g2.begin();
}
void loop() {
 u8g2.setFont(u8g2_font_ncenB14_tr);
 u8g2.firstPage();
 do {
 u8g2.setCursor(0, 20);
 u8g2.print(F("Hello World!"));
 } while ( u8g2.nextPage() );
 delay(2000);
 u8g2.clear();
 delay(2000);
}

Adding the Wifi to the code (the only difference to the code above are the 2 lines in the setup).

#include <ESP8266WiFi.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
void setup() {
 u8g2.begin();
 WiFi.begin ( "xxx", "yyy" ); 
 while ( WiFi.status() != WL_CONNECTED ) { delay(500); } 
}
void loop() {
 u8g2.setFont(u8g2_font_ncenB14_tr);
 u8g2.firstPage();
 do {
 u8g2.setCursor(0, 20);
 u8g2.print(F("Hello World!"));
 } while ( u8g2.nextPage() );
 delay(2000);
 u8g2.clear();
 delay(2000);
}

In this case, "Hello World" appears 3 times and then the screen remains blank.

Edit:

I noticed something which, I believe, is an important piece of information when I turned the debugging of the WiFi on.

The display stops working after the output pm open,type:2 0 of the debugger. I believe that pm refers to powermanagement. Could it be that the system goes sleeping? How to prevent this from happening?

asked Dec 23, 2023 at 12:30
5
  • Does the WiFi actually connect, or are things stuck in the while loop in setup()? Commented Dec 23, 2023 at 12:53
  • It does connect. I just produced a minimal example. Commented Dec 23, 2023 at 13:34
  • @ocrdu: Interestingly, "Hello world" appears 3 times (deterministically) and then the screen remains blank. Commented Dec 23, 2023 at 13:48
  • replace all of the OLED code with a blinking LED ... maybe the problem has nothing to do with the OLED Commented Dec 23, 2023 at 17:39
  • Without the OLED, the WiFi works. So either OLED or WiFi work individually. Together, only the WiFi works. The OLED stops working after some time. Commented Dec 23, 2023 at 23:03

1 Answer 1

5

I managed to solve the issue and figure out what the problem is. I put here an answer for reference, if this question appears again. It turns out that the reset of the OLED is important. It is easy to see, if one uses the Adafruit_SSD1306 library. The code

 #define SCREEN_WIDTH 128 
 #define SCREEN_HEIGHT 32
 #define OLED_RESET 0 
 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

produces exactly the issues described in the text. Changing it into

 #define SCREEN_WIDTH 128 
 #define SCREEN_HEIGHT 32
 #define OLED_RESET 16 
 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

solves the issue. Similarly, replacing U8X8_PIN_NONE with 16 in the code above, runs as expected. It looks like the example provided with the board is incorrect.

answered Dec 24, 2023 at 8:59
2
  • For me, this solved a critical problem, of a sketch using U8g2lib.h where the OLED always switched off after about 30s. Using 16 instead of U8X8_PIN_NONE in the constructor: U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16); solved this issue. Commented Dec 29, 2024 at 17:41
  • Thanks a lot! /*reset*/ 16 helped me as well with a Heltec Wifi Kit 8 Commented Mar 5 at 11:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.