Hi, I am new to the Arduino Community and so far the amount of knowledge here is incredible. I am working on a project where I am setting up 10 load cells to measure the strength of elastics. I am using an Arduino Mega, 10x 300g Load Cells, 10x HX711 modules. I am able to wire everything up without issues and have successfully tested 1 Load cell at a time with bogde's HX711 library. I have even ran 10 instances of the simple code which works great but not quite what I am needing for this. I have come across several posts about using the HX711-multi library by compugician and I have been trying to test it out somewhat unsuccessfully.
I am testing it on the serial plotter and it works great for up to 5 Load Cells but then as soon as I add a 6'th there is a lot of static and the numbers seem to jump around a lot. Beyond 6 I don't get any readings and only 1 number shows up for any of the Load Cells: -8388607.
Maybe I am setting up the code for the 10 load cells wrong but here is my code. Any help would really be appreciated.
#include "HX711-multi.h"
// Pins to the load cell amp
#define CLK A0 // clock pin to the 10 load cell amps
#define DOUT1 A4 // data pin to the first lca
#define DOUT2 6 // data pin to the second lca
#define DOUT3 8 // data pin to the third lca
#define DOUT4 9 // data pin to the fourth lca
#define DOUT5 7 // data pin to the fifth lca
#define DOUT6 10 // data pin to the sixth lca
#define DOUT7 5 // data pin to the seventh lca
#define DOUT8 4 // data pin to the eighth lca
#define DOUT9 3 // data pin to the ninth lca
#define DOUT10 2 // data pin to the tenth lca
#define BOOT_MESSAGE "MIT_ML_SCALE V0.8"
#define TARE_TIMEOUT_SECONDS 4
byte DOUTS[10] = {DOUT1, DOUT2, DOUT3, DOUT4, DOUT5, DOUT6, DOUT7, DOUT8, DOUT9, DOUT10};
#define CHANNEL_COUNT sizeof(DOUTS)/sizeof(byte)
long int results[CHANNEL_COUNT];
HX711MULTI scales(CHANNEL_COUNT, DOUTS, CLK);
void setup() {
Serial.begin(115200);
Serial.println(BOOT_MESSAGE);
Serial.flush();
pinMode(11,OUTPUT);
}
void sendRawData() {
scales.read(results);
for (int i=0; i<scales.get_count(); ++i) {;
Serial.print( -results[i]);
Serial.print( (i!=scales.get_count()-1)?"\t":"\n");
}
delay(1000);
}
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();
}
}
}
I am testing it on the serial plotter and it works great for up to 5 Load Cells but then as soon as I add a 6'th there is a lot of static and the numbers seem to jump around a lot. Beyond 6 I don't get any readings and only 1 number shows up for any of the Load Cells: -8388607.
Does that apply to the combination of hardware and software or is it just the software. What I mean: if you connect all 10 load cells but have only 5 in the software, does it work or does it fail?
I cannot find a limitation in the software that would explain that behavior. Please post a complete wiring diagram of your setup.
Find out whether the library supports 10 load cells on the Uno. Cofigure for 10 channels but measure only one channel in loop(). Does it work?
Move the delay into the for loop and make it long enough so that the serial data are transmitted. Or, better, check Serial.availableForWrite() before advancing to the next channel.
Good points raisie above to follow up on, exactly the questions I would have asked/carried out, including basics like power supply integrity for the multiple load cells.
The multi library seems to be a bit old, not recently updated, so very possibly hasn't been developed/tested to the stage of 4-5+ load cells. There is interesting discussion here https://github.com/bogde/HX711/issues/35#issuecomment-422836688, where the problem seems to be that the HX's are converting asynchronously, and the multi code may not catch each device as it is ready everytime - the problem would get worse the more there are to read with one clock line.
Although it increases the amount of clock pins, if there is no apparent way of reading 4-5+ cells/HX711's reliably with changes to the multi code, perhaps 1 extra clock line could be used to read 2x5 cells at a time, a decent compromise compared to having 10 clock lines and instances. At least a Mega has a high pin count so should have pins available if not used for other purpose. Although you have tried 10 instances, and it is not what you need for this project, apart from perhaps cycle time what is the main objection to multiple instances?
Another possibility could be to distribute out some intelligence to each HX711 with say an AtTiny, to convert and hold each conversion for sending - a bit of a project in itself though with decisions to be made on the hardware comms, syncing and protocol.