gandalf15 / HX711

Read HX711 ADC for Weigh Scales on Rasperry PIs.
BSD 3-Clause "New" or "Revised" License
113 stars 81 forks source link

When more weight, the value goes down #8

Closed adriencarbonaro closed 5 years ago

adriencarbonaro commented 5 years ago

When I put more weight on the scale, the value goes down in the negatives. Maybe the offset is not well calibrated, but the value should go up when I put more weight. Does someone know why ?

gandalf15 commented 5 years ago

Simple solution. Just turn the load cell by 180 degree in vertical axis. Sometimes the manufacturer puts the sticker other way around. This should help.

adriencarbonaro commented 5 years ago

I'll do that if there is no software solution but the load cell is already fixed so it is not so easy to turn it around. Do you know a software solution ? Otherwise I'll do just that. Thank you !

gandalf15 commented 5 years ago

Sure, we can solve it in software. I'll look at it tomorrow.

gandalf15 commented 5 years ago

Meanwhile, can you provide more info? Which function you want to use? is it get_weight_mean? Do you "zero" (tare) the scale with hx.zero method? I think that if you set the variable hx._scale_ratio_A_128 = - ratio to negative ratio this should just work fine. Then do not use hx.set_scale_ratio(scale_ratio=ratio) method to set the ratio. There is check if the ratio is negative it raises ValueError. You have to access the variable as described above. As I said I'll look at it tomorrow. Let me know if this worked.

adriencarbonaro commented 5 years ago

I'll provide more info this afternoon! I'll try your solution and tell you if it works

adriencarbonaro commented 5 years ago

I think it is a problem of ratio and offset. I'm not sure to understand how to set them.

gandalf15 commented 5 years ago

If you are using channel A and gain 128 try this and copy the output. If not working try debug mode. Also, do not forget to change your dout_pin and pd_sck_pin to your pin numbers.

hx = HX711(dout_pin=21, pd_sck_pin=20)
result = hx.reset()
result = hx.zero(readings=20)
input('Put known weight on the scale and then press Enter')
data = hx.get_data_mean(readings=20)
if data != False:
    known_weight_grams = input(
        'Write how many grams it was and press Enter: ')
    value = float(known_weight_grams)
    print(str(value) + ' grams')
    ratio = data / value  # calculate the ratio for channel A and gain 128
    print('data:', data)
    print('known weight is:', value)
    print('Ratio should be for you a negative number. It is:', ratio)
    hx._scale_ratio_A_128 = ratio  # in this case ratio should be negative number
else:
    raise ValueError('Cannot calculate mean value. Try debug mode.')
while (True):
    current_weight =  hx.get_weight_mean(10)
    print('Current weight on the scale is:', current_weight)
gandalf15 commented 5 years ago

You can try to pull the latest changes from master branch. the example.py should work.

adriencarbonaro commented 5 years ago

Sorry I didn't have much time to respond before. Thank for the info. I did what you told me too and it worked like a charm. I then pulled your latest changes that did the exact same thing so it is great now. I'll be using your library a lot in the next few weeks so I'll come back if needed.

Thank you again, great work.