ESP8266 with SSD1306 0.91" display - display randomly turns off.

I have two white ESP8266 boards with I2C ssd1306 oled 0.91" display, see picture. On both boards display randomly turns off and not recovered until reset button. Micro is still running? problem is only with display. Have tried two different libraries with the same result so, that is why, thinking it is hardware problem.
Are there any ideas on what could be bad and how to fix?


It is ALWAYS wise to post a link to the actual display that you have bought. e.g. Ebay Sale page.

The image is "ok" but I don't want to Google and guess.
Especially when you could have provided a clickable link.

David.

I've got 4 of those and they work fine, however they were not without problems.

Put a resistor between maybe 1k and 5k between GPIO15 (D8) and ground. Without the resistor it won't always start properly.

I use Adafruit_SSD1306.h library without problems.

I have 2 of them mounted as daughter boards on PCBs providing WiFi access to a PIC, these work without a problem. I have another on breadboard on my desk, which occasionally freezes, especially if I move it around. Left alone it seems to be OK. I can only guess touching it is putting noise on the pins and upsetting it.

Also try 0μ1 capacitors between the 5V pins and ground and the 3V3 pins and ground.

@Perry,

I have a TTGO ESP32 board with a small 240x160 TFT on it.
There are a wide range of ESP32/ESP8266 with mounted OLED/TFT

Yes, I can probably find one that matches the picture in #0
But a real link removes all guesswork.

And if your boards are a bit "sensitive" there is even more reason to specify the exact board.
It also means that we can pinpoint the particular capacitor on the pcb.

David.

@SergeS, @PerryBebbington,

these do look good.

I know pure advertisement may be against the rule.
But in the context of a question a clickable link to the shop site should be ok.

Please always put a clickable link to the devices in question in this forum section!

It spares responders time to search, and is a source for inspiration (at least for me).

Jean-Marc

The original might be from HELTEC: 2PCS WIFI ESP8266 0.91 Inch Blue OLED Display WIFI Kit 32 IOT Development Board for Arduino

Top right of this photo is the one on my desk


Taken from Measuring rainfall [Solved] [For now!] - #31 by PerryBebbington - Project Guidance - Arduino Forum
Power is to the 5V pin from the breadboard, although probably hard to see in that photo.
(Display shows wind speed in MPH)

david_prentice:
It is ALWAYS wise to post a link to the actual display that you have bought. e.g. Ebay Sale page.

The image is "ok" but I don't want to Google and guess.
Especially when you could have provided a clickable link.

David.

Yes, you are absolutely right! I did not realized it can help another people... Link is below. But to be honest - I've bought it kind of long time ago, around 6 month ago. link

Thanks for the link.

It identifies your item which avoids a list of supplementary questions.

Most importantly. It takes you 10 seconds to copy-paste a link. Which is much easier for you than typing some limited information (that always prompts further questions)

On both boards display randomly turns off and not recovered until reset button.

#2 has good advice. 0u1F means the same as 100nF.

ESP8266 always requires a regular kick. i.e. call to yield()
If you ever find a random crash on ESP8266 you should check this first.

If not sure, post your code. Readers might spot a problem.
Either paste the full sketch or attach a file.

David.

david_prentice:
Thanks for the link.

It identifies your item which avoids a list of supplementary questions.

Most importantly. It takes you 10 seconds to copy-paste a link. Which is much easier for you than typing some limited information (that always prompts further questions)
#2 has good advice. 0u1F means the same as 100nF.

ESP8266 always requires a regular kick. i.e. call to yield()
If you ever find a random crash on ESP8266 you should check this first.

If not sure, post your code. Readers might spot a problem.
Either paste the full sketch or attach a file.

David.

Yep, will play with caps and resistor, as per PerryBebbington suggestion above.

I do not think there is a reason post code, seems like it is not a software problem because of:
0) code is trivial :slight_smile: , just show 1 sec counter there;

  1. two boards like on the picture in original post from the same seller are failed on the same way;
  2. two different codes with different SSD1306 libs are failed on the same way;
  3. another SSD1306 display (128x64) with another ESP8266 board (lolin-12e) with the same code - works with no problem.
  4. read my original post - esp8266 was not crashed, it is still alive, I see it outputs values to the Serial.

PerryBebbington:
I've got 4 of those and they work fine, however they were not without problems.

Put a resistor between maybe 1k and 5k between GPIO15 (D8) and ground. Without the resistor it won't always start properly.

I use Adafruit_SSD1306.h library without problems.

I have 2 of them mounted as daughter boards on PCBs providing WiFi access to a PIC, these work without a problem. I have another on breadboard on my desk, which occasionally freezes, especially if I move it around. Left alone it seems to be OK. I can only guess touching it is putting noise on the pins and upsetting it.

Also try 0μ1 capacitors between the 5V pins and ground and the 3V3 pins and ground.

Resistor and caps did not help.

