rb2468 / tray-a-way

GNU General Public License v3.0
0 stars 0 forks source link

How to read values with Load Cells & Amp #53

Closed bshapero13 closed 2 years ago

bshapero13 commented 2 years ago
bshapero13 commented 2 years ago

The first step was to ensure the load cell and amplifier were connected appropriately and the schematics can be seen below:

Screen Shot 2022-02-28 at 5 46 21 PM Screen Shot 2022-03-02 at 10 00 07 AM

The physical connections can be seen below:

Screen Shot 2022-03-02 at 10 35 31 AM
bshapero13 commented 2 years ago

For the purposes of this configuration, the following connections were made:

bshapero13 commented 2 years ago

Afterward the following repository was cloned to obtain the library for the HX711 to use its functions. The load cell needed to be calibrated first, so the function calibration.py was created and below is the code for the function:

calibration(1) Calibration (2)
bshapero13 commented 2 years ago

This function works by retrieving the initial offset of the load cell with the calibrate() function by calling the HX711 library function. This offset is then compared to an item of some known weight and the function hx.read_average() is used again to retrieve the value of the item on the load cell and take the difference between that object's measured weight and the initial offset. The actual weight of the item is then inputted , and by doing so, a ratio between actual and measured value can be made that will be used as a ratio to convert the weights of the items placed onto the load cell.

bshapero13 commented 2 years ago

Once the ratio is found, the weight is displayed in grams and if the calibration does not seem accurate, then the load cell might want to be recalibrated. A 1250g object was used on the scale and this was the output produced:

calibration output
bshapero13 commented 2 years ago

It can be seen that this adjusted scale is off by 30g, which for the purposes of our project will perhaps be detrimental. The reason for the disparity is that the HX711 Amplifier may take a minute or two to fully process values and so a new calibration was performed and the new output was produced:

Screen Shot 2022-02-28 at 11 13 26 PM

This value is much closer to the expected weight of the item, which may not be exactly as displayed on the item so the marginal difference is within reason

bshapero13 commented 2 years ago

When calibrated, the load cell can be tested out fully by continuously measuring data and outputting it. The following function loadcelltest.py was created:

loadcelltest
bshapero13 commented 2 years ago

In this file, the setup() function uses the offset and scaling factor found from the output of the calibration.py file and sets these values so the data is displayed accurately. The file then enters a loop that will run until a keyboard interruption and will display the weight in grams of the object by using the HX711 library and its function hx.get_grams() and the following output was produced:

Screen Shot 2022-02-28 at 11 22 44 PM

Note that initially the load cell is hovering around the value of 0 with some slight fluctuation, which is understandable. For potential modification, a the loop function of loadcelltest.py could be modified to only output integer values since difference of 10ths of a gram will not be applicable to the uses of our product.

bshapero13 commented 2 years ago

The video test can be found in this folder and shows a finger being placed onto the load cell and weight gently applied while at the same time letting up to see if the load cell will be able to detect rapid changes, and it was able to do so.