Qwiic Scale Hookup Guide

Pages
Contributors: Nate
Favorited Favorite 5

Qwiic Scale Arduino Library and Overview

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

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 calling myScale.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 calling myScale.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 calling myScale.setSampleRate(NAU7802_SPS_80). 10, 20, 40, 80, and 320 samples per second is available.
  • bool setChannel(uint8_t channelNumber) - Select between 1 and 2
  • bool 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 Defaults
  • bool powerUp() - Power up digital and analog sections of scale, ~2mA
  • bool powerDown() - Puts scale into low-power 200nA mode
  • bool setIntPolarityHigh() - Set Int pin to be high when data is ready (default)
  • bool setIntPolarityLow() - Set Int pin to be low when data is ready
  • uint8_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 register
  • bool clearBit(uint8_t bitNumber, uint8_t registerAddress) - Mask & clear a given bit within a register
  • bool getBit(uint8_t bitNumber, uint8_t registerAddress) - Return a given bit within a register
  • uint8_t getRegister(uint8_t registerAddress) - Get contents of a register
  • bool setRegister(uint8_t registerAddress, uint8_t value) - Send a given value to be written to given address. Return true if successful.