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.
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: HX711 - which lib should I use?

Post by Roberthh » Sun Feb 14, 2021 7:16 pm

machine.idle() just serves the purpose of avoiding a busy loop. time.sleep_ms(1) works as well.

Edit: I see machine.idle(). May you should use the daily build firmware. It progresses fast at the moment.

hgrbirchall
Posts: 3
Joined: Sun Feb 14, 2021 6:45 pm
Location: London, UK

Re: HX711 - which lib should I use?

Post by hgrbirchall » Sun Feb 14, 2021 7:47 pm

Thanks the latest update appears to have fixed that issue, I have it working now for the scales.py file, with GPIO 16 as the data pin and GPIO as the clock pin. when I tried to run your hxtest.py example I am getting the following terminal message:
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "/lib/hx711_spi.py", line 9, in __init__
TypeError: extra keyword arguments given
This is the only change I have made so far:

Code: Select all

from hx711_spi import *
hx = HX711(16, 18, 19)

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

Re: HX711 - which lib should I use?

Post by Roberthh » Sun Feb 14, 2021 8:22 pm

The driver uses the SPI call logic of pycom. You have to change that line in hx711_spi.py to:

self.spi = SPI(0, mode=SPI.MASTER, baudrate=1000000, polarity=0,
phase=0, sck=Pin(spi_clk), mosi=Pin(pd_sck), miso=Pin(dout))

Please note that the SPI clock will NOT be connected. The HX711 will be clocked by the mosi pin.

hgrbirchall
Posts: 3
Joined: Sun Feb 14, 2021 6:45 pm
Location: London, UK

Re: HX711 - which lib should I use?

Post by hgrbirchall » Sun Feb 14, 2021 10:37 pm

Thank you Robert. I think I have it working now. I am using GPIO 16 as the data (miso) pin and GPIO 19 as the skc (mosi) pin.

Now to turn it into meaningful results! The plan is to make a data logger which I can use with load cells for work.

sciortino
Posts: 1
Joined: Sat Feb 27, 2021 8:11 pm

Re: HX711 - which lib should I use?

Post by sciortino » Sat Feb 27, 2021 8:17 pm

I'm working with a high school robotics team that want's to use the hx711 with a pico to design some "smart" exercise equipment.

Would you be willing to share some samples of your code?

Jeff

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

Re: HX711 - which lib should I use?

Post by Roberthh » Sat Feb 27, 2021 9:09 pm

The repository contains samples of the code. At the moment, the SPI version is the best to use. But I can also make a PIO version, which makes use of the PIO state machine and should perform better. Just give me a day or two for set-up.

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

Re: HX711 - which lib should I use?

Post by Roberthh » Sun Feb 28, 2021 10:57 am

There is a variant now of the driver using the RP2040's PIO at https://github.com/robert-hh/hx711
Like the GPIO version it uses two pins only, but unlike GPIO, once started the timing cannot be affected by interrupts.

Josmagal
Posts: 3
Joined: Sat Feb 12, 2022 7:54 pm

Re: HX711 - which lib should I use?

Post by Josmagal » Sat Feb 12, 2022 8:07 pm

Hi there Robert!
I’m using the https://github.com/robert-hh/hx711-lopy library to measure the weight from a load cell connected to a HX711 board with a ESP32 board(Huzzah32 from Adafruit).
I’m using de SPI version. The code does not return any kind of errors, but the value returned varies a lot even from negative to positive values.
Can you give any advice?
Thanks in advance

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

Re: HX711 - which lib should I use?

Post by Roberthh » Sat Feb 12, 2022 8:17 pm

What is the range of the variation?
Did you connect the load cell properly?

Josmagal
Posts: 3
Joined: Sat Feb 12, 2022 7:54 pm

Re: HX711 - which lib should I use?

Post by Josmagal » Sat Feb 26, 2022 8:51 pm

Thanks for you reply.
Changed to the GPIO version and all is good.
Will try the spi version soon
Thanks again
BTW do you think it possible and accurate (+-2g) to display weight variations per second?

Post Reply