Page 3 of 8

Re: HX711 - which lib should I use?

Posted: Wed Mar 02, 2022 9:15 pm
by Josmagal
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?

Re: HX711 - which lib should I use?

Posted: Thu Mar 03, 2022 7:47 am
by Roberthh
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.

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

Posted: Tue Jul 19, 2022 11:59 am
by kiranmai1268
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.

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 12:10 pm
by Roberthh
I know that the code I provided (No 1 in your list) works. So which error do you get in scale.py?

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 1:31 pm
by kiranmai1268
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.

Re: HX711 - which lib should I use?

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

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 2:36 pm
by kiranmai1268
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.

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 2:41 pm
by Roberthh
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.

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 3:06 pm
by kiranmai1268
still getting the same error after placing the hx711_gpio.

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 3:27 pm
by Roberthh
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.