Is there a flaw in HX711_ADC?

I am using the library HX711_ADC v1.2.12

While researching the well-known weight-drift issue and trying to understand the library I found this code:

/*  start(t): 
*	will do conversions continuously for 't' +400 milliseconds (400ms is min. settling time at 10SPS). 
*   Running this for 1-5s in setup() - before tare() seems to improve the tare accuracy */
void HX711_ADC::start(unsigned long t)
{
	t += 400;
	lastDoutLowTime = millis();
	while(millis() < t) 
	{
		update();
		yield();
	}
	tare();
	tareStatus = 0;
}

where t is the "stabilizing time".

Using the value suggested in the examples (2000ms), the while loop condition becomes

	millis() < 2400

which will always be false after a couple of seconds once the program starts running and the while loop becomes meaningless. Also, if other setup activities take longer than 2.4s before this function is first called, the while loop will never be executed.


I believe it should rather be something like

millis() -lastDoutLowTime < t

Am I missing something here?


(lastDoutLowTime should not be modified by this function, but that is a separate issue)

I suppose that the logic here is this - the scales are powered immediately after switching controller on, so the drift starts at millis = 0. If you enter this function after a few seconds because something else is happening in your setup, then you don’t need to wait an additional 2 seconds.

Although you can change the line as you suggest at see what happened...

Sparkfun seems to suggest here turning on the HX711 only when a read is due. In this case, millis would be much greater along the way