@@ -937,6 +937,7 @@ void menuConfigure_NAU7802(void *configPtr)
937937 SerialPrintf2 (" \r\n Scale calibration factor: %s\r\n " , tempStr);
938938
939939 SerialPrintf2 (" Scale zero offset: %d\r\n " , sensorConfig->zeroOffset );
940+ SerialPrintf2 (" Scale offset register: %d\r\n " , sensor->get24BitRegister (NAU7802_OCAL1_B2));
940941
941942 sensor->getWeight (true , 10 ); // Flush
942943 olaftoa (sensor->getWeight (true , sensorConfig->averageAmount ), tempStr, sensorConfig->decimalPlaces , sizeof (tempStr) / sizeof (char ));
@@ -1024,9 +1025,10 @@ void menuConfigure_NAU7802(void *configPtr)
10241025 olaftoa (LDO, tempStr, 1 , sizeof (tempStr) / sizeof (char ));
10251026 SerialPrintf2 (" 9) LDO voltage: %s\r\n " , tempStr);
10261027 }
1027- SerialPrint (F (" 10) Use internal calibration: " ));
1028- if (sensorConfig->useCalibrationInternal == true ) SerialPrintln (F (" Enabled" ));
1029- else SerialPrintln (F (" Disabled" ));
1028+ SerialPrint (F (" 10) Calibration mode: " ));
1029+ if (sensorConfig->calibrationMode == 0 ) SerialPrintln (F (" None" ));
1030+ else if (sensorConfig->calibrationMode == 1 ) SerialPrintln (F (" Internal" ));
1031+ else SerialPrintln (F (" External" ));
10301032
10311033 SerialPrintln (F (" x) Exit" ));
10321034
@@ -1049,6 +1051,16 @@ void menuConfigure_NAU7802(void *configPtr)
10491051
10501052 sensor->getWeight (true , 10 ); // Flush
10511053
1054+ if (sensorConfig->calibrationMode == 2 ) // External calibration
1055+ {
1056+ sensor->calibrateAFE (NAU7802_CALMOD_OFFSET); // External offset calibration
1057+
1058+ sensorConfig->offsetReg = sensor->get24BitRegister (NAU7802_OCAL1_B2); // Save new offset
1059+ sensorConfig->gainReg = sensor->get32BitRegister (NAU7802_GCAL1_B3); // This should not have changed, but read it anyway
1060+
1061+ sensor->getWeight (true , 10 ); // Flush
1062+ }
1063+
10521064 sensor->calculateZeroOffset (sensorConfig->averageAmount ); // Zero or Tare the scale
10531065
10541066 sensorConfig->zeroOffset = sensor->getZeroOffset ();
@@ -1132,11 +1144,11 @@ void menuConfigure_NAU7802(void *configPtr)
11321144
11331145 sensor->setGain (sensorConfig->gain );
11341146
1135- if (sensorConfig->useCalibrationInternal )
1147+ if (sensorConfig->calibrationMode == 1 ) // Internal calibration
11361148 {
11371149 sensor->getWeight (true , 10 ); // Flush
11381150
1139- sensor->calibrateAFE (); // Recalibrate after changing gain / sample rate
1151+ sensor->calibrateAFE (NAU7802_CALMOD_INTERNAL ); // Recalibrate after changing gain / sample rate
11401152 }
11411153
11421154 SerialPrintln (F (" \r\n\r\n Gain updated. Please zero and calibrate the scale\r\n\r\n " ));
@@ -1151,13 +1163,14 @@ void menuConfigure_NAU7802(void *configPtr)
11511163
11521164 sensor->setSampleRate (sensorConfig->sampleRate );
11531165
1154- if (sensorConfig->useCalibrationInternal )
1166+ if (sensorConfig->calibrationMode == 1 ) // Internal calibration
11551167 {
11561168 sensor->getWeight (true , 10 ); // Flush
11571169
1158- sensor->calibrateAFE (); // Recalibrate after changing gain / sample rate
1170+ sensor->calibrateAFE (NAU7802_CALMOD_INTERNAL ); // Recalibrate after changing gain / sample rate
11591171 }
11601172
1173+ // Limit averageAmount (to prevent getWeight timing out after 1s)
11611174 if ((sensorConfig->sampleRate ) == 0 && (sensorConfig->averageAmount > 9 ))
11621175 sensorConfig->averageAmount = 9 ;
11631176 else if ((sensorConfig->sampleRate ) == 1 && (sensorConfig->averageAmount > 19 ))
@@ -1179,20 +1192,22 @@ void menuConfigure_NAU7802(void *configPtr)
11791192
11801193 sensor->setLDO (sensorConfig->LDO );
11811194
1182- if (sensorConfig->useCalibrationInternal )
1195+ if (sensorConfig->calibrationMode == 1 ) // Internal calibration
11831196 {
11841197 delay (sensor->getLDORampDelay ()); // Wait for LDO to ramp before attempting calibrateAFE
11851198
11861199 sensor->getWeight (true , 10 ); // Flush
11871200
1188- sensor->calibrateAFE (); // Recalibrate after changing gain / sample rate
1201+ sensor->calibrateAFE (NAU7802_CALMOD_INTERNAL ); // Recalibrate after changing gain / sample rate
11891202 }
11901203
11911204 SerialPrintln (F (" \r\n\r\n LDO updated. Please zero and calibrate the scale\r\n\r\n " ));
11921205 }
11931206 else if (incoming == 10 )
11941207 {
1195- sensorConfig->useCalibrationInternal ^= 1 ;
1208+ sensorConfig->calibrationMode += 1 ;
1209+ if (sensorConfig->calibrationMode == 3 )
1210+ sensorConfig->calibrationMode = 0 ;
11961211
11971212 sensor->reset ();
11981213 sensor->powerUp ();
@@ -1210,11 +1225,11 @@ void menuConfigure_NAU7802(void *configPtr)
12101225
12111226 delay (sensor->getLDORampDelay ()); // Wait for LDO to ramp before attempting calibrateAFE
12121227
1213- if (sensorConfig->useCalibrationInternal )
1228+ if (sensorConfig->calibrationMode == 1 ) // Internal calibration
12141229 {
12151230 sensor->getWeight (true , 10 ); // Flush
12161231
1217- sensor->calibrateAFE (); // Recalibrate after changing gain / sample rate
1232+ sensor->calibrateAFE (NAU7802_CALMOD_INTERNAL ); // Recalibrate after changing gain / sample rate
12181233 }
12191234
12201235 sensor->getWeight (true , 10 ); // Flush
0 commit comments