Hello everyone and thank you in advance for any advice you can offer.
As part of a larger project, I'm trying to display the output from a load cell on an OLED display. I'm using a HX711 amplifier, a SH1106 OLED, and Arduino Uno.
I have very simple sketches for both the scale and OLED that work perfectly. Sadly, when I combine them, the program does not seem to run.
From my research it seems that this could be a memory issue and so I've stripped the code down as far as my current skills allow. I've also implemented a memory reporting function I found here and ,assuming the output is correct, can tell you that the HX711 sketch is using 193kb of RAM, and the OLED sketch 1497kb. Combined, this is 1690kb.
Sketch Goal:
Take readings from a calibrated load cell/HX711 combo and display that reading on an OLED display in conjunction with some static text.
Combined OLED and HX711 Sketch - Not working:
// Scale Libraries and setup
#include <HX711.h>
#define DOUT 3
#define CLK 4
#define calibration_factor -970 // Calibration factor of scale
HX711 scale(DOUT, CLK);
// End scale libraries and setup
// OLED Libraries and setup
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
// End OLED libraries and setup
// Variables
int loadCellValue = 1;
void setup() {
Serial.begin(9600);
scale.set_scale(calibration_factor);
scale.tare();
}
void loop() {
Serial.println(F("Entering Loop")); // Used to show loop has been entered
loadCellValue = scale.get_units(); // Take reading from scale
//Some Example Text
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK, WHITE);
display.setCursor(3,5);
display.println(" Some Example Text ");
display.println();
display.setTextColor(WHITE);
display.setTextSize(3);
display.setCursor(15,21);
display.print(loadCellValue);
display.print("/");
display.print("20");
display.display();
delay(2000);
}
Working OLED Test Sketch
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
void setup() {
Serial.begin(9600);
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
}
void loop() {
int loadCellVal = 17;
Serial.println("Entering Loop"); // prove that loop has begun
// Some example text
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK, WHITE);
display.setCursor(3,5);
display.println(" Some Example Text ");
display.println();
display.setTextColor(WHITE);
display.setTextSize(3);
display.setCursor(15,21);
display.print(loadCellVal);
display.print("/");
display.print("20");
display.display();
delay(2000);
Serial.println(freeRam());
}
int freeRam() {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
Working HX711/Load Cell Sketch
#include <HX711.h>
#define DOUT 3
#define CLK 4
#define calibration_factor -970 // Calibration factor of scale
HX711 scale(DOUT, CLK);
int loadCellValue = 1;
void setup() {
Serial.begin(9600);
scale.set_scale(calibration_factor);
scale.tare();
}
void loop() {
Serial.println("Entering Loop"); // prove that loop has begun
Serial.println(loadCellValue);
loadCellValue = scale.get_units();
Serial.println(freeRam());
}
int freeRam() {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
I'd be grateful of any tips or advice as to how to further troubleshoot this problem, or at least a few keywords with which to continue googling!
Thanks in advance again,
Nick