I’ve written this code as a kind of combination from the example code for the HX711 load sensor and the HTU21D-F Temp/Humidity sensor. The first iteration of code, I was able to get the temperature and humidity to display and continually update on the OLED, however I’m having trouble getting the third line with the current load to display.
I suspect it’s something with the way I’m defining the HX711. The previous iteration of this code, I had
// Include Libraries
#include <Arduino.h>
#include <HX711.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_HTU21DF.h>
// Pin Definitions
#define scaledout 3
#define scaleclk 2
#define OLED_RESET 4
#define OLED128x3
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_SSD1306 OLED128X32(OLED_RESET);
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
// object initialization
HX711 scale;
#define calibration_factor 2280
#define SSD1306_LCDHEIGHT 32
void setup(){
// Use of the serial monitor to print messages or data
Serial.begin(9600);
while (!Serial);
Serial.println("start");
Wire.begin();
htu.begin();
scale.begin(scaledout, scaleclk);
scale.set_scale();
scale.tare(); //Assuming no weight on teh scale at start up, reset to 0
OLED128X32.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for 128x32)
OLED128X32.clearDisplay(); // Clear the buffer.
OLED128X32.display();
}
void displayTempHumidWeight(){
delay (20);
// Reading temperature or humidity takes about 250ms
// Sensor readings may also be up to 2 seconds in lag
float h = htu.readHumidity();
// Read temperature in Celsius
float t = htu.readTemperature();
// Read temperature as Fahrenheit
float scaleUnits = scale.get_units();
// Read load as kilograms
if (isnan(h) || isnan(t) || isnan(scaleUnits)) {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(5,0);
display.print("Couldn't read the sensor - FIX IT!");
return;
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print("Humidity: ");
display.print(h);
display.print(" %\t");
display.setCursor(0,10);
display.print("Temperature: ");
display.print(t);
display.print(" C");
display.setCursor(0,20);
display.print("weight");
display.print(scaleUnits);
display.print("kg");
}
void loop(){
displayTempHumidWeight();
display.display();
}
I suspect it’s something with the HX711 define, originally I had it at
HX711 scale(scaledout, scaleclk);
instead of HX711 scale; but kept receiving the error below:
Temp-Humidity-Load-Display-Test-2:22:32: error: no matching function for call to 'HX711::HX711(int, int)'
HX711 scale(scaledout, scaleclk);
^
In file included from D:\Arduino\2-26\Temp-Humidity-Load-Display-Test\Temp-Humidity-Load-Display-Test-2\Temp-Humidity-Load-Display-Test-2.ino:3:0:
C:\Users\Brian Fischer\Documents\Arduino\libraries\libraries\HX711-master\src/HX711.h:30:3: note: candidate: HX711::HX711()
HX711();
^
C:\Users\Brian Fischer\Documents\Arduino\libraries\libraries\HX711-master\src/HX711.h:30:3: note: candidate expects 0 arguments, 2 provided
C:\Users\Brian Fischer\Documents\Arduino\libraries\libraries\HX711-master\src/HX711.h:19:7: note: candidate: constexpr HX711::HX711(const HX711&)
class HX711
^
C:\Users\Brian Fischer\Documents\Arduino\libraries\libraries\HX711-master\src/HX711.h:19:7: note: candidate expects 1 argument, 2 provided
exit status 1
no matching function for call to 'HX711::HX711(int, int)'
However the original example code has the same line “HX711 scale(scaledout, scaleclk);” but doesn’t show those errors.