Ever since I got my Borons 6 months ago, I’ve been having trouble getting good stable readings from my HX711 weigh sensors. With my Electrons, the readings were always rock-solid. This is a typical example of measurements using the HX711ADC library where I’m averaging 20 readings (constant weight, but no offset applied).
When I reduce the number of times the data are averaged to 1 (i.e. no averaging), the output is considerably more stable, but the outliers are greatly exacerbated (constant weight, offset applied). Clearly the risk of a bad data point increases with the number of reads.
I have investigated many possible causes, incl.:
RF interference. I’ve experimented with placing the antenna at increasing distances from the Boron, incl fitting external antennas up to 3m away. No difference.
Tried different Borons (six) – no difference
Tried different HX711 ADC’s (eight) – no difference
Tried different strain gauges (six) – no difference
Tried different libraries (both Particle community libraries as well as a library I uploaded myself. Used standard example code too – no difference
Tried slowing down the rate at which bits are clocked in. This is apparently a problem with MCUs which have fast clock speeds (see here). However, as I understand it, the Boron’s clock speed is slower than the Electron (64MHz vs 120MHz resp)? In any case, adding extra 1ms delays between clocking in bits did not stop the outliers.
Tried swapping pins on the Borons (from D3 and D4 to A2 and A3) - no difference
Tried filtering out bad data points with an IF statement. That helped considerably but new bad values still occur, and besides, this doesn’t get to the root of the problem.
At this stage, I’m out of ideas as to what could be causing the outliers and what the fix might be. Has anyone else been having problems with Boron and HX711 outliers? Any help greatly appreciated!
I don’t have a definitive cause or solution yet, but thanks to @blub, I do have an adequate work around. The work around involves using median values to effectively filter out the spikes. See post #46647.
Some sample data to show how well it works:
I believe I’m having the same issue, but I’m using an Argon instead of a Boron. I discovered the fast clock speed post as well before finding this thread, but like you, when I tried the adding the delays, it didn’t help.
I’m at the point where I’m filtering out the extremely bad data points with an if statement, but it still would be better to get this solved.
Have you tried wiring the sensor with a shielded cable and connecting the drain (bare, usually silver colored) wire only at one end to ground? This is designed to EM interference to ground.
Thanks for the suggestion. No, I haven’t tried a shielded cable yet. At this point, I’m actually suspecting the HX711 is getting into a bad state, because when I see a bad reading, it takes several hundred milliseconds longer before the ready signal is asserted again.
I think the next step needs to be check the signals with a scope to see what is happening.
Maybe someone here can get to the bottom of this. I am experiencing the same problem for months now. I have put a bandage ever the problem with a median calculation, but I am unhappy with the bug. I have tested the code I am using separately on an Arduino Uno and I get perfect results. Once I replace the Arduino with my Boron, the bug emerges.
For anyone experienced with the HX711 library, I have made an observation which may point towards the problem: The time it takes to take the reading increases while reporting a bogus data point. Please see the attached image.
This Output was regenerated using this short Code:
#include <HX711ADC.h>
#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT 3
#define CLK 2
HX711ADC scale;
long time1 = 0;
void setup() {
Serial.begin(9600);
Serial.println("HX711 scale demo");
scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
Serial.println("Readings:");
}
void loop() {
time1 = millis();
Serial.print(" Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
Serial.print(" kg Time to take reading = "); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.print(millis() - time1);
Serial.println();
}
Can anyone give me a few suggestions as to how to address this?
Thanks.