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