olkal / HX711_ADC

Arduino library for the HX711 24-bit ADC for weight scales
MIT License
235 stars 124 forks source link

tare at startup #125

Closed ilker-aktuna closed 7 months ago

ilker-aktuna commented 8 months ago

I have a weird issue.

If at startup, I do tare like: LoadCell.start(stabilizingtime, true);

it works fine. But it does tare when the device reboots (due to electricity outage) I don't want to do tare at startup. So I change it to: LoadCell.start(stabilizingtime, false);

But when I do not do tare, it does not measure correct after a reboot.

I read the saved calibration value from eprom and set it as calibration value at startup:

startup code:

 EEPROM.get(calVal_eepromAdress, calval);
  if(!(calval>0)) {
    calval=1.0;
  }
LoadCell.start(stabilizingtime, _tare);
  if (LoadCell.getTareTimeoutFlag() || LoadCell.getSignalTimeoutFlag()) {
    Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
    while (1);
  }
  else {
    LoadCell.setCalFactor(calval);
  }
  while (!LoadCell.update());
  LoadCell.setCalFactor(calval);

If I manually do a tare after reboot, it starts showing the correct value. So it surely saves calibration value and loads at startup. It just does not preserve tare at reboot. what is wrong with my code ?

olkal commented 8 months ago

Hi! You need to save the zero-offset (tare) value and restore it at reboot. See the example Persistent_zero_offset.ino.

ilker-aktuna commented 8 months ago

ok. I didn't know that. Do you have a documentation of this ? Examples are fine but from their name sometimes what it does is not understood.

olkal commented 8 months ago

No, unfortunately not. But I have now added a line in the readme file for this particular issue.

ilker-aktuna commented 8 months ago

thanks. that's better than nothing :) btw, I have another question: when there is a change of load, the getData() method does not provide the final measurement at one shot. I have to call it several times to get a good measurement. So when there is a demand for measurement, I implemented like this:

                for(int x=0;x<30;x++) {
                  boolean _resume = false;
                  while (_resume == false) {
                  if (LoadCell.update()) {
                    i = LoadCell.getData();
                    _resume = true;
                  }
                  }
                }
               finalWeight=i;

is this correct implementation?

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 7 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.