HX711 Calibration with Power-Gating

Hello again,

In May 2024 I presented myself to this forum with my scale set-up.
Limited time and real life matters stopped me to further work on the project. Also I got a bear messing with my bees.

I’m sharing below my findings during the HX711 calibration.

My Hivemon Scale set-up is using Grafana Cloud at the moment because I have only one scale prototype. My intention is to build a few more and use InfluxDb and Grafana as local instances on my home server.

In the mean time I did some updating to the set-up:
Adding HX711 disconnect feature.
Adding median filtering on the HX711 reads.

But of course I suppose all these were already covered in the forum.
I think it would be useful to explain my problem with the scale and the solution I found.

Problem:
I observed a difference between the weight reported with the “calibration-sketch” and the weight reported by the “main-firmware” later.
For me as a beginnner in electronics and programming, it was like searching a needle in a haystack.

Initially the calibration was done with a simple sketch, the “calibration-sketch”, the circuit was powered by USB continuosly and the OFFSET and the SCALE_FACTOR parameters were read directly and then hardcoded into the “main-firmware”. In this operating conditions both parameters seemed to be correct, and the weight reported was ok.

In the “main-firmware”, HX711 is not working in the same “continuous power supply” regime. By design I want my sensor to be low-power (because I’m using a PV and 2X 18650 batteries). Basically HX711 power supply is controlled by a P-MOS controlled by the ESP32 pin (Deep-Sleep cycle and wake-up at 15mins). So HX711 sleeps 15 mins and is woken up only before measurement. After power-up, the module needs time to stabilize and the first measurements can be unstable.

Because of this, calibration values obtained in the simple “calibration-sketch” does not corresponded with the real operating conditions of the HX711 from the “main”. Basically in the the weight reported by the “main” sketch was not correct. I had no ideea that the operating conditions matters so much for the calibration.

Solution:
The calibration procedure must reproduce exactly the operating steps of the “main” firmware (below is the updated “calibration-sketch” with the actual timings):

  1. sensorPowerOn() from ESP32 pin
  2. delay pentru power-on stabilisation through P-MOS
  3. HX711 initialisation - initHX711()
  4. scale.power_up()
  5. delay for HX711 stabilisation
  6. discard first unstable readings
  7. RAW read no weight
  8. RAW read with a known weight
  9. OFFSET and SCALE_FACTOR parameters calculation

In this way the calibration is done in the same conditions as the normal sensor operation. Active power-gating, same stabilisation delays, same start-up sequence and same discarding of the first readings.

After this change the OFFSET and SCALE_FACTOR parameters became “compatible” with the “main-firmware”, and the weight reported started to correspond to the real weight.

Conclusion:
The HX711 calibration should not be done in an “idealized” operating regime, with the HX711 continously powered, but in the actual operating regime of the scale using same power-gating, delays and read sequence.

Additional findings:

  1. My scale support set-up is quite heavy (I use 50X30 mm steel squares for the double H support- probably 15kg) so initially I thought that the manipulation of the support between calibration and positioning at the beehives location is causing the weight errors. Actually this should not be a problem, I have a 50g difference after the support manipulation, so no issues from that.

  2. I changed a few HX711 modules (keeping the same calibration parameters) to see if there is a change of the readings, it is but minor, some 10 grams difference, probably for some modules will be bigger.

  3. On every internet source I searched it says that HX711 24bit ADC is very sensible and the readings can be affected if it sits close to the ESP32 WIFI antenna. In my set-up HX711 sits within 1cm distance to the ESP32, the readings are fine once the calibration is done correctly.

Thank you for reading this long post.
I hope this helps.

Please feel free to ask any questions, I’ll try to answer the best I can.

Best wishes,
Octavian

1 Like

Many thanks, @Octavian, for your report. I experienced the same problems when I first started working with scales and the HX711: I set up a calibration script, collected values for loadCell.set_scale() and loadCell.set_offset(), copy’a’pasted them into the main sketch – and … argh … – it did not work as expected.

After that, I created a line chart of the values and noticed a slight trend over time. At certain point, the values stabilized. That made me realize the influence of time and temperature during the calibration process.

So I introduced a pause of 3 seconds after every single measurement, and voilà – the calibration values worked correctly in the main sketch! Pretty much the same learning curve you described.

By the way, I don’t think a P-MOSFET is necessary to completely cut power to the HX711. From my observations, loadCell.power_down() should be sufficient.

Btw I’m using this calibration sketch in case you’re interested:

[edit] As you may have noticed, in the adjustment sketch I recommend applying a baseline load (~1 kg) to the scale. The reason for this was that I had been testing with load cells and only a bit of aluminum extrusion, see Open Hive "Scale Bar" for Single Side Weighting, which weighs almost nothing. With this adjustment – using a baseline load – I obtained more reliable calibration values ​​than I did with a completely unloaded load cell. However, in a “heavy lifting” scenario like yours, involving a heavy frame for the load cell, this is, of course, not necessary.

1 Like

Hello Clemens,

Thank you for your advices.

Actually I looked over the Open Hive calibration script. What I did not like is that it is interactive, mine is on a waiting timer for switching the weight (10 sec). On the other hand Open Hive is using RunningMedian witch is better than mine, I just use average (probably I have to change this).

Open Hive uses the HX711 functions to induce a low-power operation between reads, I’m actually switching off the HX711 power through a P-MOS pin.

But I probably update the calibtration code with the RunningMedian and the print-out of the readings statistics.

Curently I’m building another 3 scales (total of four), soldering the components.

I still have to buy the BOSCHE loadcells, and put toghether the loadcells frames. There is some work to be done.

Thank you,

Octavian

1 Like