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.
Josmagal
Posts: 3
Joined: Sat Feb 12, 2022 7:54 pm

Re: HX711 - which lib should I use?

Post by Josmagal » Wed Mar 02, 2022 9:15 pm

Roberthh wrote:
Sat Feb 12, 2022 8:17 pm
What is the range of the variation?
Did you connect the load cell properly?
I' trying again the spi library with no results
Just to check the connections:
load cell to HX711:
red to E+
black to E-
white to A-
green to A+

Hx711 to ESP Huzzah32
GND to GND
VCC to 3V
DT to MISO Pin (GPIO19)
SCK to MOSI Pin GPIO 18)

GPIO 5 is the spi clock pin but it´s not connected
I´m using the hx711_spi.py library
The code is as follows:

Code: Select all

from hx711_spi import HX711
from machine import Pin, SPI


pin_OUT = Pin(19, Pin.IN, pull=Pin.PULL_DOWN)
pin_SCK = Pin(18, Pin.OUT)
spi_SCK = Pin(5)

spi = SPI(1, baudrate=1000000, polarity=0,
          phase=0, sck=spi_SCK, mosi=pin_SCK, miso=pin_OUT)

hx711 = HX711(pin_SCK, pin_OUT, spi)

hx711.set_gain(128)
hx711.tare()
while True:
    value = hx711.get_value()
    print(value)
The result is as shown on the attached image.
Can you figure what I´m doing wrong?
Attachments
Captura de ecrã 2022-03-02, às 21.07.53.png
Captura de ecrã 2022-03-02, às 21.07.53.png (286.82 KiB) Viewed 4483 times

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 » Thu Mar 03, 2022 7:47 am

I can't tell the difference. You could try a lower baud rate. When using GPIO, the baud rate is lower. The lowest acceptable baud rate according to the data sheet is 10 kHz.

kiranmai1268
Posts: 11
Joined: Tue Jul 19, 2022 11:26 am

Re: HX711 - Which source code should I use for load cell & HX711?

Post by kiranmai1268 » Tue Jul 19, 2022 11:59 am

Hi there,

we are working on 1kg load cells and HX711 amplifier. I have tried multiple source codes to run on raspberry pi Pico. however unfortunately, it's giving me error in scales.py or using as a separate .py file also I tried to combine the HX711 py file and added the scale.py/test code together, but it still gives me error.

can you please direct me to the source code for programming HX711 with load cell for raspberry pi Pico using micro python?

here, are the lists of source code which I tried

https://github.com/robert-hh/hx711
https://github.com/endail/hx711-rpi-py
https://github.com/gandalf15/HX711/tree ... 11_Python3
https://github.com/SergeyPiskunov/micropython-hx711

It would be so pleasure if you help in sorting out this.

thank you.

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 » Tue Jul 19, 2022 12:10 pm

I know that the code I provided (No 1 in your list) works. So which error do you get in scale.py?

kiranmai1268
Posts: 11
Joined: Tue Jul 19, 2022 11:26 am

Re: HX711 - which lib should I use?

Post by kiranmai1268 » Tue Jul 19, 2022 1:31 pm

Hx711_gpio works perfectly fine but when running a scale.py it gives: no module name 'Hx711_gpio'. Also, tried combining the codes Hx711_gpio and scale.py but give me error: type object 'SPI' has no attribute 'MASTER'.

please give me some suggestion.

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 » Tue Jul 19, 2022 2:09 pm

The scale.py code is written for a Pycom board and does not match the other files. For a RPi Pico, the spi instantiation must be changed. But maybe just go for the examples in README.md

kiranmai1268
Posts: 11
Joined: Tue Jul 19, 2022 11:26 am

Re: HX711 - which lib should I use?

Post by kiranmai1268 » Tue Jul 19, 2022 2:36 pm

What type of changes do I have to make on hx711_spi.py file, can you specify please? As I have tried the example code for Pico RP2040 also there is a same directory it still gives me error.

I have attached an error image please go through it.
Attachments
MicrosoftTeams-image (1).png
MicrosoftTeams-image (1).png (43.85 KiB) Viewed 4070 times

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 » Tue Jul 19, 2022 2:41 pm

The source code snippet and the error message do not match. Besides that, for the GPIO mode, you have to use:

from hx711_gpio import HX711.

And obviously, the hx711_gpio.py file has to be in the file system of the board.

kiranmai1268
Posts: 11
Joined: Tue Jul 19, 2022 11:26 am

Re: HX711 - which lib should I use?

Post by kiranmai1268 » Tue Jul 19, 2022 3:06 pm

still getting the same error after placing the hx711_gpio.
Attachments
same fol.png
same fol.png (9.73 KiB) Viewed 4058 times
error_code.png
error_code.png (41.53 KiB) Viewed 4058 times

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 » Tue Jul 19, 2022 3:27 pm

The message says: File not on the board or not in the search path. The file has to be in the file system of the RPi pico, not on the PC.

Post Reply