Arduino crashes when using hx711 and adafruit oled simultaneously.

I can't figure this one out. i have a crash-situation I can't figure out. i made a bare minimum code example that reproduces the error.

i'm building a simple weight-scale project using load sensors with hx711 decoders and an adafruit 32*128 monochrome oled i2c display.
The HX711 works like a dream, and in my main program it produces calibrated exact weight and displays it flawlessly on the serial monitor.
The oled also works like a charm in an example sketch, and produces rectangles, text and whatever I ask from it.
It's when I try to combine the two I get problems.
Te example program below works as presented, and produces repeatedly The words "Test before", a scale readout and the word "Test". However because the display.begin-line is commented out, the oled is not doing anything. (The "display.cleardisplay" statement is there to make a change in the oled state by commenting or uncommenting it to see if it's doing anything.)

If I uncomment the display.begin-line, the oled displays what it's told to, and the serial monitor outputs the words "Test before" once, and everything halts.

I guess this happens because of an incompatibility between the libraries, but I can't find any way to fix it.

I tried to disconnect the hx711, and as expected, the program ran without problem, displaying 0,000 for the scale-reading.

Help please?

Here's the program:

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Wire.h>
#include <SPI.h>

#include <HX711.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

HX711 scale_a(5, 4);

void setup() {
// display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Oled setup Crash on scale_a.get_units if this line is uncommented.
// oled setup to here
//display.clearDisplay();
display.display();
Serial.begin(38400);
delay(1000);

}

void loop() {
Serial.println("Test Before");
Serial.println(scale_a.get_units(1),3);
Serial.println("Test");

}

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

HX711 scale_a(5, 4);

Could those two 4's both represent pin numbers? If so, that appears to be a pin conflict.

Johnwasser:

Thank you very much. You were spot on.

Ok. Now I feel stupid. As I understood the .h and .cpp files, the "4" in the oled files referred to "4-pin configuration versus 5-pin configuration.
The 4 in scale_a(5,4) is referring to digital pin 4.
I changed #define OLED_RESET 4 to #define OLED_RESET 8, and now it works beautifully, both in the test-sketch, and in my main program.

Now I just wonder what that statement actually does, as pin 8 is not attached to anything, and the only connectors on the oled is SCL, SDA, VCC and GND.

#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_RESET);

I cannot omit it, as the paranthesis needs a number. Do I actually have to dedicate a pin to a reset function I don't need?

I attached the .h and the .cpp-files in case someone can make more sense of them than I.

Adafruit_SSD1306.cpp (24.2 KB)

Adafruit_SSD1306.h (5.63 KB)

Stigsch:

#define OLED_RESET 8

Adafruit_SSD1306 display(OLED_RESET);



I cannot omit it, as the paranthesis needs a number. Do I actually have to dedicate a pin to a reset function I don't need?

It shouldn't need a number since the parameter has a default value:

  Adafruit_SSD1306(int8_t RST = -1);

If I omit the number I get compile error:

exit status 1
request for member 'begin' in 'display', which is of non-class type 'Adafruit_SSD1306()'

If I omit the number I get compile error:

exit status 1
request for member 'begin' in 'display', which is of non-class type 'Adafruit_SSD1306()'

Post the complete code and the complete error message.