Page 1 of 1

HX711 readout

Posted: Mon Jan 24, 2022 2:14 pm
by megb123
Hey, we are currently using an HX711 weight sensor using a 2kg load cell with a raspberry pi Pico in Micropython.

Currently, any values obtained from the load cell are all extremely erratic, either the same number 8388607 or 0, regardless of any weight used. Would anyone have any suggestions? This is our current code:

from hx711 import HX711
import utime
from machine import Pin

pin_OUT = Pin(20, Pin.IN, pull=Pin.PULL_DOWN)
pin_SCK = Pin(21, Pin.OUT)

hx711 = HX711(pin_SCK, pin_OUT)

while True:
value = hx711.read()
print(value)
utime.sleep(.5)

We have changed the hardware, but is there a possibility it could be broken? Or is it maybe the library or this code? Is this because we have not yet calibrated it?
Please send any suggestions.
Thanks.

Re: HX711 readout

Posted: Mon Jan 24, 2022 2:37 pm
by megb123
Hey, we have resolved this issue! However we are having trouble calibrating our HX711 weight sensor with a 2kg load cell. Currently, it is reading out values in bit form, and we are unsure how to calibrate it to read out in kg or g. We are using micropython, but we can only find answers in C++/C. (Using with a Raspberry Pi Pico)
Would anyone have any suggestions?
Thank you.

Re: HX711 readout

Posted: Mon Jan 24, 2022 5:21 pm
by Roberthh
You have to do the calibration yourself, but that is pretty simple. Just a linear transformation in the form y = a * (x - b)
hx711.read() returns a number. Small for no or small weights, larger for heavier weights.
First take a reading with no weight applied.

offset = hx711.read()

then use a good known reference weight, preferably 1 KG, and take the reading for that weigth.

ref_load = hx711.read()

Then you can calculate the scaling factor as

scaling = ref_load - offset

And get the final kg value as:

weight = (hx711.read() - offset) / scaling

Since the HX711 ADC is pretty noisy, you may have to take an average of a set of readings.