HX711 - which lib should I use?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
walterheisenberg
Posts: 6
Joined: Sun Jan 27, 2019 11:50 am

HX711 - which lib should I use?

Post by walterheisenberg » Fri Feb 08, 2019 6:19 am

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: https://github.com/SergeyPiskunov/micropython-hx711
Features:
read, on/off, is_ready

and another one:
https://github.com/HowManyOliversAreThe ... mpy-driver
Features:
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
Thx

User avatar
Roberthh
Posts: 1210
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: HX711 - which lib should I use?

Post by Roberthh » Fri Feb 08, 2019 7:05 am

Take the one that works.
I can confuse you a little bit more by pointing at another (of dozens) implementation: https://github.com/robert-hh/hx711-lopy.
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.

walterheisenberg
Posts: 6
Joined: Sun Jan 27, 2019 11:50 am

Re: HX711 - which lib should I use?

Post by walterheisenberg » Sun Feb 10, 2019 4:45 pm

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.
Thx

Here is another lib with different calculation:
https://github.com/Honey-Pi/rpi-scripts ... 11.py#L331
Do you think this one gives better results and it is worth looking into it?

User avatar
Roberthh
Posts: 1210
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: HX711 - which lib should I use?

Post by Roberthh » Sun Feb 10, 2019 7:29 pm

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.

Post Reply