add error messages, timeout tare
This commit is contained in:
parent
9b5afc68c7
commit
cf64e3b901
58
CG_scale.ino
58
CG_scale.ino
@ -4,7 +4,7 @@
|
|||||||
(c) 2019 by M. Lehmann
|
(c) 2019 by M. Lehmann
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
#define CGSCALE_VERSION "1.0.51"
|
#define CGSCALE_VERSION "1.0.55"
|
||||||
/*
|
/*
|
||||||
|
|
||||||
******************************************************************
|
******************************************************************
|
||||||
@ -180,6 +180,8 @@ unsigned long lastTimeMenu = 0;
|
|||||||
unsigned long lastTimeLoadcell = 0;
|
unsigned long lastTimeLoadcell = 0;
|
||||||
bool updateMenu = true;
|
bool updateMenu = true;
|
||||||
int menuPage = 0;
|
int menuPage = 0;
|
||||||
|
String errMsg[5] = "";
|
||||||
|
int errMsgCnt = 0;
|
||||||
|
|
||||||
|
|
||||||
// Restart CPU
|
// Restart CPU
|
||||||
@ -414,12 +416,35 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tare
|
// tare
|
||||||
|
byte loadcell_1_rdy = 0;
|
||||||
|
byte loadcell_2_rdy = 0;
|
||||||
|
byte loadcell_3_rdy = 0;
|
||||||
|
lastTimeLoadcell = millis();
|
||||||
|
|
||||||
|
while ((loadcell_1_rdy + loadcell_2_rdy + loadcell_3_rdy) < 3) {
|
||||||
|
loadcell_1_rdy = LoadCell_1.startMultiple(STABILISINGTIME);
|
||||||
|
loadcell_2_rdy = LoadCell_2.startMultiple(STABILISINGTIME);
|
||||||
if (nLoadcells > 2) {
|
if (nLoadcells > 2) {
|
||||||
while (!LoadCell_1.startMultiple(STABILISINGTIME) && !LoadCell_2.startMultiple(STABILISINGTIME) && !LoadCell_3.startMultiple(STABILISINGTIME)) {
|
loadcell_3_rdy = LoadCell_3.startMultiple(STABILISINGTIME);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
while (!LoadCell_1.startMultiple(STABILISINGTIME) && !LoadCell_2.startMultiple(STABILISINGTIME)) {
|
loadcell_3_rdy = 1;
|
||||||
}
|
}
|
||||||
|
// timeout
|
||||||
|
if ((millis() - lastTimeLoadcell) > TARE_TIMEOUT) {
|
||||||
|
errMsg[++errMsgCnt] = "ERROR: Timeout TARE\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check loadcells if error
|
||||||
|
if (!loadcell_1_rdy) {
|
||||||
|
errMsg[++errMsgCnt] = "ERROR: Loadcell 1 not ready\n";
|
||||||
|
}
|
||||||
|
if (!loadcell_2_rdy) {
|
||||||
|
errMsg[++errMsgCnt] = "ERROR: Loadcell 2 not ready\n";
|
||||||
|
}
|
||||||
|
if (!loadcell_3_rdy) {
|
||||||
|
errMsg[++errMsgCnt] = "ERROR: Loadcell 3 not ready\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// set calibration factor
|
// set calibration factor
|
||||||
@ -495,7 +520,7 @@ void loop() {
|
|||||||
if (nLoadcells > 2) {
|
if (nLoadcells > 2) {
|
||||||
CG_trans = (distanceX3 / 2) - (((weightLoadCell1 + weightLoadCell2 / 2) * distanceX3) / weightTotal);
|
CG_trans = (distanceX3 / 2) - (((weightLoadCell1 + weightLoadCell2 / 2) * distanceX3) / weightTotal);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
CG_length = 0;
|
CG_length = 0;
|
||||||
CG_trans = 0;
|
CG_trans = 0;
|
||||||
}
|
}
|
||||||
@ -521,6 +546,7 @@ void loop() {
|
|||||||
|
|
||||||
oledDisplay.firstPage();
|
oledDisplay.firstPage();
|
||||||
do {
|
do {
|
||||||
|
if (errMsgCnt == 0) {
|
||||||
// print battery
|
// print battery
|
||||||
if (enableBatVolt) {
|
if (enableBatVolt) {
|
||||||
oledDisplay.drawXBMP(88, 1, 12, 6, batteryImage);
|
oledDisplay.drawXBMP(88, 1, 12, 6, batteryImage);
|
||||||
@ -554,6 +580,13 @@ void loop() {
|
|||||||
oledDisplay.print(buff);
|
oledDisplay.print(buff);
|
||||||
oledDisplay.print(F(" mm"));
|
oledDisplay.print(F(" mm"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
oledDisplay.setFont(u8g2_font_5x7_tr);
|
||||||
|
for (int i = 1; i <= errMsgCnt; i++) {
|
||||||
|
oledDisplay.setCursor(0, 7 * i);
|
||||||
|
oledDisplay.print(errMsg[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} while ( oledDisplay.nextPage() );
|
} while ( oledDisplay.nextPage() );
|
||||||
|
|
||||||
@ -713,6 +746,9 @@ void loop() {
|
|||||||
Serial.print(F("disabled)\n"));
|
Serial.print(F("disabled)\n"));
|
||||||
}
|
}
|
||||||
Serial.print(F("14 - Show actual values\n15 - Reset to factory defaults\n\n"));
|
Serial.print(F("14 - Show actual values\n15 - Reset to factory defaults\n\n"));
|
||||||
|
for (int i = 1; i <= errMsgCnt; i++) {
|
||||||
|
Serial.print(errMsg[i]);
|
||||||
|
}
|
||||||
Serial.print(F("Please choose the menu number:"));
|
Serial.print(F("Please choose the menu number:"));
|
||||||
updateMenu = false;
|
updateMenu = false;
|
||||||
break;
|
break;
|
||||||
@ -875,7 +911,7 @@ void main_page()
|
|||||||
webPage += "<br><br><br>";
|
webPage += "<br><br><br>";
|
||||||
webPage += "<main role=\"main\" class=\"container\">";
|
webPage += "<main role=\"main\" class=\"container\">";
|
||||||
webPage += "<div class=\"jumbotron\">";
|
webPage += "<div class=\"jumbotron\">";
|
||||||
|
if (errMsgCnt == 0) {
|
||||||
// print weight
|
// print weight
|
||||||
webPage += "<div class=\"container\">";
|
webPage += "<div class=\"container\">";
|
||||||
webPage += "<div class=\"row mt-3\">";
|
webPage += "<div class=\"row mt-3\">";
|
||||||
@ -900,7 +936,6 @@ void main_page()
|
|||||||
|
|
||||||
// print cg trans
|
// print cg trans
|
||||||
if (nLoadcells > 2) {
|
if (nLoadcells > 2) {
|
||||||
//webPage += "<br>";
|
|
||||||
webPage += "<div class=\"container\">";
|
webPage += "<div class=\"container\">";
|
||||||
webPage += "<div class=\"row mt-3\">";
|
webPage += "<div class=\"row mt-3\">";
|
||||||
webPage += "<div class=\"col-xs-6\"><img src=\"cglr.png\" class=\"pull-left mr-4\" alt=\"weight\" style=\"width:auto;height:50px\"></div>";
|
webPage += "<div class=\"col-xs-6\"><img src=\"cglr.png\" class=\"pull-left mr-4\" alt=\"weight\" style=\"width:auto;height:50px\"></div>";
|
||||||
@ -915,7 +950,6 @@ void main_page()
|
|||||||
|
|
||||||
// print battery
|
// print battery
|
||||||
if (enableBatVolt) {
|
if (enableBatVolt) {
|
||||||
//webPage += "<br>";
|
|
||||||
webPage += "<div class=\"container\">";
|
webPage += "<div class=\"container\">";
|
||||||
webPage += "<div class=\"row mt-3\">";
|
webPage += "<div class=\"row mt-3\">";
|
||||||
webPage += "<div class=\"col-xs-6\"><img src=\"battery.png\" class=\"pull-left mr-4\" alt=\"weight\" style=\"width:auto;height:50px\"></div>";
|
webPage += "<div class=\"col-xs-6\"><img src=\"battery.png\" class=\"pull-left mr-4\" alt=\"weight\" style=\"width:auto;height:50px\"></div>";
|
||||||
@ -925,6 +959,14 @@ void main_page()
|
|||||||
webPage += "</div>";
|
webPage += "</div>";
|
||||||
webPage += "</div>";
|
webPage += "</div>";
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
webPage += "<div class=\"container\">";
|
||||||
|
webPage += "<font size=\"6\"> ";
|
||||||
|
for (int i = 1; i <= errMsgCnt; i++) {
|
||||||
|
webPage += errMsg[i];
|
||||||
|
}
|
||||||
|
webPage += "</div>";
|
||||||
|
}
|
||||||
webPage += "</div>";
|
webPage += "</div>";
|
||||||
webPage += "</main>";
|
webPage += "</main>";
|
||||||
webPage += "<p><font size=\"2\"><center>(c) 2019 M. Lehmann - Version: ";
|
webPage += "<p><font size=\"2\"><center>(c) 2019 M. Lehmann - Version: ";
|
||||||
|
@ -59,6 +59,7 @@ CG scale with 3 Loadcells:
|
|||||||
// **** Measurement settings ****
|
// **** Measurement settings ****
|
||||||
|
|
||||||
#define STABILISINGTIME 3000 // ms
|
#define STABILISINGTIME 3000 // ms
|
||||||
|
#define TARE_TIMEOUT 4000 // ms
|
||||||
|
|
||||||
#define UPDATE_INTERVAL_OLED_MENU 500 // ms
|
#define UPDATE_INTERVAL_OLED_MENU 500 // ms
|
||||||
#define UPDATE_INTERVAL_LOADCELL 100 // ms
|
#define UPDATE_INTERVAL_LOADCELL 100 // ms
|
||||||
|
@ -59,6 +59,7 @@ CG scale with 3 Loadcells:
|
|||||||
// **** Measurement settings ****
|
// **** Measurement settings ****
|
||||||
|
|
||||||
#define STABILISINGTIME 3000 // ms
|
#define STABILISINGTIME 3000 // ms
|
||||||
|
#define TARE_TIMEOUT 4000 // ms
|
||||||
|
|
||||||
#define UPDATE_INTERVAL_OLED_MENU 500 // ms
|
#define UPDATE_INTERVAL_OLED_MENU 500 // ms
|
||||||
#define UPDATE_INTERVAL_LOADCELL 100 // ms
|
#define UPDATE_INTERVAL_LOADCELL 100 // ms
|
||||||
@ -100,8 +101,8 @@ U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NON
|
|||||||
#define V_REF 3300 // set supply voltage from 1800 to 5500mV
|
#define V_REF 3300 // set supply voltage from 1800 to 5500mV
|
||||||
|
|
||||||
// voltage divider
|
// voltage divider
|
||||||
#define RESISTOR_R1 10000 // ohm
|
#define RESISTOR_R1 20000 // ohm
|
||||||
#define RESISTOR_R2 20000 // ohm
|
#define RESISTOR_R2 10000 // ohm
|
||||||
|
|
||||||
/*
|
/*
|
||||||
voltage input
|
voltage input
|
||||||
|
Loading…
x
Reference in New Issue
Block a user