Qwiic Scale Hookup Guide
Qwiic Scale Arduino Library and Overview
The SparkFun Qwiic Scale NAU7802 Arduino Library is a fully featured library for reading weights as well as configuring the IC. We recommend you install the library via the Arduino IDE by using the library manager and search for SparkFun Scale. Or you can download and manually install a zip of the library by clicking on the link below. For those who want to view the code, check out the GitHub repo.
Once you have the library installed we recommend you start with Example1 and advance through the examples as you go. You do not need to read or absorb all the following functions, they are demonstrated and described in the examples. But if you're really advanced and just want the available functions, here they are:
bool begin(TwoWire &wirePort = Wire)
- Check communication and initialize sensor. Returns true if sensor is successfully started. Optionally, you can pass in a different Wire port.bool isConnected()
- Returns true if device acknowledges a call to its I2C address.bool available()
- Returns true if Cycle Ready bit is set (conversion is complete).int32_t getReading()
- Returns 24-bit reading. Assumes CR Cycle Ready bit (ADC conversion complete) has been checked by.available()
.int32_t getAverage(uint8_t samplesToTake)
- Return the average of a given number of readings.void calculateZeroOffset(uint8_t averageAmount = 8)
- Also called taring. Call this with nothing on the scale.void setZeroOffset(int32_t newZeroOffset)
- Sets the internal variable. Useful for users who are loading values from NVM.int32_t getZeroOffset()
- Ask library for the zero offset value. Useful for storing value into NVM.void calculateCalibrationFactor(float weightOnScale, uint8_t averageAmount = 8)
- Call this with the value of the thing on the scale. Sets the calibration factor based on the weight on scale and zero offset.void setCalibrationFactor(float calFactor)
- Pass a known calibration factor into library. Helpful when loading settings from NVM.float getCalibrationFactor()
- Ask library for the calibration factor. Useful for storing value into NVM.float getWeight(bool allowNegativeWeights = false)
- Once you've set zero offset and cal factor, you can ask the library to do the calculations for you. By default, negative weights will be returned as 0.bool setGain(uint8_t gainValue)
- Set the gain by callingmyScale.setGain(NAU7802_GAIN_16)
. x1, 2, 4, 8, 16, 32, 64, 128 are available.bool setLDO(uint8_t ldoValue)
- Set the onboard Low-Drop-Out voltage regulator to a given value by callingmyScale.setLDO(NAU7802_LDO_3V6)
. 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.2, 4.5V are available.bool setSampleRate(uint8_t rate)
- Set the readings per second by callingmyScale.setSampleRate(NAU7802_SPS_80)
. 10, 20, 40, 80, and 320 samples per second is available.bool setChannel(uint8_t channelNumber)
- Select between 1 and 2bool calibrateAFE()
- Calibrate the analog front end of the IC. This function is unrelated to setting the zero offset and calibration factor and should rarely be used. It is recommended that the AFE be re-calibrated any time the gain, SPS, or channel number is changed. Returns true if CAL_ERR bit is 0 (no error).bool reset()
- Resets all registers to Power On Defaultsbool powerUp()
- Power up digital and analog sections of scale, ~2mAbool powerDown()
- Puts scale into low-power 200nA modebool setIntPolarityHigh()
- Set Int pin to be high when data is ready (default)bool setIntPolarityLow()
- Set Int pin to be low when data is readyuint8_t getRevisionCode()
- Get the revision code of this IC. Always 0x0F.
Here are the lower level functions to manipulate registers:
bool setBit(uint8_t bitNumber, uint8_t registerAddress)
- Mask & set a given bit within a registerbool clearBit(uint8_t bitNumber, uint8_t registerAddress)
- Mask & clear a given bit within a registerbool getBit(uint8_t bitNumber, uint8_t registerAddress)
- Return a given bit within a registeruint8_t getRegister(uint8_t registerAddress)
- Get contents of a registerbool setRegister(uint8_t registerAddress, uint8_t value)
- Send a given value to be written to given address. Return true if successful.