olkal / HX711_ADC

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

Erroneous data after setSamplesInUse() #46

Closed sonic74 closed 4 years ago

sonic74 commented 4 years ago

When doing

LoadCell.begin();
long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
LoadCell.setCalFactor(calibrationValue); // user set calibration value (float)
LoadCell.setSamplesInUse(1)
if (LoadCell.update()) newDataReady = true;
//get smoothed value from data set
if (newDataReady) {
  float a = LoadCell.getData();
}

I get wrong data. Shouldn't

https://github.com/olkal/HX711_ADC/blob/dff0de8503fdc335e77aef6521881ae8d5b76ae1/src/HX711_ADC.h#L112

be initialized to 0?

olkal commented 4 years ago

Hi! Initializing lastSmoothedData in the .h file should not be required as it is being assigned to a value before use (in line 258 of the .cpp file).

I'm not able to replicate an error using setSamplesInUse(1), output data is as expected. Could you please provide the complete sketch?

sonic74 commented 4 years ago

Initializing lastSmoothedData in the .h file should not be required as it is being assigned to a value before use (in line 258 of the .cpp file).

Only when calling getData() before setSamplesInUse()

olkal commented 4 years ago

You're right. I have revised the header file according to your comment, thanks.

sonic74 commented 4 years ago

Unfortunately, the missing initialisation doesn't seem to have been the culprit. As a workaround I now added refreshDataSet() after setSamplesInUse()