Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Confused with changes in the HX711 calibration constants #59

Closed
classbproject opened this issue Jan 28, 2025 · 14 comments
Closed

Confused with changes in the HX711 calibration constants #59

classbproject opened this issue Jan 28, 2025 · 14 comments
Assignees
Labels
question Further information is requested

Comments

@classbproject
Copy link

Last year, I built a Nano project that uses the HX711 ADC to read two load cells. Based on the weight difference, it plays an audio file.

In the code below, the calibration constants were in the 400 range as shown in the code below. However, the library has been updated. During a recent calibration cycle, these constants now appear as decimals (see the calibration output at the end).

Should I update my code to include these as decimals?

// scale constants.
const float calibrationCell1 = 432.997039;
const float calibrationCell2 = 421.606750;
const long offsetCell1 = 4294948297;
const long offsetCell2 = 4294445015;

The most recent calibration output is as shown below,

CALIBRATION
===========
remove all weight from the loadcell
and press enter

Determine zero weight offset
OFFSET: 4294437740

place a weight on the loadcell
enter the weight in (whole) grams and press enter
WEIGHT: 150
SCALE:  0.524167

use scale.set_offset(4294437740); and scale.set_scale(0.524167);
in the setup of your project
@RobTillaart RobTillaart self-assigned this Jan 28, 2025
@RobTillaart RobTillaart added the question Further information is requested label Jan 28, 2025
@RobTillaart
Copy link
Owner

Should I update my code to include these as decimals?

Yes, you can as the calibration and the internal code can handle / use those decimals.
In fact not using the decimals would be a systematic error, although a small one
Note that rounding or truncating the value will give an error of max 1 in 432 in your case.
This would be roughly less than 0.25% so not that big of an error.

If you want you could round the value, 432.997039 would previously be 432 but actual 433 seems to be a better value to use.
Rounding would reduce the systematic error to 0.5 in 432 => ~ 0.13% so in the range of the accuracy of most loadcells.

@classbproject
Copy link
Author

classbproject commented Jan 28, 2025

Thank you. Just so that I've understood this properly, its okay to use scale.set_scale(0.524167); instead of scale.set_scale(433);? I should've been more clearer in my initial query and asked this instead of just asking about decimals.

@RobTillaart
Copy link
Owner

As said the use of floats is no problem.

However it is strange that those numbers are so far apart (assuming it is the same setup)
Or is it another loadcell?
Or using another zero reference?

@classbproject
Copy link
Author

Or using another zero reference?

Not sure I understand what you mean by this. Its the same loadcell. I was surprised by the difference as well and assumed that it is because of the library updates.

@RobTillaart
Copy link
Owner

You can't break the setup so just give it a try if it gives meaningful outcomes.

Q: which versions did you compare exactly? So I can investigate.

@classbproject
Copy link
Author

The constants mentioned above were with version 0.5.0. The ones now are with the latest version.

@RobTillaart
Copy link
Owner

Ok, I am going to have a quick look at the changes.

@RobTillaart
Copy link
Owner

Changes between 0.5.0 and 0.5.2 (latest)

  1. internal long _offset => int32_t _offset + get/set_offset() function
  2. internal _lastRead => _lastTimeRead + calling function

HX_calibration.ino

  1. uint32_t offset => int32_t offset as it was possible to have a negative offset. This negative offset did not change the working of the library. See Fix calibration sketch #54 - as adding e.g an offset of 4294811764 or -155532 gives the same effect (due to roll over math).

So in short I cannot explain your results from the changes in the code (yet, will check deeper as I have no setup)


Using the same weight:
Can you run the calibration sketch with version 0.5.0 and post the whole output.
Can you run the calibration sketch with version 0.5.2 and post the whole output.

@RobTillaart
Copy link
Owner

Or using another zero reference?

Not sure I understand what you mean by this. Its the same loadcell. I was surprised by the difference as well and assumed that it is because of the library updates.

Did you call the tare() function before calibration?
You must know the signal the load cell gives when it is in its zero position (normally this is no weight).

@classbproject
Copy link
Author

Using the same weight:
Can you run the calibration sketch with version 0.5.0 and post the whole output.
Can you run the calibration sketch with version 0.5.2 and post the whole output.

Will do.

Did you call the tare() function before calibration?
You must know the signal the load cell gives when it is in its zero position (normally this is no weight).

I used the calibration sketch from the examples. I believe it does call tare() before getting the existing offset.

@classbproject
Copy link
Author

I declared the calibration constants as a float. Is that the right data type for it, or do I need to use something else?

@RobTillaart
Copy link
Owner

bool set_scale(float scale = 1.0) uses a float so float is oK
You might use an integer type as the compiler will auto convert (within limits).

@classbproject
Copy link
Author

classbproject commented Jan 29, 2025

So I tried this again right now with versions 0.5.0 and 0.5.2 and now I'm getting consistent constants in the range of 422 and 435 for two different loadcells. Not sure why I was seeing values less than 1 yesterday. My apologies for being a bother.

@RobTillaart
Copy link
Owner

No problem,
to hear it all is stable and working is better news than having a serious bug :)

Assuming there are no related questions I close this issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants