diff --git a/CG_scale.ino b/CG_scale.ino
index 32d829f..f887475 100644
--- a/CG_scale.ino
+++ b/CG_scale.ino
@@ -4,18 +4,32 @@
(c) 2019 by M. Lehmann
------------------------------------------------------------------
*/
-#define CGSCALE_VERSION "2.0"
+#define CGSCALE_VERSION "2.11"
/*
******************************************************************
history:
+ V2.11 18.08.20 code is now compatible with standard OLED displays
+ and original code base (default pw length = 32)
+ V2.1 18.07.20 added support for ESP8266 based Wifi Kit 8
+ (by Pulsar07/ (https://heltec.org/project/wifi-kit-8/)
+ R.Stransky is a ESP8266 with
+ a build in OLED 128x32
+ battery connector with charging management
+ reset and GPIO0 button
+ support for a tare button (PIN_TARE_BUTTON)
+ bug fixed: wifi password now with up to 64 chars
+ bug fixed: wifi data (ssid/passwd) with special
+ character (e.g. +) is now supported
+ for specified battery type, voltage is displayed
+ using uncompressed html files makes WEB GUI much faster
V2.01 29.01.20 small bug fixes with AVR
V2.0 26.01.20 Webpage rewritten, no bootstrap framework needed
add translation to webpage (en, de)
optimized for measuring with landinggears
updated to ArduinoJson V6
firmware update over web interface
- V1.2.1 31.03.19 small bug fixed
+ V1.2.1 31.03.19 small bug fixed
values in model database are rounded
mDNS and OTA did not work in AP mode
V1.2 23.02.19 Add OTA (over the air update)
@@ -87,7 +101,7 @@
#endif
// HX711 constructor array (dout pin, sck pint):
-HX711_ADC LoadCell[]{HX711_ADC(PIN_LOADCELL1_DOUT, PIN_LOADCELL1_PD_SCK),HX711_ADC(PIN_LOADCELL2_DOUT, PIN_LOADCELL2_PD_SCK),HX711_ADC(PIN_LOADCELL3_DOUT, PIN_LOADCELL3_PD_SCK)};
+HX711_ADC LoadCell[] {HX711_ADC(PIN_LOADCELL1_DOUT, PIN_LOADCELL1_PD_SCK), HX711_ADC(PIN_LOADCELL2_DOUT, PIN_LOADCELL2_PD_SCK), HX711_ADC(PIN_LOADCELL3_DOUT, PIN_LOADCELL3_PD_SCK)};
// webserver constructor
#if defined(ESP8266)
@@ -142,6 +156,12 @@ bool updateMenu = true;
int menuPage = 0;
String errMsg[5];
int errMsgCnt = 0;
+int oledDisplayHeight;
+int oledDisplayWidth;
+const uint8_t *oledFontLarge;
+const uint8_t *oledFontNormal;
+const uint8_t *oledFontSmall;
+const uint8_t *oledFontTiny;
#if defined(ESP8266)
String updateMsg = "";
bool wifiSTAmode = true;
@@ -156,6 +176,200 @@ void(* resetCPU) (void) = 0;
void resetCPU() {}
#endif
+void initOLED() {
+ oledDisplay.begin();
+ oledDisplayHeight = oledDisplay.getDisplayHeight();
+ oledDisplayWidth = oledDisplay.getDisplayWidth();
+ printConsole(T_BOOT, "init OLED display: " + String(oledDisplayWidth) + String("x") + String(oledDisplayHeight));
+
+
+ oledFontLarge = u8g2_font_helvR12_tr;
+ oledFontNormal = u8g2_font_helvR10_tr;
+ oledFontSmall = u8g2_font_5x7_tr;
+ oledFontTiny = u8g2_font_4x6_tr;
+
+ if (oledDisplayHeight <= 32) {
+ oledFontLarge = u8g2_font_helvR10_tr;
+ oledFontNormal = u8g2_font_6x12_tr;
+ }
+ int ylineHeight = oledDisplayHeight / 3;
+
+ oledDisplay.setFont(oledFontNormal);
+
+ oledDisplay.firstPage();
+ do {
+ oledDisplay.setFont(oledFontLarge);
+ if (oledDisplayHeight <= 32) {
+ oledDisplay.drawXBMP(5, 0, 18, 18, CGImage);
+ } else {
+ oledDisplay.drawXBMP(20, 12, 18, 18, CGImage);
+ }
+ oledDisplay.setFont(oledFontLarge);
+
+ if (oledDisplayHeight <= 32) {
+ oledDisplay.setCursor(30, 12);
+ } else {
+ oledDisplay.setCursor(45, 28);
+ }
+ oledDisplay.print(F("CG scale"));
+
+ oledDisplay.setFont(oledFontSmall);
+ if (oledDisplayHeight <= 32) {
+ oledDisplay.setCursor(30, 22);
+ } else {
+ oledDisplay.setCursor(35, 55);
+ }
+ oledDisplay.print(F("Version: "));
+ oledDisplay.print(CGSCALE_VERSION);
+ if (oledDisplayHeight <= 32) {
+ oledDisplay.setCursor(5, 31);
+ } else {
+ oledDisplay.setCursor(20, 64);
+ }
+ oledDisplay.print(F("(c) 2019 M.Lehmann et al."));
+
+ } while ( oledDisplay.nextPage() );
+}
+
+void printOLED(String aLine1, String aLine2, String aLine3 = String(""));
+
+void printOLED(String aLine1, String aLine2, String aLine3) {
+ int ylineHeight = oledDisplayHeight / 3;
+
+ oledDisplay.firstPage();
+ do {
+ oledDisplay.setFont(oledFontNormal);
+ oledDisplay.setCursor(0, ylineHeight * 1);
+ oledDisplay.print(aLine1);
+ oledDisplay.setCursor(0, ylineHeight * 2);
+ oledDisplay.print(aLine2);
+ if (aLine3 == "") {
+ oledDisplay.drawLine(0, ylineHeight * 2 + 2, oledDisplayWidth, ylineHeight * 2 + 2);
+ oledDisplay.setFont(oledFontTiny);
+ oledDisplay.setCursor(0, oledDisplayHeight);
+ oledDisplay.print("IP:" + WiFi.localIP().toString());
+ String signature = "CG scale: V" + String(CGSCALE_VERSION);
+ oledDisplay.setCursor(oledDisplayWidth - oledDisplay.getStrWidth(signature.c_str()), oledDisplayHeight);
+ oledDisplay.print(signature);
+ } else {
+ oledDisplay.setCursor(0, oledDisplayHeight);
+ oledDisplay.print(aLine3);
+ }
+ } while ( oledDisplay.nextPage() );
+}
+
+void printScaleOLED() {
+ // print to display
+ char buff1[8];
+ char buff[12];
+ char buff2[8];
+ int pos_weightTotal = 7;
+ int pos_CG_length = 28;
+ if (nLoadcells == 2) {
+ pos_weightTotal = 17;
+ pos_CG_length = 45;
+ if (batType == 0) {
+ pos_weightTotal = 12;
+ pos_CG_length = 40;
+ }
+ }
+
+ oledDisplay.firstPage();
+ do {
+ if (errMsgCnt == 0) {
+ // print battery
+ if (batType > B_OFF) {
+ oledDisplay.drawXBMP(48, 1, 12, 6, batteryImage);
+ float percentVolt = percentBat(batVolt / batCells);
+ dtostrf(percentVolt, 3, 0, buff);
+ oledDisplay.drawBox(49, 2, (percentVolt / (100 / 8)), 4);
+
+ oledDisplay.setFont(oledFontSmall);
+ oledDisplay.setCursor(78 - oledDisplay.getStrWidth(buff), 7);
+ if (batType > B_VOLT) {
+ dtostrf(percentVolt, 3, 0, buff);
+ oledDisplay.print(buff);
+ oledDisplay.print(F("%/"));
+ }
+ dtostrf(batVolt, 2, 2, buff);
+ oledDisplay.print(buff);
+ oledDisplay.print(F("V"));
+ }
+
+ // print total weight
+ oledDisplay.setFont(oledFontNormal);
+ dtostrf(weightTotal, 7, 1, buff);
+ if (oledDisplayHeight <= 32) {
+ oledDisplay.setCursor(1, 18);
+ oledDisplay.print(F("M = "));
+ } else {
+ oledDisplay.drawXBMP(2, pos_weightTotal, 18, 18, weightImage);
+ oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_weightTotal + 17);
+ }
+ oledDisplay.print(buff);
+ oledDisplay.print(F(" g"));
+
+ // print CG longitudinal axis
+ dtostrf(CG_length, 7, 1, buff);
+ if (oledDisplayHeight <= 32) {
+ oledDisplay.setCursor(1, 32);
+ oledDisplay.print(F("CG = "));
+ } else {
+ oledDisplay.drawXBMP(2, pos_CG_length, 18, 18, CGImage);
+ oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_CG_length + 16);
+ }
+ oledDisplay.print(buff);
+ oledDisplay.print(F(" mm"));
+
+ // print CG transverse axis
+ if (nLoadcells == 3) {
+ if (oledDisplayHeight <= 32) {
+ oledDisplay.setCursor(78, 32);
+ oledDisplay.print(F("LR="));
+ dtostrf(CG_trans, 3, 0, buff);
+ } else {
+ oledDisplay.drawXBMP(2, 47, 18, 18, CGtransImage);
+ oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), 64);
+ dtostrf(CG_trans, 7, 1, buff);
+ }
+ oledDisplay.print(buff);
+ oledDisplay.print(F(" mm"));
+ }
+ } else {
+ oledDisplay.setFont(oledFontSmall);
+ for (int i = 1; i <= errMsgCnt; i++) {
+ oledDisplay.setCursor(0, 7 * i);
+ oledDisplay.print(errMsg[i]);
+ }
+ }
+
+ } while ( oledDisplay.nextPage() );
+}
+
+
+
+#ifdef PIN_TARE_BUTTON
+void handleTareBtn() {
+ static unsigned long lastTaraBtn = 0;
+ if ((millis() - lastTaraBtn) > 20) {
+ lastTaraBtn = millis();
+ static int tareBtnCnt = 0;
+ if (digitalRead(PIN_TARE_BUTTON)) {
+ tareBtnCnt = 0;
+ } else {
+ tareBtnCnt++;
+ if (tareBtnCnt > 10) {
+ Serial.println("tare button pressed");
+ printOLED("TARE ==>", " tare load cells ...");
+ // avoid keybounce
+ tareBtnCnt = -1000;
+ tareLoadcells();
+ delay(2000);
+ }
+ }
+ }
+}
+#endif
// save calibration factor
void saveCalFactor(int nLC) {
@@ -167,7 +381,7 @@ void saveCalFactor(int nLC) {
}
-void updateLoadcells(){
+void updateLoadcells() {
for (int i = LC1; i <= LC3; i++) {
if (i < nLoadcells) {
LoadCell[i].update();
@@ -176,7 +390,7 @@ void updateLoadcells(){
}
-void tareLoadcells(){
+void tareLoadcells() {
for (int i = LC1; i <= LC3; i++) {
if (i < nLoadcells) {
LoadCell[i].tare();
@@ -185,7 +399,7 @@ void tareLoadcells(){
}
-void printNewValueText(){
+void printNewValueText() {
Serial.print(F("Set new value:"));
}
@@ -210,7 +424,7 @@ bool runAutoCalibrate() {
calFactorLoadcell[i] = calFactorLoadcell[i] / (toWeightLoadCell[i] / weightLoadCell[i]);
saveCalFactor(i);
}
-
+
// finish
Serial.println(F("done"));
}
@@ -250,7 +464,7 @@ int percentBat(float cellVoltage) {
break;
}
}
-
+
float cellempty = pgm_read_float( &percentList[batTypeArray][0][0]);
float cellfull = pgm_read_float( &percentList[batTypeArray][elementCount][0]);
@@ -262,9 +476,9 @@ int percentBat(float cellVoltage) {
for (int i = 0; i <= elementCount; i++) {
float curVolt = pgm_read_float(&percentList[batTypeArray][i][0]);
if (curVolt >= cellVoltage && i > 0) {
- float lastVolt = pgm_read_float(&percentList[batTypeArray][i-1][0]);
+ float lastVolt = pgm_read_float(&percentList[batTypeArray][i - 1][0]);
float curPercent = pgm_read_float(&percentList[batTypeArray][i][1]);
- float lastPercent = pgm_read_float(&percentList[batTypeArray][i-1][1]);
+ float lastPercent = pgm_read_float(&percentList[batTypeArray][i - 1][1]);
result = float((cellVoltage - lastVolt) / (curVolt - lastVolt)) * (curPercent - lastPercent) + lastPercent;
break;
}
@@ -279,12 +493,13 @@ int percentBat(float cellVoltage) {
void setup() {
// init serial
- Serial.begin(9600);
+ Serial.begin(115200);
Serial.println();
+ delay(1000);
#if defined(ESP8266)
printConsole(T_BOOT, "startup CG scale V" + String(CGSCALE_VERSION));
-
+
// init filesystem
SPIFFS.begin();
EEPROM.begin(EEPROM_SIZE);
@@ -367,24 +582,7 @@ void setup() {
#endif
// init OLED display
-#if defined(ESP8266)
- printConsole(T_BOOT, "init OLED display");
-#endif
- oledDisplay.begin();
- oledDisplay.firstPage();
- do {
- oledDisplay.drawXBMP(20, 12, 18, 18, CGImage);
- oledDisplay.setFont(u8g2_font_helvR12_tr);
- oledDisplay.setCursor(45, 28);
- oledDisplay.print(F("CG scale"));
-
- oledDisplay.setFont(u8g2_font_5x7_tr);
- oledDisplay.setCursor(35, 55);
- oledDisplay.print(F("Version: "));
- oledDisplay.print(CGSCALE_VERSION);
- oledDisplay.setCursor(20, 64);
- oledDisplay.print(F("(c) 2019 M. Lehmann"));
- } while ( oledDisplay.nextPage() );
+ initOLED();
// init & tare Loadcells
for (int i = LC1; i <= LC3; i++) {
@@ -392,7 +590,7 @@ void setup() {
LoadCell[i].begin();
LoadCell[i].setCalFactor(calFactorLoadcell[i]);
#if defined(ESP8266)
- printConsole(T_BOOT, "init Loadcell " + String(i+1));
+ printConsole(T_BOOT, "init Loadcell " + String(i + 1));
#endif
}
}
@@ -408,28 +606,32 @@ void setup() {
#if defined(ESP8266)
+ printConsole(T_BOOT, "Wifi: STA mode - connecing with: " + String(ssid_STA));
+
// Start by connecting to a WiFi network
+ WiFi.persistent(false);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid_STA, password_STA);
- printConsole(T_BOOT, "Wifi: STA mode - connect with: " + String(ssid_STA));
long timeoutWiFi = millis();
while (WiFi.status() != WL_CONNECTED) {
delay(500);
+ Serial.print(".");
if (WiFi.status() == WL_NO_SSID_AVAIL) {
- printConsole(T_ERROR, "Wifi: No SSID available");
+ printConsole(T_ERROR, "\nWifi: No SSID available");
break;
} else if (WiFi.status() == WL_CONNECT_FAILED) {
- printConsole(T_ERROR, "Wifi: Connection failed");
+ printConsole(T_ERROR, "\nWifi: Connection failed");
break;
} else if ((millis() - timeoutWiFi) > TIMEOUT_CONNECT) {
- printConsole(T_ERROR, "Wifi: Timeout");
+ printConsole(T_ERROR, "\nWifi: Timeout");
break;
}
}
+
if (WiFi.status() != WL_CONNECTED) {
// if WiFi not connected, switch to access point mode
wifiSTAmode = false;
@@ -442,7 +644,7 @@ void setup() {
printConsole(T_RUN, "Wifi: Connected, IP: " + String(WiFi.localIP().toString()));
}
-
+
// Set Hostname
String hostname = "disabled";
#if ENABLE_MDNS
@@ -452,40 +654,22 @@ void setup() {
if (!MDNS.begin(hostname, WiFi.localIP())) {
hostname = "mDNS failed";
printConsole(T_ERROR, "Wifi: " + hostname);
- }else{
+ } else {
hostname += ".local";
printConsole(T_RUN, "Wifi: " + hostname);
}
#endif
+ if (wifiSTAmode) {
+ printOLED("WiFi: " + String(ssid_STA),
+ "Host: " + String(hostname),
+ "IP : " + WiFi.localIP().toString());
+ } else {
+ printOLED("WiFi: " + String(ssid_AP),
+ "Host: " + String(hostname),
+ "IP : " + WiFi.softAPIP().toString());
+ }
- // print wifi status
- oledDisplay.firstPage();
- do {
- oledDisplay.setFont(u8g2_font_5x7_tr);
- oledDisplay.setCursor(0, 14);
- oledDisplay.print(F("WiFi:"));
- oledDisplay.setCursor(0, 39);
- oledDisplay.print(F("Host:"));
- oledDisplay.setCursor(0, 64);
- oledDisplay.print(F("IP:"));
-
- oledDisplay.setFont(u8g2_font_helvR10_tr);
- oledDisplay.setCursor(28, 14);
- if (wifiSTAmode) {
- oledDisplay.print(ssid_STA);
- } else {
- oledDisplay.print(ssid_AP);
- }
- oledDisplay.setCursor(28, 39);
- oledDisplay.print(hostname);
- oledDisplay.setCursor(28, 64);
- if (wifiSTAmode) {
- oledDisplay.print(WiFi.localIP());
- } else {
- oledDisplay.print(WiFi.softAPIP());
- }
- } while ( oledDisplay.nextPage() );
delay(3000);
// When the client requests data
@@ -520,10 +704,10 @@ void setup() {
printConsole(T_RUN, "Webserver is up and running");
// init OTA (over the air update)
- if(enableOTA){
+ if (enableOTA) {
ArduinoOTA.setHostname(ssid_AP);
ArduinoOTA.setPassword(password_AP);
-
+
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
@@ -535,16 +719,16 @@ void setup() {
updateMsg = "Updating " + type;
printConsole(T_UPDATE, type);
});
-
+
ArduinoOTA.onEnd([]() {
updateMsg = "successful..";
printUpdateProgress(100, 100);
});
-
+
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
printUpdateProgress(progress, total);
});
-
+
ArduinoOTA.onError([](ota_error_t error) {
if (error == OTA_AUTH_ERROR) {
updateMsg = "Auth Failed";
@@ -563,14 +747,14 @@ void setup() {
ArduinoOTA.begin();
printConsole(T_RUN, "OTA is up and running");
}
-
- // https update
+
+ // https update
httpsClient.setInsecure();
- if(enableUpdate){
+ if (enableUpdate) {
// check for update
httpsUpdate(PROBE_UPDATE);
}
-
+
#endif
}
@@ -584,12 +768,16 @@ void loop() {
MDNS.update();
#endif
- if(enableOTA){
+ if (enableOTA) {
ArduinoOTA.handle();
}
server.handleClient();
#endif
+#ifdef PIN_TARE_BUTTON
+ handleTareBtn();
+#endif
+
updateLoadcells();
// update loadcell values
@@ -607,6 +795,7 @@ void loop() {
}
}
+
// update display and serial menu
if ((millis() - lastTimeMenu) > UPDATE_INTERVAL_OLED_MENU) {
@@ -623,9 +812,9 @@ void loop() {
CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) + model.distance[X1];
#if defined(ESP8266)
- if(model.mechanicsType == 2){
+ if (model.mechanicsType == 2) {
CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) - model.distance[X1];
- }else if(model.mechanicsType == 3){
+ } else if (model.mechanicsType == 3) {
CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) * -1 + model.distance[X1];
}
#endif
@@ -643,80 +832,9 @@ void loop() {
// read battery voltage
if (batType > B_OFF) {
batVolt = (analogRead(VOLTAGE_PIN) / 1024.0) * V_REF * ((resistor[R1] + resistor[R2]) / resistor[R2]) / 1000.0;
-#if ENABLE_PERCENTLIST
- if (batType > B_VOLT) {
- batVolt = percentBat(batVolt / batCells);
- }
-#endif
}
- // print to display
- char buff[8];
- int pos_weightTotal = 7;
- int pos_CG_length = 28;
- if (nLoadcells == 2) {
- pos_weightTotal = 17;
- pos_CG_length = 45;
- if (batType == 0) {
- pos_weightTotal = 12;
- pos_CG_length = 40;
- }
- }
-
- oledDisplay.firstPage();
- do {
- if (errMsgCnt == 0) {
- // print battery
- if (batType > B_OFF) {
- oledDisplay.drawXBMP(88, 1, 12, 6, batteryImage);
- if (batType == B_VOLT) {
- dtostrf(batVolt, 2, 2, buff);
- } else {
- dtostrf(batVolt, 3, 0, buff);
- oledDisplay.drawBox(89, 2, (batVolt / (100 / 8)), 4);
- }
- oledDisplay.setFont(u8g2_font_5x7_tr);
- oledDisplay.setCursor(123 - oledDisplay.getStrWidth(buff), 7);
- oledDisplay.print(buff);
- if (batType == B_VOLT) {
- oledDisplay.print(F("V"));
- } else {
- oledDisplay.print(F("%"));
- }
- }
-
- // print total weight
- oledDisplay.drawXBMP(2, pos_weightTotal, 18, 18, weightImage);
- dtostrf(weightTotal, 5, 1, buff);
- oledDisplay.setFont(u8g2_font_helvR12_tr);
- oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_weightTotal + 17);
- oledDisplay.print(buff);
- oledDisplay.print(F(" g"));
-
- // print CG longitudinal axis
- oledDisplay.drawXBMP(2, pos_CG_length, 18, 18, CGImage);
- dtostrf(CG_length, 5, 1, buff);
- oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_CG_length + 16);
- oledDisplay.print(buff);
- oledDisplay.print(F(" mm"));
-
- // print CG transverse axis
- if (nLoadcells == 3) {
- oledDisplay.drawXBMP(2, 47, 18, 18, CGtransImage);
- dtostrf(CG_trans, 5, 1, buff);
- oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), 64);
- oledDisplay.print(buff);
- 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() );
+ printScaleOLED();
// serial connection
if (Serial) {
@@ -839,7 +957,7 @@ void loop() {
switch (menuPage)
{
case MENU_HOME: {
- Serial.print(F("\n\n********************************************\nCG scale by M.Lehmann - V"));
+ Serial.print(F("\n\n********************************************\nCG scale by M.Lehmann et al. - V"));
Serial.print(CGSCALE_VERSION);
Serial.print(F("\n\n"));
@@ -851,7 +969,7 @@ void loop() {
for (int i = X1; i <= X3; i++) {
Serial.print(MENU_DISTANCE_X1 + i);
Serial.print(F(" - Set distance X"));
- Serial.print(i+1);
+ Serial.print(i + 1);
Serial.print(F(" ("));
Serial.print(model.distance[i]);
Serial.print(F("mm)\n"));
@@ -872,9 +990,9 @@ void loop() {
for (int i = LC1; i <= LC3; i++) {
Serial.print(MENU_LOADCELL1_CALIBRATION_FACTOR + i);
- if((MENU_LOADCELL1_CALIBRATION_FACTOR + i) < 10) Serial.print(F(" "));
+ if ((MENU_LOADCELL1_CALIBRATION_FACTOR + i) < 10) Serial.print(F(" "));
Serial.print(F(" - Set calibration factor of load cell "));
- Serial.print(i+1);
+ Serial.print(i + 1);
Serial.print(F(" ("));
Serial.print(calFactorLoadcell[i]);
Serial.print(F(")\n"));
@@ -883,7 +1001,7 @@ void loop() {
for (int i = R1; i <= R2; i++) {
Serial.print(MENU_RESISTOR_R1 + i);
Serial.print(F(" - Set value of resistor R"));
- Serial.print(i+1);
+ Serial.print(i + 1);
Serial.print(F(" ("));
Serial.print(resistor[i]);
Serial.print(F("ohm)\n"));
@@ -1112,10 +1230,16 @@ void getValue() {
response += buff;
response += "V";
} else {
- dtostrf(batVolt, 5, 0, buff);
+ float percentVolt = percentBat(batVolt / batCells);
+ dtostrf(percentVolt, 5, 0, buff);
response += buff;
- response += "%";
+ response += "%/";
+ dtostrf(batVolt, 5, 2, buff);
+ response += buff;
+ response += "V";
}
+ Serial.print("send response: ");
+ Serial.println(response);
server.send(200, "text/html", response);
}
@@ -1138,9 +1262,13 @@ void getRawValue() {
response += buff;
response += "V";
} else {
- dtostrf(batVolt, 5, 0, buff);
+ float percentVolt = percentBat(batVolt / batCells);
+ dtostrf(percentVolt, 5, 0, buff);
response += buff;
- response += "%";
+ response += "%/";
+ dtostrf(batVolt, 5, 2, buff);
+ response += buff;
+ response += "V";
}
server.send(200, "text/html", response);
}
@@ -1234,14 +1362,14 @@ void getWiFiNetworks() {
bool ssidSTAavailable = false;
String response = "";
int n = WiFi.scanNetworks();
-
+
if (n > 0) {
for (int i = 0; i < n; ++i) {
response += WiFi.SSID(i);
- if(WiFi.SSID(i) == ssid_STA) ssidSTAavailable = true;
+ if (WiFi.SSID(i) == ssid_STA) ssidSTAavailable = true;
if (i < n - 1) response += "&";
}
- if(!ssidSTAavailable){
+ if (!ssidSTAavailable) {
response += "&";
response += ssid_STA;
}
@@ -1293,7 +1421,7 @@ void saveParameter() {
EEPROM.put(P_ENABLE_OTA, enableOTA);
EEPROM.commit();
- if(model.name != ""){
+ if (model.name != "") {
saveModelJson(model.name);
}
@@ -1554,7 +1682,7 @@ bool deleteModelJson(String modelName) {
void writeModelData(JsonObject object) {
char buff[8];
String stringBuff;
-
+
dtostrf(weightTotal, 5, 1, buff);
stringBuff = buff;
stringBuff.trim();
@@ -1579,14 +1707,13 @@ void writeModelData(JsonObject object) {
// print update progress screen
void printUpdateProgress(unsigned int progress, unsigned int total) {
printConsole(T_UPDATE, updateMsg);
-
+
oledDisplay.firstPage();
do {
- oledDisplay.setFont(u8g2_font_helvR08_tr);
+ oledDisplay.setFont(oledFontSmall);
oledDisplay.setCursor(0, 12);
oledDisplay.print(updateMsg);
- oledDisplay.setFont(u8g2_font_5x7_tr);
oledDisplay.setCursor(107, 35);
oledDisplay.printf("%u%%\r", (progress / (total / 100)));
@@ -1611,10 +1738,10 @@ char * TimeToString(unsigned long t)
return str;
}
-void printConsole(int t, String msg){
+void printConsole(int t, String msg) {
Serial.print(TimeToString(millis()));
Serial.print(" [");
- switch(t) {
+ switch (t) {
case T_BOOT:
Serial.print("BOOT");
break;
@@ -1640,7 +1767,7 @@ void printConsole(int t, String msg){
// https update
-bool httpsUpdate(uint8_t command){
+bool httpsUpdate(uint8_t command) {
if (!httpsClient.connect(HOST, HTTPS_PORT)) {
printConsole(T_ERROR, "Wifi: connection to GIT failed");
return false;
@@ -1648,44 +1775,44 @@ bool httpsUpdate(uint8_t command){
const char * headerKeys[] = {"Location"} ;
const size_t numberOfHeaders = 1;
-
+
HTTPClient https;
https.setUserAgent("cgscale");
https.setRedirectLimit(0);
https.setFollowRedirects(true);
String url = "https://" + String(HOST) + String(URL);
- if (https.begin(httpsClient, url)) {
+ if (https.begin(httpsClient, url)) {
https.collectHeaders(headerKeys, numberOfHeaders);
printConsole(T_HTTPS, "GET: " + url);
int httpCode = https.GET();
- if (httpCode > 0) {
+ if (httpCode > 0) {
// response
- if (httpCode == HTTP_CODE_FOUND) {
+ if (httpCode == HTTP_CODE_FOUND) {
String newUrl = https.header("Location");
- gitVersion = newUrl.substring(newUrl.lastIndexOf('/')+2).toFloat();
- if(gitVersion > String(CGSCALE_VERSION).toFloat()){
+ gitVersion = newUrl.substring(newUrl.lastIndexOf('/') + 2).toFloat();
+ if (gitVersion > String(CGSCALE_VERSION).toFloat()) {
printConsole(T_UPDATE, "Firmware update available: V" + String(gitVersion));
- }else{
+ } else {
printConsole(T_UPDATE, "Firmware version found on GitHub: V" + String(gitVersion) + " - current firmware is up to date");
}
- }else if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
+ } else if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
Serial.println(https.getString());
- }else{
+ } else {
printConsole(T_ERROR, "HTTPS: GET... failed, " + https.errorToString(httpCode));
https.end();
return false;
}
- }else {
+ } else {
return false;
}
- https.end();
- }else {
+ https.end();
+ } else {
printConsole(T_ERROR, "Wifi: Unable to connect");
return false;
}
-
+
return true;
}
diff --git a/README.md b/README.md
index 32693bb..9ad3449 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Schwerpunktwaage auf Arduinobasis zum auswiegen von Flugmodellen. Es werden rela
Die wichtigsten Funktionen:
- unterstützt Waagen mit 2 oder 3 Wiegezellen
-- unterstützt ESP8266 und Arduino mit ATmega328, ATmega32u4
+- unterstützt ESP8266 (auch Wifi Kit 8) und Arduino mit ATmega328, ATmega32u4
- automatische Kalibrierung anhand eines Referenzobjekts, dadurch kein mühsames eruieren der Kalibrierwerte
- Anzeige durch OLED Display
- Batteriespannnung kann gemessen werden
diff --git a/data/index.html b/data/index.html
new file mode 100755
index 0000000..19c1bbe
--- /dev/null
+++ b/data/index.html
@@ -0,0 +1,880 @@
+
+
+
+
+
+
+
+ CG scale by M. Lehmann
+
+
+
+
+
+
+
+
+ -
+
+
+
+

+
+

+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
![]()
+
+
+
+
+
+ X1:
+
+
+
+ X2:
+
+
+
+ X3:
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+

+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ min:
+
+
+
+ max:
+
+
+
+
+
+
+
+
+
+
+ (c) 2019 M. Lehmann - Version: --
+
+
+
diff --git a/data/index.html.gz b/data/index.html.gz
deleted file mode 100755
index 3a62661..0000000
Binary files a/data/index.html.gz and /dev/null differ
diff --git a/data/models.html b/data/models.html
new file mode 100755
index 0000000..b7fd767
--- /dev/null
+++ b/data/models.html
@@ -0,0 +1,531 @@
+
+
+
+
+
+
+
+ CG scale by M. Lehmann
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+

+
+

+
+

+
+
+
+
+
+
+
+
+
+
+ (c) 2019 M. Lehmann - Version: --
+
+
+
diff --git a/data/models.html.gz b/data/models.html.gz
deleted file mode 100755
index dec398d..0000000
Binary files a/data/models.html.gz and /dev/null differ
diff --git a/data/settings.html b/data/settings.html
new file mode 100755
index 0000000..ed54e8e
--- /dev/null
+++ b/data/settings.html
@@ -0,0 +1,1062 @@
+
+
+
+
+
+
+
+ CG scale by M. Lehmann
+
+
+
+
+
+
+
+
+ -
+
+
+
+

+
+

+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+ -
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+ (c) 2019 M. Lehmann - Version: --
+
+
+
diff --git a/data/settings.html.gz b/data/settings.html.gz
deleted file mode 100755
index 12a8a32..0000000
Binary files a/data/settings.html.gz and /dev/null differ
diff --git a/settings_ESP8266.h b/settings_ESP8266.h
index e43080c..f33fe79 100644
--- a/settings_ESP8266.h
+++ b/settings_ESP8266.h
@@ -45,15 +45,35 @@ CG scale with 3 Loadcells:
*/
-#define PIN_LOADCELL1_DOUT D6
-#define PIN_LOADCELL1_PD_SCK D5
-#define PIN_LOADCELL2_DOUT D2
-#define PIN_LOADCELL2_PD_SCK D1
+// Wifi Kit 8 (https://heltec.org/project/wifi-kit-8/)
+// is a ESP8266 based board, with integrated OLED and battery management
+#define WIFI_KIT_8 1
+#ifdef WIFI_KIT_8
+ #define PIN_LOADCELL1_DOUT D6
+ #define PIN_LOADCELL1_PD_SCK D7
-#define PIN_LOADCELL3_DOUT D7
-#define PIN_LOADCELL3_PD_SCK D0
+ #define PIN_LOADCELL2_DOUT D3
+
+ #define PIN_LOADCELL2_PD_SCK D8
+
+ #define PIN_LOADCELL3_DOUT D0
+ #define PIN_LOADCELL3_PD_SCK D0
+ // D3 can be used in parallel to the load cell with Wifi Kit 8
+ #define PIN_TARE_BUTTON D3
+
+ #define MAX_SSID_PW_LENGHT 64
+#else
+ #define PIN_LOADCELL1_DOUT D6
+ #define PIN_LOADCELL1_PD_SCK D5
+
+ #define PIN_LOADCELL2_DOUT D2
+ #define PIN_LOADCELL2_PD_SCK D1
+
+ #define PIN_LOADCELL3_DOUT D7
+ #define PIN_LOADCELL3_PD_SCK D0
+#endif
// **** Measurement settings ****
@@ -81,9 +101,13 @@ CG scale with 3 Loadcells:
// Please UNCOMMENT the display used
-U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
-//U8G2_SSD1306_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
-
+#ifdef WIFI_KIT_8
+ // Wifi Kit 8 has a fixed wired 128x32 display
+ U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4);
+#else
+ U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
+ //U8G2_SSD1306_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
+#endif
// **** Voltage measurement settings ****
@@ -129,7 +153,9 @@ U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NON
// **** Wifi settings ****
+#ifndef MAX_SSID_PW_LENGHT
#define MAX_SSID_PW_LENGHT 32
+#endif
// Station mode: connect to available network
#define SSID_STA "myWiFi"