Page 4 of 8

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 4:08 pm
by kiranmai1268
Thankyou it worked.

there is one more question, how to do calibrate the values, and is it possible to continuously print the values?

thanks again.

Re: HX711 - which lib should I use?

Posted: Tue Jul 19, 2022 4:14 pm
by Roberthh
In order to calibrate the values, you need a known weight, and use the readings for that weight as the scaling factor.
To read continuously, just run a loop in the scale.py code.

Re: HX711 - which lib should I use?

Posted: Wed Jul 20, 2022 10:42 am
by kiranmai1268
I have tried scale.py but it gives me error: saying type object 'SPI' has no attribute 'Master' same error I had earlier, also you mentioned some changes has to be done to scale.py in order to work with Pico using micro python.
can you please specify

Thankyou

Re: HX711 - which lib should I use?

Posted: Wed Jul 20, 2022 2:42 pm
by Roberthh
use the gpio variant.

Re: HX711 - issue with the load cell

Posted: Thu Jul 28, 2022 3:45 pm
by kiranmai1268
We are currently trying to connect the following load cell

https://www.amazon.co.uk/gp/product/B07 ... UTF8&psc=1

We are trying to configure this with RPi4 B and RPi Pico. Currently, this is reading random values in a loop and hoping someone can help us with that. An image of the connections can be found in the following link. https://stokbox-my.sharepoint.com/perso ... sktop&ga=1

Happy to create a video showing what is happening if this helps.

Thanks,

Re: HX711 - which lib should I use?

Posted: Thu Jul 28, 2022 3:58 pm
by Roberthh
The links in your post do not work. And you can embed pictures directly in a post. That's easier for the readers.

Re: HX711 - issue with the load cell

Posted: Thu Jul 28, 2022 5:01 pm
by scruss
kiranmai1268 wrote:
Thu Jul 28, 2022 3:45 pm
We are currently trying to connect the following load cell ...
Isn't this exactly the same question as before?

Re: HX711 - which lib should I use?

Posted: Tue Aug 02, 2022 11:16 am
by kiranmai1268
yes, the same question
but we are not getting the exact value when applied pressure on load cell
can you know the reason why
is there anything that needs to change?

Re: HX711 - which lib should I use?

Posted: Tue Aug 02, 2022 11:47 am
by Roberthh
How large is the variation? The ADC in the HX711 is quite noisy, and load cells may differ a lot.

Re: HX711 - which lib should I use?

Posted: Tue Aug 02, 2022 1:23 pm
by kiranmai1268
we are getting the output as( 0,0,0) irrespective of load we are applying.

I'm attaching the image below and the code we used.

Code: Select all

import time
import sys

EMULATE_HX711=False

referenceUnit = 1

if not EMULATE_HX711:
    import RPi.GPIO as GPIO
    from hx711 import HX711
else:
    from emulated_hx711 import HX711

def cleanAndExit():
    print("Cleaning...")

    if not EMULATE_HX711:
        GPIO.cleanup()
        
    print("Bye!")
    sys.exit()

hx = HX711(5, 6)

# I've found out that, for some reason, the order of the bytes is not always the same between versions of python, numpy and the hx711 itself.
# Still need to figure out why does it change.
# If you're experiencing super random values, change these values to MSB or LSB until to get more stable values.
# There is some code below to debug and log the order of the bits and the bytes.
# The first parameter is the order in which the bytes are used to build the "long" value.
# The second paramter is the order of the bits inside each byte.
# According to the HX711 Datasheet, the second parameter is MSB so you shouldn't need to modify it.
hx.set_reading_format("MSB", "MSB")

# HOW TO CALCULATE THE REFFERENCE UNIT
# To set the reference unit to 1. Put 1kg on your sensor or anything you have and know exactly how much it weights.
# In this case, 92 is 1 gram because, with 1 as a reference unit I got numbers near 0 without any weight
# and I got numbers around 184000 when I added 2kg. So, according to the rule of thirds:
# If 2000 grams is 184000 then 1000 grams is 184000 / 2000 = 92.
#hx.set_reference_unit(113)
hx.set_reference_unit(referenceUnit)

hx.reset()

hx.tare()

print("Tare done! Add weight now...")

# to use both channels, you'll need to tare them both
#hx.tare_A()
#hx.tare_B()

while True:
    try:
        # These three lines are usefull to debug wether to use MSB or LSB in the reading formats
        # for the first parameter of "hx.set_reading_format("LSB", "MSB")".
        # Comment the two lines "val = hx.get_weight(5)" and "print val" and uncomment these three lines to see what it prints.
        
        # np_arr8_string = hx.get_np_arr8_string()
        # binary_string = hx.get_binary_string()
        # print binary_string + " " + np_arr8_string
        
        # Prints the weight. Comment if you're debbuging the MSB and LSB issue.
        val = hx.get_weight(5)
        print(val)

        # To get weight from both channels (if you have load cells hooked up 
        # to both channel A and B), do something like this
        #val_A = hx.get_weight_A(5)
        #val_B = hx.get_weight_B(5)
        #print "A: %s  B: %s" % ( val_A, val_B )

        hx.power_down()
        hx.power_up()
        time.sleep(0.1)

    except (KeyboardInterrupt, SystemExit):
        cleanAndExit()