Search code examples
arduinoesp32adafruit

Display SSD1306 stops working after a short while on esp32


I'm currently working on a sensor box, that displays the sensor data non stop in the loop of a ESP32 Node MCU on a SSD1306 Display, connected over I2C (21 and 22). But then the display does weird stuff.

I can't share all of the ESP32 Code right now, but this should be all the needed stuff anyways I guess:

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

void setup() {
    Wire.begin();
    initializeDisplay();
}

void loop() {
    ...
    writeToDisplay(.......);
}

#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 0x3C 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
bool initializeDisplay() {
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    return false;
  }
  display.display();
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Display initialized!");
  display.display();
  display.clearDisplay();
  return true;
}




void writeToDisplay(float colorTemp, float lux, float dbValue, String temperature, String relH, String co2) {
      display.clearDisplay();
      displayText ="";
      displayText += "Lux ";
      displayText += String(lux,1);
      displayText += "lx\n";
    
      displayText += "Color Temp. ";
      displayText += String(colorTemp, 1);
      displayText += "K\n";
    
      displayText += "Noise level: ";
      displayText += String(dbValue, 1);
      displayText += "dbA\n";
    
      displayText += "Temperature: ";
      displayText += temperature;
      displayText += "C\n";
    
      displayText += "relH ";
      displayText += relH;
      displayText += "%\n";
    
      displayText += "CO2 ";
      displayText += co2;
      displayText += "ppm\n";
      if(isPortable()) {
        displayText += "Portable Mode";
      }
      display.println(displayText);
      display.display();
    }

In the beginning everything works great, but after a minute or so this happens: enter image description here

Is this a memory or flash issue? Does anyone have any idea? I don't think it's a power issue.


Solution

  • Apparently the problem was, there were too many devices connected over the same I2C bus. So what fixed this:

    • Instead of soldering Display, two Sensors and a real time clock to GPIO 21 and 22, I soldered the display to GPIO 32 and 33.

    • Added Wire1.begin(32, 33); to setup

    • Changed constructor of display to Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);

    I guess the display stops working as soon as there is too much traffic on the bus. So this was not a memory problem