When code is running my load cells will not read anything other than 0, below is what my project looks like with the code and wiring. Any help would be appreciated!
#include <HX711_ADC.h>
// Define pins for HX711 connections
const int SCK_pins[] = {5, 7, 9, 11}; // SCK connections
const int DT_pins[] = {4, 6, 8, 10}; // DT connections
// Create HX711_ADC objects for each load cell
HX711_ADC LoadCell_1(DT_pins[0], SCK_pins[0]);
HX711_ADC LoadCell_2(DT_pins[1], SCK_pins[1]);
HX711_ADC LoadCell_3(DT_pins[2], SCK_pins[2]);
HX711_ADC LoadCell_4(DT_pins[3], SCK_pins[3]);
void setup() {
Serial.begin(9600);
Serial.println("Calibration Example");
// Initialize Load Cells
LoadCell_1.begin();
LoadCell_2.begin();
LoadCell_3.begin();
LoadCell_4.begin();
// Tare each load cell
LoadCell_1.tare();
LoadCell_2.tare();
LoadCell_3.tare();
LoadCell_4.tare();
Serial.println("Press 't' to tare.");
Serial.println("Then, press 'c' to calibrate.");
}
void loop() {
// Check for commands from serial monitor
if (Serial.available() > 0) {
char command = Serial.read();
if (command == 't') {
Serial.println("Taring...");
tareLoadCells();
Serial.println("Tare complete.");
} else if (command == 'c') {
Serial.println("Calibrating...");
calibrateLoadCells();
Serial.println("Calibration complete.");
}
}
// Read and print the load cell values
Serial.print("Load Cell 1: ");
Serial.print(LoadCell_1.getData(), 2);
Serial.print(" Load Cell 2: ");
Serial.print(LoadCell_2.getData(), 2);
Serial.print(" Load Cell 3: ");
Serial.print(LoadCell_3.getData(), 2);
Serial.print(" Load Cell 4: ");
Serial.println(LoadCell_4.getData(), 2);
}
void tareLoadCells() {
LoadCell_1.tare();
LoadCell_2.tare();
LoadCell_3.tare();
LoadCell_4.tare();
}
void calibrateLoadCells() {
Serial.println("Calibration complete. Load cells are now calibrated.");
}
this is the color of wires from load cells
DaveX
November 13, 2023, 8:11pm
3
Does the library sample script work on any of the individual cells?
/*
-------------------------------------------------------------------------------------
HX711_ADC
Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales
Olav Kallhovd sept2017
-------------------------------------------------------------------------------------
*/
/*
Settling time (number of samples) and data filtering can be adjusted in the config.h file
For calibration and storing the calibration value in eeprom, see example file "Calibration.ino"
The update() function checks for new data and starts the next conversion. In order to acheive maximum effective
sample rate, update() should be called at least as often as the HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS.
If you have other time consuming code running (i.e. a graphical LCD), consider calling update() from an interrupt routine,
see example file "Read_1x_load_cell_interrupt_driven.ino".
This is an example sketch on how to use this library
*/
This file has been truncated. show original
Now that I try that, same thing 0's across the board. Measured resistance across each pair of wires and get around 500 ohms. Measured voltage across Vcc and Gnd and get 5.2V on each amplifier. Double checked proper wiring. This is the error I get below with new code,
#include <HX711_ADC.h>
#if defined(ESP8266) || defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
// Pins
const int HX711_dout_1 = 4; // MCU > HX711 no 1 dout pin
const int HX711_sck_1 = 5; // MCU > HX711 no 1 sck pin
const int HX711_dout_2 = 6; // MCU > HX711 no 2 dout pin
const int HX711_sck_2 = 7; // MCU > HX711 no 2 sck pin
const int HX711_dout_3 = 8; // MCU > HX711 no 3 dout pin
const int HX711_sck_3 = 9; // MCU > HX711 no 3 sck pin
const int HX711_dout_4 = 10; // MCU > HX711 no 4 dout pin
const int HX711_sck_4 = 11; // MCU > HX711 no 4 sck pin
// HX711_ADC objects
HX711_ADC LoadCell_1(HX711_dout_1, HX711_sck_1);
HX711_ADC LoadCell_2(HX711_dout_2, HX711_sck_2);
HX711_ADC LoadCell_3(HX711_dout_3, HX711_sck_3);
HX711_ADC LoadCell_4(HX711_dout_4, HX711_sck_4);
const int calVal_eepromAddress = 0;
// Function declaration
void changeSavedCalFactor();
void setup() {
Serial.begin(57600);
delay(10);
Serial.println();
Serial.println("Starting...");
// Initialize Load Cells
LoadCell_1.begin();
LoadCell_2.begin();
LoadCell_3.begin();
LoadCell_4.begin();
// Tare each load cell
LoadCell_1.tare();
LoadCell_2.tare();
LoadCell_3.tare();
LoadCell_4.tare();
Serial.println("Startup is complete");
while (!LoadCell_1.update() || !LoadCell_2.update() || !LoadCell_3.update() || !LoadCell_4.update());
calibrate(); // Start calibration procedure
}
void loop() {
static boolean newDataReady = false;
static unsigned long t = 0;
const int serialPrintInterval = 0;
// Check for new data/start next conversion
if (LoadCell_1.update() && LoadCell_2.update() && LoadCell_3.update() && LoadCell_4.update())
newDataReady = true;
// Get smoothed value from the dataset
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
float val_1 = LoadCell_1.getData();
float val_2 = LoadCell_2.getData();
float val_3 = LoadCell_3.getData();
float val_4 = LoadCell_4.getData();
Serial.print("Load Cell 1: ");
Serial.print(val_1, 2);
Serial.print(" Load Cell 2: ");
Serial.print(val_2, 2);
Serial.print(" Load Cell 3: ");
Serial.print(val_3, 2);
Serial.print(" Load Cell 4: ");
Serial.println(val_4, 2);
newDataReady = false;
t = millis();
}
}
// Receive command from serial terminal
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') {
LoadCell_1.tareNoDelay();
LoadCell_2.tareNoDelay();
LoadCell_3.tareNoDelay();
LoadCell_4.tareNoDelay();
} else if (inByte == 'r') {
calibrate();
} else if (inByte == 'c') {
changeSavedCalFactor();
}
}
// Check if the last tare operation is complete
if (LoadCell_1.getTareStatus() && LoadCell_2.getTareStatus() && LoadCell_3.getTareStatus() && LoadCell_4.getTareStatus()) {
Serial.println("Tare complete");
}
}
void calibrate() {
Serial.println("***");
Serial.println("Start calibration:");
Serial.println("Place the load cells on a level stable surface.");
Serial.println("Remove any load applied to the load cells.");
Serial.println("Send 't' from the serial monitor to set the tare offset.");
boolean _resume = false;
while (!_resume) {
LoadCell_1.update();
LoadCell_2.update();
LoadCell_3.update();
LoadCell_4.update();
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') {
LoadCell_1.tareNoDelay();
LoadCell_2.tareNoDelay();
LoadCell_3.tareNoDelay();
LoadCell_4.tareNoDelay();
}
}
if (LoadCell_1.getTareStatus() && LoadCell_2.getTareStatus() && LoadCell_3.getTareStatus() && LoadCell_4.getTareStatus()) {
Serial.println("Tare complete");
_resume = true;
}
}
Serial.println("Now, place a known mass of 907 grams on the load cells.");
Serial.println("Then send 'c' from the serial monitor to start calibration.");
float known_mass = 0;
while (known_mass != 907.0) {
LoadCell_1.update();
LoadCell_2.update();
LoadCell_3.update();
LoadCell_4.update();
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 'c') {
LoadCell_1.refreshDataSet();
LoadCell_2.refreshDataSet();
LoadCell_3.refreshDataSet();
LoadCell_4.refreshDataSet();
float newCalibrationValue = (LoadCell_1.getNewCalibration(known_mass) +
LoadCell_2.getNewCalibration(known_mass) +
LoadCell_3.getNewCalibration(known_mass) +
LoadCell_4.getNewCalibration(known_mass)) / 4.0;
Serial.print("New calibration value has been set to: ");
Serial.println(newCalibrationValue);
Serial.print("Save this value to EEPROM address ");
Serial.print(calVal_eepromAddress);
Serial.println("? y/n");
boolean _save = false;
while (!_save) {
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 'y') {
#if defined(ESP8266) || defined(ESP32)
EEPROM.begin(512);
#endif
EEPROM.put(calVal_eepromAddress, newCalibrationValue);
#if defined(ESP8266) || defined(ESP32)
EEPROM.commit();
#endif
EEPROM.get(calVal_eepromAddress, newCalibrationValue);
Serial.print("Value ");
Serial.print(newCalibrationValue);
Serial.print(" saved to EEPROM address: ");
Serial.println(calVal_eepromAddress);
_save = true;
} else if (inByte == 'n') {
Serial.println("Value not saved to EEPROM");
_save = true;
}
}
}
Serial.println("End calibration");
Serial.println("***");
break;
}
}
}
}
// Function definition
void changeSavedCalFactor() {
// This function is the same as in the previous example, make sure it's included here.
// ...
}
DaveX
November 13, 2023, 9:23pm
5
I'd go with a stock sample code for just one of your HX711s and cells. Then you know if it is or isn't the code, and whether the the fault lies in the hardware or not.
Thanks for advice, I tested each load cell individually and they all gave me a reading of 0. I think I might resolder my amplifiers?
system
Closed
May 11, 2024, 9:33pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.