endail / hx711

Raspberry Pi HX711 C++ Library
MIT License
19 stars 11 forks source link

Calibration Exception #9

Closed Dmmesserschmidt closed 2 years ago

Dmmesserschmidt commented 3 years ago

Try run the HX711 Calibration and occurs the exception

======================================== HX711 Calibration

Find an object you know the weight of. If you can't find anything, try searching Google for your phone's specifications to find its weight. You can then use your phone to calibrate your scale.

  1. Enter the unit you want to measure the object in (eg. g, kg, lb, oz): kg

  2. Enter the weight of the object in the unit you chose (eg. if you chose 'g', enter the weight of the object in grams): 1

  3. Enter the number of samples to take from the HX711 module (eg. 15): 30

  4. Remove all objects from the scale and then press enter.

Working...terminate called after throwing an instance of 'HX711::TimeoutException' what(): timed out while trying to read bytes from HX711 Aborted

endail commented 3 years ago

Hi,

Thank you for letting me know. However, I have not been able to reproduce the error. I can confirm that the current code in the repository works on a Raspberry Pi Zero W connected to a Sparkfun HX711 breakout board.

I am working on updating the code to make it more resilient to this error, but here is why the exception is occurring at the moment.

https://github.com/endail/hx711/blob/4a6ef0de9d4e67bdaf79e04012ca70e46e4607ab/src/HX711.cpp#L125-L141

That is where the exception is thrown.

https://github.com/endail/hx711/blob/4a6ef0de9d4e67bdaf79e04012ca70e46e4607ab/include/HX711.h#L74-L86

And that is where the hardcoded values are controlling when it is thrown. Those values are based on the minimum I was able to find which worked for me, so I have very limited testing results.

If you would like to, here is what you can try:

  1. Increase _MAX_READ_TRIES. This is the number of attempts to check if the sensor is ready to be read from before throwing the exception. Also note that if you change the data type, you'll also need to change the data type on line 125 in the source file.

  2. Alter _WAIT_INTERVAL_US. This is the number of microseconds to wait between attempts. Changing this is a bit of a balancing act with _MAX_READ_TRIES.

  3. Comment out lines 133 - 138 in the source file. Doing this will increase the CPU usage to 100%, but it means it will almost certainly work. If it does not work and the program freezes, I suspect there may be a hardware issue instead.

If you do make any changes, just return to the project directory and run make before trying the calibration program again. Once you've got it working, you can run sudo make install.

endail commented 3 years ago

Hi @Dmmesserschmidt,

I've made some changes to the code. You might like to clone the repo and give it a try.

endail commented 2 years ago

This exception is no longer applicable to the current state of the code.