I would still be suspicious of the wiring. i.e. how good are your soldered joints, wire crimps, ...

If you post your code in code tags I will put it on one of mine and see what happens.

PerryBebbington:
If you post your code in code tags I will put it on one of mine and see what happens.

Than you so much. Code is below, nothing fancy. Rarely working more than 5 minutes.

#include <Wire.h>
//#include <Adafruit_GFX.h>  //not needed
#include <Adafruit_SSD1306.h>

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

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET   -1 //8 // 3 //4    Reset pin # (or -1 if sharing Arduino reset pin)

//Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi = &Wire, int8_t rst_pin = -1, uint32_t clkDuring = 400000UL, uint32_t clkAfter = 100000UL);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire , OLED_RESET);
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET, 100000UL, 100000UL);

void setup() 
{
  Serial.begin(115200);
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); }
  display.clearDisplay();  
  display.setTextSize(2);  
  display.setTextColor(SSD1306_WHITE); 
  display.setCursor(0,0); 
  display.println("Hello!!!");
  display.display();
  Serial.println("\r\nStarted...");
  delay(1000);
}

int cnt=0;
void loop()  
{ 
  display.clearDisplay();  
  display.setTextSize(4);
  display.setCursor(0,0);     
  display.println(cnt++);
  if (cnt==1000) cnt=0;
  display.display();
  Serial.printf("\r\n cnt: %d", cnt);
  delay(1000);
}

Thanks.

Nothing wrong with your hardware.

The first time I ran it the number counted to 9 then the display went the display went blank. I tried with smaller text (text size 1, 2 and 3) and it counted OK.

However, after a few tries I noticed that it would go blank sometimes, while typing this it went blank at 54 with text size 3. The count in the serial monitor continues OK.

Now it's up to 250 without a problem and still going.

Try this:

#include <Wire.h>
//#include <Adafruit_GFX.h>  //not needed
#include <Adafruit_SSD1306.h>

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

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET   16 //8 // 3 //4    Reset pin # (or -1 if sharing Arduino reset pin)

//Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi = &Wire, int8_t rst_pin = -1, uint32_t clkDuring = 400000UL, uint32_t clkAfter = 100000UL);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire , OLED_RESET);
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET, 100000UL, 100000UL);

void setup()
{
  Serial.begin(115200);
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); }
  display.clearDisplay(); 
  display.setTextSize(2); 
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.println("Hello!!!");
  display.display();
  Serial.println("\r\nStarted...");
  delay(1000);

  display.setTextSize(4);
}

int cnt=0;
void loop() 
{
  count();
}

void count() {
  const uint32_t interval = 1000;
  uint32_t currentMillis = millis();
  static uint32_t lastMillis;
  if (currentMillis - lastMillis >= interval) {
    lastMillis = currentMillis;
    display.clearDisplay(); 
    display.setCursor(0,0);     
    display.println(cnt++);
    if (cnt==1000) cnt=0;
    display.display();
    Serial.printf("\r\n cnt: %d", cnt);
  }
}

The problem was this:

#define OLED_RESET   -1 //8 // 3 //4    Reset pin # (or -1 if sharing Arduino reset pin)

Which I have changed to:

#define OLED_RESET   16 //8 // 3 //4    Reset pin # (or -1 if sharing Arduino reset pin)

The other changes I have made are:

Moved setTextSize to setup because you don't need to change it every time you print to the display. Although this has nothing to do with your problem I was a bit suspicious of it at first. No harm in having it where you had it, I was just tidying up before I found the real problem.

Made your delay into a millis() based timer, this is non-blocking. It is really important you understand this as it is fundamental to writing non-blocking, multitasking code.

Moved your test code into a separate function; putting everything in loop() might be OK for simple testing but it soon grows into an unmanageable mess if you don't separate code into functions. You need to learn this too.

This one really helps, thank you!

#define OLED_RESET   16

I thought I had tried this, but seems like not :-).
I've put voltmeter on the GPIO16 and see constant high level there, +3.3V.
When OLED_RESET configured as -1, GPIO16 is really input with no pullup resistor, so it is floating input.
Confirmed with voltmeter, in this case voltage over there is high after reset, then slowly drifting to low, at some point cause ssd1306 to reset. btw, If to connect 10K pullup resistor from GPIO16 to +3.3V - this preventing pin voltage to goes down and also works :-).

Thank you again, I should realize it by myself...

Thank you again, I should realize it by myself...

You are welcome.

Don't worry that you think you should have realised yourself, we all do it, I do it; stare at obviously wrong code and fail to see what is wrong. Usually sleep helps, but not always.

PerryBebbington:
You are welcome.

Don't worry that you think you should have realised yourself, we all do it, I do it; stare at obviously wrong code and fail to see what is wrong. Usually sleep helps, but not always.

:wink: yep, a lot of things (technically speaking :wink: i have done during sleeping!

This topic was automatically closed after 120 days. New replies are no longer allowed.