bogde / HX711

An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.
MIT License
896 stars 538 forks source link

Can't Get Readings Faster than 450ms #214

Open Dreded opened 2 years ago

Dreded commented 2 years ago

Edit: Im using a MKRZero(p1am-100)

so I have a Load cell attached to an HX711 and am wondering if the HX711 does averaging internally because despite having a delay of 250ms after putting a load on it it comes up roughly half way to the actual loaded weight and I have to wait for 500ms before getting an accurate reading.

The Code Executed...

void cycleSolenoid(int state)
{
  Serial.print("State: ");
  Serial.println(state);
  P1.writeDiscrete(state, 2, 1); //Turn slot 1 channel 2 on or off, Fire piston
  delay(250); //Wait for 250ms to allow the load cell and distance sensor to settle

  //Read Load Cell
  force = getForce("lb"); // "lb" or "kg"

  //Read 
  travel = getDistance("mm"); // "mm" or "inch" of piston travel

  //Print
  Serial.print(force);
  Serial.print(",");
  Serial.println(travel);
}

Here is My Serial Output with some comments about whats wrong

//load in lb, distance in mm

State: 0
0.19,0.40 // as expected as its been sitting in this state for 5min+ 0.4 mm is the unloaded position

State: 1
34.78,2.30 // im expecting 170 lbs and 2.3-2.7 mm(fluctuates due to stretch of material being measured so the longer the load is being applied the more it will stretch up to 2.7mm

State: 1
170.57,2.60 // called ASAP(hit 1 in rapid succession on KB) as expected

State: 1
170.87,2.70 // called ASAP(hit 1 in rapid succession on KB) as expected

State: 1
171.04,2.70 // called ASAP(hit 1 in rapid succession on KB) as expected and we can see there is no more stretch

State: 0
99.53,0.40 // the load cell is still reporting 99lbs despite the load being completely unloaded and the distance backs up the fact that its unloaded as 0.4mm is unloaded

State: 0
0.11,0.40 // 250ms later(so 500ms from initial measure) the HX711/your library now reports what's expected

As you can see 500ms is not enough time for the reading to settle, to be clear these readings are not 250ms apart(they are at least 250ms apart due to the delay but im manually typing 1 or 0 into the serial console to set state

also if you are wondering I can cycle the piston at 5Hz and it will travel its full stroke reliably(verified by camera and Distance reading)

If I set the delay to 100ms while loading I can catch the Piston mid stroke, mid stroke when unloading is under 50ms State: 1 0.25,1.80

Dreded commented 2 years ago

I found a partial answer, so while the chip runs at 10hz according to the datasheet the settling time at 10hz is 400ms and if you pull the RATE pin high the settling time is 50ms

The datasheet has this to say about settling time...

(1)Settling time refers to the time from power up, reset, input channel change and gain change to valid stable output data.

seems to me that just means the first reading should take 400ms to be stable, after that every 100ms should work.. but it doesn't, any ideas?

Of course I can just bodge in a Pullup resistor to the rate pin to make it work but this seems like it shouldn't be necessary.

the datasheet can be found here: https://www.digikey.ca/htmldatasheets/production/1836471/0/0/1/hx711.html page 3 has the relevant info