gandalf15 / HX711

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

last known weight lost on power reset #12

Closed hristakiev closed 5 years ago

hristakiev commented 5 years ago

I use HX711 Python library which at every hour write down in sqlite3 weight and time. INSERT INTO loadcellSample (weight, comment, sampleDateTime) The problem is when there is a power reset and weight is still present on the scale the output goes back to 0.I have to remove the weight from the load cell,power reset and place the weight back on the scale.Problem is that my weight is 100Kgs and it is not practical to remove weight. So i'm looking for a solution when there is a constant load on the cell and after power failure to restore last known weight?

gandalf15 commented 5 years ago

There you go mate. https://github.com/gandalf15/HX711/blob/master/HX711_Python3/example_save_state.py

This is example that shows you how to do it. It cannot be part of the library. You do not have to save the state every time you read the load cell, you can use time or some kind of counter to control the writes to SD card.

gandalf15 commented 5 years ago

BTW. There is a new filter implemented of you use the latest version of the library. It improve reading by a lot.

hristakiev commented 5 years ago

Happy new year, thank you don't forget me i get the idea to use a swap file, but when i power off the pi it create the swap_file.swp but its empty and than: sudo ./example_save_state.py /home/bee/work/save/HX711/HX711_Python3/hx711.py:60: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(self._pd_sck, GPIO.OUT) # pin _pd_sck is output only Traceback (most recent call last): File "./example_save_state.py", line 18, in hx = pickle.load(swap_file) EOFError: Ran out of input

gandalf15 commented 5 years ago

Hi, Happy New Year to you too. I forgot to flush and fsynch. Please try now. It should work. It works on my table and I tried the situation with power failure. Also, you have to save the state only once at the beginning. Please let me know. Thanks.

hristakiev commented 5 years ago

Thank you again, now everything works fine.Good job :)

gandalf15 commented 5 years ago

Glad to help.