endail / hx711-rpi-py

Python bindings for Raspberry Pi HX711 C++ Library
MIT License
11 stars 4 forks source link

convert raw values from hx.read #4

Closed aero9560 closed 2 years ago

aero9560 commented 2 years ago

Hello Thanks for update, now options are working perfectly fine . i want to perform some function on reading obtained for load cell but as hx.weight return a object i can't do that, is there a way to converts raw reading obtained from hx.read to convert them to reading like obtained from hx.weight so additional operation can be done on them. Thanks

endail commented 2 years ago

If you want the weight as a number you just need to cast the Mass object to a float like this:

val = float(hx.weight())

But if you just want the raw numbers from the scale which haven't been adjusted according the calibration settings (reference unit and offset), you can use either:

  1. hx.getValues() and pass in:
    • the number of samples you want (an integer)
    • the amount of time you want to spend sampling (a datetime.timedelta).

OR

  1. hx.read() with an optional Options object like you have done with .weight().

A third option, if you just want to adjust a raw value according to calibration settings, is to use hx.normalise(raw_value). So you could do something like:

for val in hx.getValues(10):
  print( hx.normalise(val) )
aero9560 commented 2 years ago

Hello Thanks for previous reply that were very helpful. I am using tkinter interface to show weight . Is there a way by which measured weight shown on tkinter window remain stable not like always blinking.

endail commented 2 years ago

Unfortunately I don't have any experience with tkinter, so I can't help with that.

aero9560 commented 2 years ago

hello Is AdavancedHX711 not available for python. I am getting invalid syntax for hx = AdavancedHX711(27, 17, 198227, 114496, Rate::Hz_80). or i have to remove the jumper first then use AdavancedHX711.

endail commented 2 years ago

The Rate::Hz_80 part is the problem. That's C++ code. Try this:

hx = AdavancedHX711(27, 17, 198227, 114496, Rate.HZ_80)
aero9560 commented 2 years ago

Hi My 1000 kg load cell output keep fluctuating ( between 0.0 and 0.1). Do yo have any suggestion regarding this. Does increasing the excitation voltage will help(current using voltage from hx711). Thanks

endail commented 2 years ago

You could try increasing the number of samples obtained, either by using a larger number when you call hx.weight(samples) or using a longer timeout period hx.weight(timedelta(seconds=3)).

If that doesn't work, you might need to look at using some kind of statistical function which smooths-out or can tolerate those fluctuations. But this library doesn't include that functionality.

EmasRicky commented 2 years ago

How to tare the scale? Please help

endail commented 2 years ago

hx.zero()