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

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);
}