Hello. My project uses an ESP-32 Thing Microprocessor connected to 10 load sensors (TAL220 connected via HX711 load cell amplifier). The project has two circuit boards (one mounted above the other) with jacks to connect five load cells on each board. Each bank of five loadcells shares a common clock.
The library I have used is the HX711-multi (source: [GitHub - compugician/HX711-multi: An Arduino library to interface multiple HX711 units simultaneously]) which enables multiple load cells to share a common clock line.
I have used this library extensively with two instances of the 'HX711MULTI' class declared and no problems.
I needed to update the code (nothing related to the load sensors) and now the code only works when one instance of the HX711MULTI class is declared and I don't know why.
I have adapted the example script from the HX711-multi library to try and work out the problem and have not been able to solve it. The test code is below.
#include "HX711-multi.h"
// Pins to the load cell amp
#define CLK_BOTTOM 32 // clock pin for bottom bank of load cells
#define DOUT_A 35 // data pin to the first lca
#define DOUT_B 34 // data pin to the second lca
#define DOUT_C 39 // data pin to the third lca
#define DOUT_D 38 // data pin to the second lca
#define DOUT_E 37 // data pin to the third lca
#define CLK_TOP 15 // clock pin for top bank of load cells
#define DOUT_F 36 // Loadcell F data pin
#define DOUT_G 0 // Loadcell G data pin
#define DOUT_H 4 // Loadcell H data pin
#define DOUT_I 17 // Loadcell G data pin
#define DOUT_J 16 // Loadcell H data pin
#define BOOT_MESSAGE "MIT_ML_SCALE V0.8"
#define TARE_TIMEOUT_SECONDS 4
byte DOUTS_BOTTOM[5] = {DOUT_A, DOUT_B, DOUT_C, DOUT_D, DOUT_E};
byte DOUTS_TOP[5] = {DOUT_F, DOUT_G, DOUT_H, DOUT_I, DOUT_J};
#define CHANNEL_COUNT_BOTTOM sizeof(DOUTS_BOTTOM)/sizeof(byte)
#define CHANNEL_COUNT_TOP sizeof(DOUTS_TOP)/sizeof(byte)
long int results[CHANNEL_COUNT_BOTTOM];
HX711MULTI scales_bottom(CHANNEL_COUNT_BOTTOM, DOUTS_BOTTOM, CLK_BOTTOM);
//HX711MULTI scales_top(CHANNEL_COUNT_TOP, DOUTS_TOP, CLK_TOP);
void setup() {
Serial.begin(9600);
Serial.println(BOOT_MESSAGE);
Serial.flush();
//pinMode(11,OUTPUT);
tare();
}
void tare() {
bool tareSuccessful = false;
unsigned long tareStartTime = millis();
while (!tareSuccessful && millis()<(tareStartTime+TARE_TIMEOUT_SECONDS*1000)) {
tareSuccessful = scales_bottom.tare(20,10000); //reject 'tare' if still ringing
}
}
void sendRawData() {
scales_bottom.read(results);
for (int i=0; i<scales_bottom.get_count(); ++i) {;
Serial.print( -results[i]);
Serial.print( (i!=scales_bottom.get_count()-1)?"\t":"\n");
}
delay(10);
}
void loop() {
sendRawData(); //this is for sending raw data, for where everything else is done in processing
//on serial data (any data) re-tare
if (Serial.available()>0) {
while (Serial.available()) {
Serial.read();
}
tare();
}
delay(5000);
}
The code compiles no problems with either one or both HX711MULTI classes declared.
When one of the HX711MULTI classes is commented out, the code works as expected on the Serial Monitor (i.e. prints values for five load cells every 5s).
When both HX711MULTI classes are defined, the Serial Monitor displays the following:
BlockquoteӔn⸮fg⸮⸮R⸮⸮fg⸮Ӓ~⸮fg⸮R~⸮f⸮⸮⸮R~⸮f⸮
The ESP32 appears to shutdown and restart every few seconds with a new string as shown above displayed on the Serial Monitor.
I am a bit stumped, as this code worked fine previously with two declarations of the HX711-MULTI class. I don't know what has changed.