I’m having some issues getting my SEN-15242 boards to work correctly. I’ve tried several different arduino boards, a Mega, a Leonardo and a MKR-NB-1500, all giving me similar results. Only have this one NAU7802 device hooked to the I2C and powering the board with 3.3v. AVDD pin is not connected to anything since the Sparkfun library is already setting AVDD to use the internal LDO.
In my latest attempt, I’m using the Sparkfun CompleteScale sample with some addition to verify the registers were being configured
/*
Use the Qwiic Scale to read load cells and scales
By: Nathan Seidle @ SparkFun Electronics
Date: March 3rd, 2019
License: This code is public domain but you buy me a beer if you use this
and we meet someday (Beerware license).
This example shows how to setup a scale complete with zero offset (tare),
and linear calibration.
If you know the calibration and offset values you can send them directly to
the library. This is useful if you want to maintain values between power cycles
in EEPROM or Non-volatile memory (NVM). If you don't know these values then
you can go through a series of steps to calculate the offset and calibration value.
Background: The IC merely outputs the raw data from a load cell. For example, the
output may be 25776 and change to 43122 when a cup of tea is set on the scale.
These values are unitless - they are not grams or ounces. Instead, it is a
linear relationship that must be calculated. Remeber y = mx + b?
If 25776 is the 'zero' or tare state, and 43122 when I put 15.2oz of tea on the
scale, then what is a reading of 57683 in oz?
(43122 - 25776) = 17346/15.2 = 1141.2 per oz
(57683 - 25776) = 31907/1141.2 = 27.96oz is on the scale
SparkFun labored with love to create this code. Feel like supporting open
source? Buy a board from SparkFun!
https://www.sparkfun.com/products/15242
Hardware Connections:
Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 9600 baud to see the output
*/
#include <Wire.h>
#include <EEPROM.h> //Needed to record user settings
#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_NAU8702
NAU7802 myScale; //Create instance of the NAU7802 class
//EEPROM locations to store 4-byte variables
#define LOCATION_CALIBRATION_FACTOR 0 //Float, requires 4 bytes of EEPROM
#define LOCATION_ZERO_OFFSET 10 //Must be more than 4 away from previous spot. Long, requires 4 bytes of EEPROM
bool settingsDetected = false; //Used to prompt user to calibrate their scale
//Create an array to take average of weights. This helps smooth out jitter.
#define AVG_SIZE 4
float avgWeights[AVG_SIZE];
byte avgWeightSpot = 0;
void setup()
{
Serial.begin(9600);
delay(5000);
Serial.println("Qwiic Scale Example");
Wire.begin();
Wire.setClock(100000); //Qwiic Scale is capable of running at 400kHz if desired
if (myScale.begin() == false)
{
Serial.println("Scale not detected. Please check wiring. Freezing...");
while (1);
}
Serial.println("Scale detected!");
readSystemSettings(); //Load zeroOffset and calibrationFactor from EEPROM
myScale.setSampleRate(NAU7802_SPS_320); //Increase to max sample rate
myScale.calibrateAFE(); //Re-cal analog front end when we change gain, sample rate, or channel
Serial.print("Zero offset: ");
Serial.println(myScale.getZeroOffset());
Serial.print("Calibration factor: ");
Serial.println(myScale.getCalibrationFactor());
for (byte i = 0;i<32;i++) {
if(i==0x17)
i=0x1F;
byte test=myScale.getRegister(i);
Serial.print(i,HEX);
Serial.print( " ");
Serial.println( test,BIN);
}
}
void loop()
{
delay(500);
if (myScale.available() == true)
{
long currentReading = myScale.getReading();
float currentWeight = myScale.getWeight();
Serial.print("Reading: ");
Serial.print(currentReading);
Serial.print("\tWeight: ");
Serial.print(currentWeight, 2); //Print 2 decimal places
avgWeights[avgWeightSpot++] = currentWeight;
if(avgWeightSpot == AVG_SIZE) avgWeightSpot = 0;
float avgWeight = 0;
for (int x = 0 ; x < AVG_SIZE ; x++)
avgWeight += avgWeights[x];
avgWeight /= AVG_SIZE;
Serial.print("\tAvgWeight: ");
Serial.print(avgWeight, 2); //Print 2 decimal places
if(settingsDetected == false)
{
Serial.print("\tScale not calibrated. Press 'c'.");
}
Serial.println();
}
if (Serial.available())
{
byte incoming = Serial.read();
if (incoming == 't') //Tare the scale
myScale.calculateZeroOffset();
else if (incoming == 'c') //Calibrate
{
calibrateScale();
}
}
}
//Gives user the ability to set a known weight on the scale and calculate a calibration factor
void calibrateScale(void)
{
Serial.println();
Serial.println();
Serial.println(F("Scale calibration"));
Serial.println(F("Setup scale with no weight on it. Press a key when ready."));
while (Serial.available()) Serial.read(); //Clear anything in RX buffer
while (Serial.available() == 0) delay(10); //Wait for user to press key
myScale.calculateZeroOffset(64); //Zero or Tare the scale. Average over 64 readings.
Serial.print(F("New zero offset: "));
Serial.println(myScale.getZeroOffset());
Serial.println(F("Place known weight on scale. Press a key when weight is in place and stable."));
while (Serial.available()) Serial.read(); //Clear anything in RX buffer
while (Serial.available() == 0) delay(10); //Wait for user to press key
Serial.print(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): "));
while (Serial.available()) Serial.read(); //Clear anything in RX buffer
while (Serial.available() == 0) delay(10); //Wait for user to press key
//Read user input
float weightOnScale = Serial.parseFloat();
Serial.println();
myScale.calculateCalibrationFactor(weightOnScale, 64); //Tell the library how much weight is currently on it
Serial.print(F("New cal factor: "));
Serial.println(myScale.getCalibrationFactor(), 2);
Serial.print(F("New Scale Reading: "));
Serial.println(myScale.getWeight(), 2);
recordSystemSettings(); //Commit these values to EEPROM
}
//Record the current system settings to EEPROM
void recordSystemSettings(void)
{
//Get various values from the library and commit them to NVM
EEPROM.put(LOCATION_CALIBRATION_FACTOR, myScale.getCalibrationFactor());
EEPROM.put(LOCATION_ZERO_OFFSET, myScale.getZeroOffset());
}
//Reads the current system settings from EEPROM
//If anything looks weird, reset setting to default value
void readSystemSettings(void)
{
float settingCalibrationFactor; //Value used to convert the load cell reading to lbs or kg
long settingZeroOffset; //Zero value that is found when scale is tared
//Look up the calibration factor
EEPROM.get(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
if (settingCalibrationFactor == 0xFFFFFFFF)
{
settingCalibrationFactor = 0; //Default to 0
EEPROM.put(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
}
//Look up the zero tare point
EEPROM.get(LOCATION_ZERO_OFFSET, settingZeroOffset);
if (settingZeroOffset == 0xFFFFFFFF)
{
settingZeroOffset = 1000L; //Default to 1000 so we don't get inf
EEPROM.put(LOCATION_ZERO_OFFSET, settingZeroOffset);
}
//Pass these values to the library
myScale.setCalibrationFactor(settingCalibrationFactor);
myScale.setZeroOffset(settingZeroOffset);
settingsDetected = true; //Assume for the moment that there are good cal values
if (settingCalibrationFactor < 0.1 || settingZeroOffset == 1000)
settingsDetected = false; //Defaults detected. Prompt user to cal scale.
}
gets me this output
Qwiic Scale Example
Scale detected!
Zero offset: 0
Calibration factor: 0.00
0 10101110
1 111111
2 1110000
3 0
4 0
5 0
6 0
7 10000000
8 0
9 0
A 0
B 0
C 0
D 0
E 10000000
F 0
10 0
11 0
12 10000000
13 0
14 0
15 110000
16 0
1F 1111
Reading: -8388607 Weight: nan AvgWeight: nan Scale not calibrated. Press 'c'.
Reading: -8388608 Weight: nan AvgWeight: nan Scale not calibrated. Press 'c'.
Reading: -8388607 Weight: nan AvgWeight: nan Scale not calibrated. Press 'c'.
My load cell is 4, 120 ohm strain gauges hooked in a Wheatstone bridge configuration. with red going to the top, Black to the bottom and green/white to the side terminals.
When I hook my multimeter across red/black for the strain gauge, I get 0.4vdc.
When I check 3v3, I get 3.2vdc
I get the same results when no load cell is connected to the input. I still don’t get a voltage output from the NAU7802 board. I even tried going to a brand-new NAU7802 board since I bought a bunch for this project, but still am not getting anywhere.
Assuming I’m reading the registers correctly, VLDO seems to be set to 2.4v ia 0x01 register and is enabled by the AVDD bit on 0x00 register