adafruit / Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
http://www.adafruit.com/category/63_98
Other
1.75k stars 964 forks source link

Display stops working after a few seconds, ESP32 NodeMCU #220

Closed AnanasPizza closed 2 years ago

AnanasPizza commented 2 years ago

I'm using the library on an ESP32, trying to display new data on every loop, without any delay calls. The code below is obviously very stripped down. It's connected to 21 and 22 pins. As well as a Real Time clock, a TCS Light sensor, and a SCD30.

The issue is, that after a few seconds/minutes, this happens: WhatsApp Image 2021-09-14 at 09 54 10

Is this a RAM Error?

After compilation this is the RAM and Flash Usage RAM: [= ] 12.4% (used 40524 bytes from 327680 bytes) Flash: [========= ] 85.1% (used 1115840 bytes from 1310720 bytes)

#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 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();
    }
ladyada commented 2 years ago

hiya, this is a good question to post to the espressif forums or whomever you purchased hardware from. thanks :)