Read 5 hx711 load cell values

Hi all,

I am trying to use 5 hx711 load cells for a project and everything works using following library when I use 3 load cells but I get strange readings when I use 4 load cells.

when I change following:

byte DOUTS[3] = {DOUT1, DOUT2, DOUT3};

to:

byte DOUTS[5] = {DOUT1, DOUT2, DOUT3, DOUT4, DOUT5};

I am guessing there's a problem with not being able to read 5 cells fast enough.

Here is the function that I think needs to be changed in HX711-multi.cpp:

void HX711MULTI::readRaw(long *result) {
	int i,j;
	// wait for all the chips to become ready
	while (!is_ready());

	// pulse the clock pin 24 times to read the data
	for (i = 0; i < 24; ++i) {
		digitalWrite(PD_SCK, HIGH);
		if (NULL!=result) {
			for (j = 0; j < COUNT; ++j) {
				bitWrite(result[j], 23-i, digitalRead(DOUT[j]));
			}
		}
		digitalWrite(PD_SCK, LOW);
	}
   
	// set the channel and the gain factor for the next reading using the clock pin
	for (i = 0; i < GAIN; ++i) {
		digitalWrite(PD_SCK, HIGH);
		digitalWrite(PD_SCK, LOW);
	}

    // Datasheet indicates the value is returned as a two's complement value, so 'stretch' the 24th bit to fit into 32 bits. 
    if (NULL!=result) {
	    for (j = 0; j < COUNT; ++j) {
	    	if ( ( result[j] & 0x00800000 ) ) {
	    		result[j] |= 0xFF000000;
	    	} else {
	    		result[j] &= 0x00FFFFFF; //required in lieu of re-setting the value to zero before shifting bits in.
	    	}
	    } 

    }
}

Please post the full code that you are using to read 5 cells

I am using the sample code at HX711-multi.ino

but reading 5douts instead of 3 douts.

Please post your actual code here not a link to some code that is not actually what you are running

It's the actual code. There is no point posting the entire code if it's %90 the same. I posted what I have changed which is one line.

The problem is also the library I am using and not my code.

Here is the code However:

#include "HX711-multi.h" // Pins to the load cell amp 
#define CLK 2 // clock pin to the load cell amp 
#define DOUT1 3 // data pin to the first lca 
#define DOUT2 4 // data pin to the second lca 
#define DOUT3 5
#define DOUT4 6 // data pin to the 4th lca
#define DOUT5 7
#define BOOT_MESSAGE "MIT_ML_SCALE V0.8" 


#define TARE_TIMEOUT_SECONDS 4 

byte DOUTS[5] = {DOUT1, DOUT2, DOUT3,DOUT4,DOUT5}; 

#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); 
tare(); 
}

 void tare() { 
bool tareSuccessful = false; 
unsigned long tareStartTime = millis(); 
while (!tareSuccessful && millis()<(tareStartTime+TARE_TIMEOUT_SECONDS*1000)) { 

tareSuccessful = scales.tare(20,10000); //reject 'tare' if still ringing 
} } 

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(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(); 
} 
}

just a thought... could it be a power issue?

I mean if it works for 3 but not 5, it could that your Vcc supply which powers ALL the load cells may not be able to drive more than 3 load cells at a time...

milador:
It's the actual code. There is no point posting the entire code if it's %90 the same.

Quite the contrary, there's no point posting anything but the exact code that is failing. Trust us on this,
the problem can be anywhere, a single misplaced comma, anything, having something that's not genuine
leads to confusion and wasted time.

The problem is also the library I am using and not my code.

I wish that I had your confidence

Can't see anything obvious with the code. I had a look at the HX711-multi library and I think its fast enough
for the timing constraints in the HX711 datasheet - putting a 'scope on the pins is the only sure way to check this.

You have a millis() roll-over bug in your tare() function but that's not the issue here. My guess is this is
hardware related, either too much load capacitance on the clock pin (long cables?), or power issue (not so
likely) or a faulty HX711.

So I am using a separate power supply for load cells. It could be hardware issues for sure but I did a test by using the same DOUT pin 5 times and I run to same issue.

I was wondering if anyone has ran to this problem otherwise I will need to make my own read function or use Hx711 library instead but there will be too many wires which can cause noise.

I have a feeling it's a formatting issue with the array. So I do some few more tests before going toward my own implementation.

Thanks all for trying to help:)