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.