Page 1 of 1

HX711 - which lib should I use?

Posted: Fri Feb 08, 2019 6:19 am
by walterheisenberg
I connected a HX711 to my ESP32 and want to get it running. After searching the net, I found 2 libraries:

The official one here:
read, on/off, is_ready

and another one: ... mpy-driver
read, on/off, is_ready, tare, raw_read
In this lib, I had to comment in @micropython.native to get it working on the ESP32

Which one should I use? What do you recommend? Which one is better, faster?
I am new to python programming and microcontrollers, so please give me a hint
The only source I could find in this forum was this thread, which lead me to the second lib

Re: HX711 - which lib should I use?

Posted: Fri Feb 08, 2019 7:05 am
by Roberthh
Take the one that works.
I can confuse you a little bit more by pointing at another (of dozens) implementation:
The interesting part is the variant which uses SPI. It avoids the basic problem with the HX711 drivers on ESP8266 or ESP32: a low pulse of about 60 ┬Ás resets the HX711, leading to a bad result. That is hard to achieve with pin toggling py python code. Using SPI avoids that. The drawback of the SPI implementation is, that you have to define a CLK Pin, which is actually not used. The clock for the HX711 is created with the MOSI pin. I have run that SPI version for few days with 80 samples/sec, and had no invalid reading. The toggle versions had between 2% and 0.1% bad readings.
The version pointed out was made for a Pycom LoPy. Therefore you must adapt the SPI init code at the start of __init__(). There is a lot of non-core methods around, which you might ignore. The most useful of them is the read_lowpass() one, which filters out the noise, better than the read_average() method.

Re: HX711 - which lib should I use?

Posted: Sun Feb 10, 2019 4:45 pm
by walterheisenberg
Thank you for the tips. Everything is up and running without SPI for now.
What is your opinion about this:
Would it be better to replace read() with read_lowpass() in read_average()?
I want to get the average value of 3 lowpass filtered readings.

Here is another lib with different calculation: ...
Do you think this one gives better results and it is worth looking into it?

Re: HX711 - which lib should I use?

Posted: Sun Feb 10, 2019 7:29 pm
by Roberthh
It adds no value if you replace read() in read_average() with read_lowpass(). If the output of read_lowpass() is still fluctuation too much, change the time constant to a lower value.
The other lib you pointed at looks like bloatware. Practically, it returns what read_average() does, just with much more fuzz around it. And, to make it even worse, it uses the numpy lib - for calculating something trivial as the average and standard deviation.