OLED display freezing issue

I made a device that measures force on a load cell and displays it on a mini 0.96” I2C OLED display.

The code works fine in the attached form. I let it run over the night and there were no issues with freezing whatsoever. But if I increase text size from 1 to 2, 3 or 4 (line 32) then the display will work for a couple of seconds and then freeze indefinitely. The larger the text size, the sooner the display freezes.

Hardware details:
Arduino Uno
0.96” I2C OLED
Load Cell Amplifier - HX711

Line 32:

display.setTextSize(1);

Full code:

#include "HX711.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET LED_BUILTIN
#define DOUT 2
#define CLK 3

HX711 scale;

float calibration_factor = 56400; 
//56400 worked for my 440lb max scale set

Adafruit_SSD1306 display(OLED_RESET);
  #if (SSD1306_LCDHEIGHT != 64)
  #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  #endif
void setup() {
//Serial.begin(9600);
scale.begin(DOUT, CLK);
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
}

void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.print(scale.get_units(), 1);
//display.println(" N");

display.setTextColor(BLACK, WHITE); // 'inverted' text
display.display();

delay(100);
}

When you upload your code, do you see any warning? Sounds like a memory shortage issue.

I do not get any warning.

Note the Adafruit library allocates the display buffer at runtime, so the needed memory is not shown in the compiler output. A 128x64 display needs 1024 bytes of ram, 128x32 needs 512.

Thank you for clearing that up. I really didn't know what to make of it.

Are there any other options other than upgrading from UNO to a board with more RAM?

Look at the page buffer examples for the U8g2 library, that can significantly reduce the display buffer size. Note that U8g2 allocates the buffer at compile-time, so it is included in the ram usage.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.