dangrie158 / opencushion

A c++ driver and a node binding for the HX711 Load Cell Amp
MIT License
14 stars 17 forks source link

Automatically recover on read issues #1

Closed maxnowack closed 7 years ago

maxnowack commented 7 years ago

Is it possible to automatically recover on read issues? You mentioned the problem in the troubleshooting section of the readme. I've found this c library for the raspberry pi: https://github.com/ggurov/hx711 In the last section of the readme, @ggurov mentioned that the raspberry pi isn't designed to work with chips like the hx711 in realtime, so he included a few safeguard for resetting the chip, etc. I'm not sure, where these safeguards are implemented in his library, but maybe it is possible to also include these safeguards?

dangrie158 commented 7 years ago

Hey max, I looked at the repo and only found 2 "safguards": setting the priority of the process higher and resetting the chip before initializing.

The first one isn't really a safe guard since the clock soley comes from the Raspberry and the clock being slightly out of phase due to scheduling isn't a problem for the hx711.

The second one gets closer to solving an actual problem. The only way I could get the chip into a "hanging" state is when I desynchronized the chip and the Raspberry due to a missing clock on the sensor or restarting the driver in the middle of a read. In this case it is sufficient to power cycle the sensor before a read to resynchronize it. From the datasheet:

When PD_SCK pin changes from low to high and stays at high for longer than 60μs, HX711 enters power down mode (Fig.3)

I already implemented the power down and power up functions, so you could just power the chip down after every read and power it up before every read. After a power down the chip gets also a power-on reset so you need to reset the gain (which already happens after every read, sou you would need to insert a dummy read after power up).

I'm happy to accept any PR if you have success and want to share your code.

maxnowack commented 7 years ago

Oh, I just forgot to thank you for the very clear answer! I've finished the hardware part of my project and now dive into the code. I'll let you know, if I have any improvements to share :)