Qwiic Scale Hookup Guide
How to Characterize Your Scale
You should have your scale hooked up, but there's one more step before we get measuring. It's time to teach your scale how much one thing weighs so it can tell how much everything else weighs!
Load cells have a linear response meaning their value changes in proportion to the force or weight applied to it. Remember the y = mx + b
stuff you learned in school? Itâs ok if you didnât! The characterization of a scale looks like this:
- Hookup the scale and get the Example1_BasicReadings.ino outputting a good, changing value.
- Load Example2_CompleteScale.ino
- Take everything off your scale and press âcâ to get a âzeroâ reading
- Place a known weight (can of soda, weight lifting plate, etc) on your scale and enter its value. For example, if you placed a 150 gram weight on your scale, enter 150.0.
Thatâs it. You can remove the known weight and weigh anything else you have lying around. But whatâs really going on?
Instead of y = mx + b
imagine weight = calibrationFactor * reading + zeroOffset
.
The SparkFun library for the NAU7802 takes digital readings. These readings will vary from 10,000 to over 1 million. These values are unitless - the IC doesnât know if thereâs grams or lbs or stones on your scale, all it knows is the change in value. So when you remove all weight from your scale, thereâs still a non-zero value being measured. We call this the zero offset (also known as the +b
portion of the y = mx + b
) and itâs set when you call the calculateZeroOffset()
function. When you place a known weight on the scale and call the calculateCalibrationFactor(150.0)
function the library will do the following math (and set the m
portion of y=mx+b
).
Let's say you measured 213417
with nothing on the scale. Once you added 150grams the scale measured 265412
. From these numbers we can calculate the slope of the line:
Zero offset = 213417 Calibration factor = (265412 - 213417) / 150 = 346.6333
We now know that for every change of 346 in the digital reading we are seeing a change of 1 gram. NEAT.
Now, whatever we put on the scale we can get its weight by extrapolating between the zero offset and the known weight. For example, if we put an unknown thing on the scale and get a reading of 244094 we know:
244094 - 213417 = 30677 30677 / 346.633 = 88.4999
88.5 grams! Again, these values are unitless but as long as you know that the known weight was in grams, then the âweightâ is output in grams.
getZeroOffset()
and getCalibrationFactor()
functions. Once obtained, store these values in EEPROM or other NVM. This will allow you to create a scale that can power up, load the values from NVM and immediately begin measuring weight. When power cycling your system youâll want to reload them with the setZeroOffset(213417)
and setCalibrationFactor(346.6333)
functions. This is demonstrated in Example2.