Skip to content

Commit e6b91f8

Browse files
authored
Merge pull request #6 from sparkfun/release_candidate
v1.0.5
2 parents 688f255 + 19793c2 commit e6b91f8

File tree

11 files changed

+422
-80
lines changed

11 files changed

+422
-80
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
Hardware Connections:
2828
Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
2929
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
30-
Open the serial monitor at 9600 baud to see the output
30+
Open the serial monitor at 115200 baud to see the output
3131
*/
3232

3333
#include <Wire.h>
@@ -38,7 +38,7 @@ NAU7802 myScale; //Create instance of the NAU7802 class
3838

3939
void setup()
4040
{
41-
Serial.begin(9600);
41+
Serial.begin(115200);
4242
Serial.println("Qwiic Scale Example");
4343

4444
Wire.begin();
@@ -55,7 +55,7 @@ void loop()
5555
{
5656
if(myScale.available() == true)
5757
{
58-
long currentReading = myScale.getReading();
58+
int32_t currentReading = myScale.getReading();
5959
Serial.print("Reading: ");
6060
Serial.println(currentReading);
6161
}

examples/Example2_CompleteScale/Example2_CompleteScale.ino

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
Hardware Connections:
3131
Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
3232
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
33-
Open the serial monitor at 9600 baud to see the output
33+
Open the serial monitor at 115200 baud to see the output
3434
*/
3535

3636
#include <Wire.h>
@@ -41,8 +41,9 @@
4141
NAU7802 myScale; //Create instance of the NAU7802 class
4242

4343
//EEPROM locations to store 4-byte variables
44+
#define EEPROM_SIZE 100 //Allocate 100 bytes of EEPROM
4445
#define LOCATION_CALIBRATION_FACTOR 0 //Float, requires 4 bytes of EEPROM
45-
#define LOCATION_ZERO_OFFSET 10 //Must be more than 4 away from previous spot. Long, requires 4 bytes of EEPROM
46+
#define LOCATION_ZERO_OFFSET 10 //Must be more than 4 away from previous spot. int32_t, requires 4 bytes of EEPROM
4647

4748
bool settingsDetected = false; //Used to prompt user to calibrate their scale
4849

@@ -53,7 +54,9 @@ byte avgWeightSpot = 0;
5354

5455
void setup()
5556
{
56-
Serial.begin(9600);
57+
EEPROM.begin(EEPROM_SIZE); //Some platforms need this. Comment this line if needed
58+
59+
Serial.begin(115200);
5760
Serial.println("Qwiic Scale Example");
5861

5962
Wire.begin();
@@ -75,13 +78,15 @@ void setup()
7578
Serial.println(myScale.getZeroOffset());
7679
Serial.print("Calibration factor: ");
7780
Serial.println(myScale.getCalibrationFactor());
81+
82+
Serial.println("\r\nPress 't' to Tare or Zero the scale.");
7883
}
7984

8085
void loop()
8186
{
8287
if (myScale.available() == true)
8388
{
84-
long currentReading = myScale.getReading();
89+
int32_t currentReading = myScale.getReading();
8590
float currentWeight = myScale.getWeight();
8691

8792
Serial.print("Reading: ");
@@ -156,6 +161,8 @@ void calibrateScale(void)
156161
Serial.println(myScale.getWeight(), 2);
157162

158163
recordSystemSettings(); //Commit these values to EEPROM
164+
165+
settingsDetected = true;
159166
}
160167

161168
//Record the current system settings to EEPROM
@@ -164,28 +171,30 @@ void recordSystemSettings(void)
164171
//Get various values from the library and commit them to NVM
165172
EEPROM.put(LOCATION_CALIBRATION_FACTOR, myScale.getCalibrationFactor());
166173
EEPROM.put(LOCATION_ZERO_OFFSET, myScale.getZeroOffset());
174+
175+
EEPROM.commit(); //Some platforms need this. Comment this line if needed
167176
}
168177

169178
//Reads the current system settings from EEPROM
170179
//If anything looks weird, reset setting to default value
171180
void readSystemSettings(void)
172181
{
173182
float settingCalibrationFactor; //Value used to convert the load cell reading to lbs or kg
174-
long settingZeroOffset; //Zero value that is found when scale is tared
183+
int32_t settingZeroOffset; //Zero value that is found when scale is tared
175184

176185
//Look up the calibration factor
177186
EEPROM.get(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
178187
if (settingCalibrationFactor == 0xFFFFFFFF)
179188
{
180-
settingCalibrationFactor = 0; //Default to 0
189+
settingCalibrationFactor = 1.0; //Default to 1.0
181190
EEPROM.put(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
182191
}
183192

184193
//Look up the zero tare point
185194
EEPROM.get(LOCATION_ZERO_OFFSET, settingZeroOffset);
186195
if (settingZeroOffset == 0xFFFFFFFF)
187196
{
188-
settingZeroOffset = 1000L; //Default to 1000 so we don't get inf
197+
settingZeroOffset = 0; //Default to 0 - i.e. no offset
189198
EEPROM.put(LOCATION_ZERO_OFFSET, settingZeroOffset);
190199
}
191200

@@ -194,6 +203,6 @@ void readSystemSettings(void)
194203
myScale.setZeroOffset(settingZeroOffset);
195204

196205
settingsDetected = true; //Assume for the moment that there are good cal values
197-
if (settingCalibrationFactor < 0.1 || settingZeroOffset == 1000)
206+
if (settingCalibrationFactor == 1.0 || settingZeroOffset == 0)
198207
settingsDetected = false; //Defaults detected. Prompt user to cal scale.
199208
}

examples/Example3_Gain_SampleRate/Example3_Gain_SampleRate.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Hardware Connections:
2424
Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
2525
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
26-
Open the serial monitor at 9600 baud to see the output
26+
Open the serial monitor at 115200 baud to see the output
2727
*/
2828

2929
#include <Wire.h>
@@ -34,7 +34,7 @@ NAU7802 myScale; //Create instance of the NAU7802 class
3434

3535
void setup()
3636
{
37-
Serial.begin(9600);
37+
Serial.begin(115200);
3838
Serial.println("Qwiic Scale Example");
3939

4040
Wire.begin();
@@ -57,7 +57,7 @@ void loop()
5757
{
5858
if(myScale.available() == true)
5959
{
60-
long currentReading = myScale.getReading();
60+
int32_t currentReading = myScale.getReading();
6161
Serial.print("Reading: ");
6262
Serial.println(currentReading);
6363
}

examples/Example4_LowPower/Example4_LowPower.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Hardware Connections:
1616
Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
1717
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
18-
Open the serial monitor at 9600 baud to see the output
18+
Open the serial monitor at 115200 baud to see the output
1919
*/
2020

2121
#include <Wire.h>
@@ -26,7 +26,7 @@ NAU7802 myScale; //Create instance of the NAU7802 class
2626

2727
void setup()
2828
{
29-
Serial.begin(9600);
29+
Serial.begin(115200);
3030
Serial.println("Qwiic Scale Example");
3131

3232
Wire.begin();
@@ -46,11 +46,11 @@ void loop()
4646
myScale.powerUp(); //Power up scale. This scale takes ~600ms to boot and take reading.
4747

4848
//Time how long it takes for scale to take a reading
49-
long startTime = millis();
49+
unsigned long startTime = millis();
5050
while(myScale.available() == false)
5151
delay(1);
5252

53-
long currentReading = myScale.getReading();
53+
int32_t currentReading = myScale.getReading();
5454
Serial.print("Startup time: ");
5555
Serial.print(millis() - startTime);
5656
Serial.print(", ");

examples/Example5_Interrupt/Example5_Interrupt.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Hardware Connections:
1616
Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
1717
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
18-
Open the serial monitor at 9600 baud to see the output
18+
Open the serial monitor at 115200 baud to see the output
1919
*/
2020

2121
#include <Wire.h>
@@ -30,7 +30,7 @@ void setup()
3030
{
3131
pinMode(interruptPin, INPUT); //No need for pullup. NAU7802 does not use open drain INT.
3232

33-
Serial.begin(9600);
33+
Serial.begin(115200);
3434
Serial.println("Qwiic Scale Example");
3535

3636
Wire.begin();
@@ -50,7 +50,7 @@ void loop()
5050
{
5151
if (digitalRead(interruptPin) == LOW)
5252
{
53-
long currentReading = myScale.getReading();
53+
int32_t currentReading = myScale.getReading();
5454
Serial.print("Reading: ");
5555
Serial.println(currentReading);
5656
}

examples/Example6_AdvancedI2C/Example6_AdvancedI2C.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Hardware Connections:
1616
Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
1717
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
18-
Open the serial monitor at 9600 baud to see the output
18+
Open the serial monitor at 115200 baud to see the output
1919
*/
2020

2121
#include <Wire.h>
@@ -26,7 +26,7 @@ NAU7802 myScale; //Create instance of the NAU7802 class
2626

2727
void setup()
2828
{
29-
Serial.begin(9600);
29+
Serial.begin(115200);
3030
Serial.println("Qwiic Scale Example");
3131

3232
Wire1.begin(); //This line won't compile on an Uno. This example is for other platforms that have multiple I2C ports.
@@ -44,7 +44,7 @@ void loop()
4444
{
4545
if (myScale.available())
4646
{
47-
long currentReading = myScale.getReading();
47+
int32_t currentReading = myScale.getReading();
4848
Serial.print("Reading: ");
4949
Serial.println(currentReading);
5050
}

0 commit comments

Comments
 (0)