Cannot make working HX711 24bit ADC with Imp

Hi All,

I am playing with my home project where I use weight cell to measure weight. I am using external ADC HX711. Here is a doc http://www.dfrobot.com/image/data/SEN0160/hx711_english.pdf . It comes with a simple code example, and it works fine with arduino.

Here is a code I used for Arduino:
`#define PD_SCK A2
#define DOUT A3

void setup(){
Serial.begin(9600);
pinMode(PD_SCK, OUTPUT);
pinMode(DOUT, INPUT);
digitalWrite(PD_SCK, LOW);
}
void loop(){
Serial.println(read());
delay(500);
}

bool is_ready() {
return digitalRead(DOUT) == LOW;
}

long read() {
// wait for the chip to become ready
while (!is_ready());

unsigned long Count;
unsigned char i;
Count = 0;
// pulse the clock pin 24 times to read the data
for (i=0; i<24; i++) {
digitalWrite(PD_SCK, HIGH);

if(digitalRead(DOUT) > 0){
  Count++;
}
digitalWrite(PD_SCK, LOW);
Count=Count<<1; 

}

digitalWrite(PD_SCK, HIGH);
digitalWrite(PD_SCK, LOW);
Count=Count^0x800000;
return Count;
}`

and here is an output I get:

11788148
11788334
11794016
11790056
11790494
11790600
11791018
11790966
11791484
11791760

Then I played with imp for a lot, but still cannot make it working, it always shows the same data and doesn;tmater if I put something on a scales.

Here is simple code:

`const HIGH = 1;
const LOW = 0;

DOUT <- hardware.pin8;
PD_SCK <- hardware.pin9;
PD_SCK.configure(DIGITAL_OUT);
DOUT.configure(DIGITAL_IN);

server.log(“start”);

PD_SCK.write(LOW);
imp.sleep(0.000001);

function ReadCount(){

local count = 0;
while(!DOUT.read());

for (local i=0; i < 24; i++){
PD_SCK.write(HIGH);

if(DOUT.read() > 0) { 
    count++; 
}
PD_SCK.write(LOW); 
count = count << 1;
}

PD_SCK.write(HIGH);
PD_SCK.write(LOW); 
count=count^0x800000; 
return count; 

}

for (local j=0; j<5; j++){
server.log(ReadCount());
}
server.log(“end”);
`

and output just next:

2014-06-18 21:25:00 UTC-7 [Device] start
2014-06-18 21:25:00 UTC-7 [Device] 8388606
2014-06-18 21:25:00 UTC-7 [Device] 25165822
2014-06-18 21:25:00 UTC-7 [Device] 25165822
2014-06-18 21:25:00 UTC-7 [Device] 25165822
2014-06-18 21:25:00 UTC-7 [Device] 25165822
2014-06-18 21:25:00 UTC-7 [Device] end

I read hx711 documents lots of times to understand what I am doing wrong. I tried to put some sleep in microseconds according to doc, but it didn’t help.

Any ideas how to make it working? I am completely lost and cannot find a right path. Any help appreciated.

Definitely strange, because the numbers you are getting there have more than 24 bits, which doesn’t make much sense looking at your code.

8388606 = 0x7ffffe (ok, that one is 24 bits)
25165822 = 0x17ffffe (25 bits?)

What voltage are you running the chip at?

One thing I did notice is that arduino driver reads the data line when the clock is high, whereas the datasheet reads the data line when the clock is low. Either should be fine (as long as you’re 0.1us from the edge, time T2 in the datasheet) but just a bit strange.

You should also put a delay inbetween readings, because more than one reading per conversion cycle confuses the chip, supposedly. The ardino is waiting half a second and the imp isn’t waiting at all. Not nice for a final progra, but an imp.sleep(0.5) at the top of ReadCount() is probably worth a try.

Thanks for reply Hugo.

I am using 5v that go to imp and HX711.

I added sleep for 0.5s in read count and also change line to read data according to a datasheet:

`function ReadCount(){
imp.sleep(0.1);
local count = 0;
while(!DOUT.read());

for (local i=0; i < 24; i++){
PD_SCK.write(HIGH);
count = count << 1;
PD_SCK.write(LOW);
if(DOUT.read() > 0) {
count++;
}
imp.sleep(0.00001);
}

PD_SCK.write(HIGH);
count=count^0x800000;
PD_SCK.write(LOW); 
return count; 

} `

I’ve got data, but it doesn’t look stable though:

2014-06-19 11:37:04 UTC-7 [Device] 10095497
2014-06-19 11:37:04 UTC-7 [Device] 10095408
2014-06-19 11:37:05 UTC-7 [Device] 10095440
2014-06-19 11:37:05 UTC-7 [Device] 10095430
2014-06-19 11:37:05 UTC-7 [Device] 9242019
2014-06-19 11:37:05 UTC-7 [Device] 10095447
2014-06-19 11:37:05 UTC-7 [Device] 9242017
2014-06-19 11:37:06 UTC-7 [Device] 9241994
2014-06-19 11:37:06 UTC-7 [Device] 9242016
2014-06-19 11:37:06 UTC-7 [Device] 9242008
2014-06-19 11:37:06 UTC-7 [Device] 9241985
2014-06-19 11:37:06 UTC-7 [Device] 9242029
2014-06-19 11:37:06 UTC-7 [Device] 9241987
2014-06-19 11:37:07 UTC-7 [Device] 9241986
2014-06-19 11:37:07 UTC-7 [Device] 9241983
2014-06-19 11:37:07 UTC-7 [Device] 9242006
2014-06-19 11:37:07 UTC-7 [Device] 9241995
2014-06-19 11:37:07 UTC-7 [Device] 9242032
2014-06-19 11:37:08 UTC-7 [Device] 10095393
2014-06-19 11:37:08 UTC-7 [Device] 10095453
2014-06-19 11:37:08 UTC-7 [Device] 10095436
2014-06-19 11:37:08 UTC-7 [Device] 9242048
2014-06-19 11:37:08 UTC-7 [Device] 10095389
2014-06-19 11:37:08 UTC-7 [Device] 10095384

You’re almost certainly not waiting half a second between readings (and your code says 0.1), looking at the timestamps on those log messages?

I’d be worried that the imp wifi transmit might be coupling onto the strain gauge hookup. Can you move the imp much further away and see if it’s more stable?

You're almost certainly not waiting half a second between readings (and your code says 0.1), looking at the timestamps on those log messages?

This is because I played a little bit with different values and didn’t realize any difference between 0.1 and 0.5 second.

I'd be worried that the imp wifi transmit might be coupling onto the strain gauge hookup. Can you move the imp much further away and see if it's more stable?

You mean away from a wifi AP? or from ADC?

From the ADC. The imp is pumping RF energy out which is very likely coupling onto the sensitive high impedance wires from the strain gauge to the ADC.

@ilyanesterov ,Did you able to make the code working? can you share the circuit diagram for reference.

Did you take a look here? https://community.electricimp.com/blog/imp-load-cells/

Look at page 10.41 in this document - I have used it to get rid of noise pickup from Variable speed motor drives on an AD7792.

http://www.analog.com/media/en/training-seminars/design-handbooks/173574898sscsect10.PDF

Hi!
I am trying to read the XH711 from the imp and having same kind of issues.
Did you manage to solve the problem?

I am looking for some working code but I cannot find any

Working code is here: https://gist.github.com/bbharris/53f4351af704867b4df0

We lost the post from our blog, but it’s in the archive here: https://web.archive.org/web/20160606084340/https://community.electricimp.com/blog/imp-load-cells/