diff --git a/CG_scale.ino b/CG_scale.ino
index cc6d543..1758afa 100644
--- a/CG_scale.ino
+++ b/CG_scale.ino
@@ -4,11 +4,12 @@
(c) 2019 by M. Lehmann
------------------------------------------------------------------
*/
-#define CGSCALE_VERSION "1.0"
+#define CGSCALE_VERSION "1.0.51"
/*
******************************************************************
history:
+ V1.1 beta ESP8266
V1.0 12.01.19 first release
@@ -51,6 +52,14 @@
#include
#include
+// libraries for ESP8266 (NodeMCU 1.0 )
+#ifdef ARDUINO_ESP8266_NODEMCU
+#include
+#include
+#include
+#include
+#endif
+
// Settings in separate file
#include "settings.h"
@@ -59,6 +68,12 @@ HX711_ADC LoadCell_1(PIN_LOADCELL1_DOUT, PIN_LOADCELL1_PD_SCK);
HX711_ADC LoadCell_2(PIN_LOADCELL2_DOUT, PIN_LOADCELL2_PD_SCK);
HX711_ADC LoadCell_3(PIN_LOADCELL3_DOUT, PIN_LOADCELL3_PD_SCK);
+// webserver constructor
+#ifdef ARDUINO_ESP8266_NODEMCU
+ESP8266WebServer server(80);
+IPAddress apIP(ip[0], ip[1], ip[2], ip[3]);
+#endif
+
// serial menu
enum
{
@@ -73,12 +88,15 @@ enum
MENU_LOADCELL1_CALIBRATION_FACTOR,
MENU_LOADCELL2_CALIBRATION_FACTOR,
MENU_LOADCELL3_CALIBRATION_FACTOR,
+ MENU_RESISTOR_R1,
+ MENU_RESISTOR_R2,
MENU_BATTERY_MEASUREMENT,
MENU_SHOW_ACTUAL,
MENU_RESET_DEFAULT
};
// EEprom parameter addresses
+#define EEPROM_SIZE 120
enum
{
P_NUMBER_LOADCELLS = 1,
@@ -90,7 +108,9 @@ enum
P_LOADCELL3_CALIBRATION_FACTOR = P_LOADCELL2_CALIBRATION_FACTOR + sizeof(float),
P_ENABLE_BATVOLT = P_LOADCELL3_CALIBRATION_FACTOR + sizeof(float),
P_REF_WEIGHT = P_ENABLE_BATVOLT + sizeof(float),
- P_REF_CG = P_REF_WEIGHT + sizeof(float)
+ P_REF_CG = P_REF_WEIGHT + sizeof(float),
+ P_RESISTOR_R1 = P_REF_CG + sizeof(float),
+ P_RESISTOR_R2 = P_RESISTOR_R1 + sizeof(float)
};
// battery image 12x6
@@ -126,7 +146,7 @@ static const unsigned char CGtransImage[] U8X8_PROGMEM = {
};
// set default text
-static const String PROGMEM newValueText = "Set new value:";
+static const String newValueText = "Set new value:";
// load default values
uint8_t nLoadcells = NUMBER_LOADCELLS;
@@ -136,6 +156,8 @@ float distanceX3 = DISTANCE_X3;
float calFactorLoadcell1 = LOADCELL1_CALIBRATION_FACTOR;
float calFactorLoadcell2 = LOADCELL2_CALIBRATION_FACTOR;
float calFactorLoadcell3 = LOADCELL3_CALIBRATION_FACTOR;
+float resistorR1 = RESISTOR_R1;
+float resistorR2 = RESISTOR_R2;
bool enableBatVolt = ENABLE_VOLTAGE;
float refWeight = REF_WEIGHT;
float refCG = REF_CG;
@@ -147,9 +169,12 @@ float weightLoadCell3 = 0;
float lastWeightLoadCell1 = 0;
float lastWeightLoadCell2 = 0;
float lastWeightLoadCell3 = 0;
+float weightTotal = 0;
+float CG_length = 0;
+float CG_trans = 0;
+float batVolt = 0;
unsigned long lastTimeMenu = 0;
unsigned long lastTimeLoadcell = 0;
-bool displayInit = false;
bool updateMenu = true;
int menuPage = 0;
@@ -158,27 +183,160 @@ int menuPage = 0;
void(* resetCPU) (void) = 0;
-// save calibration factors
+// save values to eeprom
+void saveLoadcells() {
+ EEPROM.put(P_NUMBER_LOADCELLS, nLoadcells);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
+void saveDistanceX1() {
+ EEPROM.put(P_DISTANCE_X1, distanceX1);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
+void saveDistanceX2() {
+ EEPROM.put(P_DISTANCE_X2, distanceX2);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
+void saveDistanceX3() {
+ EEPROM.put(P_DISTANCE_X3, distanceX3);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
+void saveRefWeight() {
+ EEPROM.put(P_REF_WEIGHT, refWeight);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
+void saveRefCG() {
+ EEPROM.put(P_REF_CG, refCG);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
void saveCalFactor1() {
LoadCell_1.setCalFactor(calFactorLoadcell1);
EEPROM.put(P_LOADCELL1_CALIBRATION_FACTOR, calFactorLoadcell1);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
}
void saveCalFactor2() {
LoadCell_2.setCalFactor(calFactorLoadcell2);
EEPROM.put(P_LOADCELL2_CALIBRATION_FACTOR, calFactorLoadcell2);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
}
void saveCalFactor3() {
LoadCell_3.setCalFactor(calFactorLoadcell3);
EEPROM.put(P_LOADCELL3_CALIBRATION_FACTOR, calFactorLoadcell3);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
+void saveResistorR1() {
+ EEPROM.put(P_RESISTOR_R1, resistorR1);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+
+void saveResistorR2() {
+ EEPROM.put(P_RESISTOR_R2, resistorR2);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+void saveEnableBatVolt() {
+ EEPROM.put(P_ENABLE_BATVOLT, enableBatVolt);
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
+}
+
+void auto_calibrate() {
+ Serial.print(F("Autocalibration is running"));
+ for (int i = 0; i <= 20; i++) {
+ Serial.print(F("."));
+ delay(100);
+ }
+ // calculate weight
+ float toWeightLoadCell2 = ((refCG - distanceX1) * refWeight) / distanceX2;
+ float toWeightLoadCell1 = refWeight - toWeightLoadCell2;
+ float toWeightLoadCell3 = 0;
+ if (nLoadcells > 2) {
+ toWeightLoadCell1 = toWeightLoadCell1 / 2;
+ toWeightLoadCell3 = toWeightLoadCell1;
+ }
+ // calculate calibration factors
+ calFactorLoadcell1 = calFactorLoadcell1 / (toWeightLoadCell1 / weightLoadCell1);
+ calFactorLoadcell2 = calFactorLoadcell2 / (toWeightLoadCell2 / weightLoadCell2);
+ if (nLoadcells > 2) {
+ calFactorLoadcell3 = calFactorLoadcell3 / (toWeightLoadCell3 / weightLoadCell3);
+ }
+ saveCalFactor1();
+ saveCalFactor2();
+ saveCalFactor3();
+ // finish
+ Serial.println(F("done"));
}
void setup() {
+#ifdef ARDUINO_ESP8266_NODEMCU
+ // init webserver
+ WiFi.mode(WIFI_AP);
+ WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
+ WiFi.softAP(ssid, password);
+
+ server.begin();
+ server.on("/", main_page);
+ server.on("/index.html", main_page);
+ server.on("/settings", settings_page);
+ server.on("/settings.png", settingsImg);
+ server.on("/weight.png", weightImg);
+ server.on("/cg.png", cgImg);
+ server.on("/cglr.png", cgLRimg);
+ server.on("/battery.png", batteryImg);
+ server.on("/CG_scale_mechanics.png", mechanicsImg);
+ server.on("/bootstrap.min.css", bootstrap);
+ server.on("bootstrap.min.css", bootstrap);
+ server.on("/popper.min.js", popper);
+ server.on("/bootstrap.min.js", bootstrapmin);
+ server.on("bootstrap.min.js", bootstrapmin);
+
+ SPIFFS.begin();
+ EEPROM.begin(EEPROM_SIZE);
+#endif
+
// init OLED display
oledDisplay.begin();
oledDisplay.firstPage();
@@ -237,25 +395,44 @@ void setup() {
EEPROM.get(P_REF_CG, refCG);
}
+ if (EEPROM.read(P_RESISTOR_R1) != 0xFF) {
+ EEPROM.get(P_RESISTOR_R1, resistorR1);
+ }
+
+ if (EEPROM.read(P_RESISTOR_R2) != 0xFF) {
+ EEPROM.get(P_RESISTOR_R2, resistorR2);
+ }
+
// init Loadcells
LoadCell_1.begin();
LoadCell_2.begin();
- LoadCell_3.begin();
+ if (nLoadcells > 2) {
+ LoadCell_3.begin();
+ }
// tare
- while (!LoadCell_1.startMultiple(STABILISINGTIME) && !LoadCell_2.startMultiple(STABILISINGTIME) && !LoadCell_3.startMultiple(STABILISINGTIME)) {
+ if (nLoadcells > 2) {
+ while (!LoadCell_1.startMultiple(STABILISINGTIME) && !LoadCell_2.startMultiple(STABILISINGTIME) && !LoadCell_3.startMultiple(STABILISINGTIME)) {
+ }
+ } else {
+ while (!LoadCell_1.startMultiple(STABILISINGTIME) && !LoadCell_2.startMultiple(STABILISINGTIME)) {
+ }
}
// set calibration factor
LoadCell_1.setCalFactor(calFactorLoadcell1);
LoadCell_2.setCalFactor(calFactorLoadcell2);
- LoadCell_3.setCalFactor(calFactorLoadcell3);
+ if (nLoadcells > 2) {
+ LoadCell_3.setCalFactor(calFactorLoadcell3);
+ }
// stabilize scale values
for (int i = 0; i <= 5; i++) {
LoadCell_1.update();
LoadCell_2.update();
- LoadCell_3.update();
+ if (nLoadcells > 2) {
+ LoadCell_3.update();
+ }
delay(200);
}
@@ -269,7 +446,9 @@ void loop() {
LoadCell_1.update();
LoadCell_2.update();
- LoadCell_3.update();
+ if (nLoadcells > 2) {
+ LoadCell_3.update();
+ }
// update loadcell values
@@ -299,11 +478,6 @@ void loop() {
if ((millis() - lastTimeMenu) > UPDATE_INTERVAL_OLED_MENU) {
lastTimeMenu = millis();
- float weightTotal;
- float CG_length = 0;
- float CG_trans = 0;
- float batVolt = 0;
-
// total model weight
weightTotal = weightLoadCell1 + weightLoadCell2 + weightLoadCell3;
if (weightTotal < MINIMAL_TOTAL_WEIGHT && weightTotal > MINIMAL_TOTAL_WEIGHT * -1) {
@@ -318,11 +492,14 @@ void loop() {
if (nLoadcells > 2) {
CG_trans = (distanceX3 / 2) - (((weightLoadCell1 + weightLoadCell2 / 2) * distanceX3) / weightTotal);
}
+ }else{
+ CG_length = 0;
+ CG_trans = 0;
}
// read battery voltage
if (enableBatVolt) {
- batVolt = (analogRead(VOLTAGE_PIN) / 1024.0) * V_REF * (float(RESISTOR_R1 + RESISTOR_R2) / RESISTOR_R2) / 1000.0;
+ batVolt = (analogRead(VOLTAGE_PIN) / 1024.0) * V_REF * ((resistorR1 + resistorR2) / resistorR2) / 1000.0;
}
// print to display
@@ -389,66 +566,43 @@ void loop() {
break;
case MENU_LOADCELLS:
nLoadcells = Serial.parseInt();
- EEPROM.put(P_NUMBER_LOADCELLS, nLoadcells);
+ saveLoadcells();
menuPage = 0;
updateMenu = true;
break;
case MENU_DISTANCE_X1:
distanceX1 = Serial.parseFloat();
- EEPROM.put(P_DISTANCE_X1, distanceX1);
+ saveDistanceX1();
menuPage = 0;
updateMenu = true;
break;
case MENU_DISTANCE_X2:
distanceX2 = Serial.parseFloat();
- EEPROM.put(P_DISTANCE_X2, distanceX2);
+ saveDistanceX2();
menuPage = 0;
updateMenu = true;
break;
case MENU_DISTANCE_X3:
distanceX3 = Serial.parseFloat();
- EEPROM.put(P_DISTANCE_X3, distanceX3);
+ saveDistanceX3();
menuPage = 0;
updateMenu = true;
break;
case MENU_REF_WEIGHT:
refWeight = Serial.parseFloat();
- EEPROM.put(P_REF_WEIGHT, refWeight);
+ saveRefWeight();
menuPage = 0;
updateMenu = true;
break;
case MENU_REF_CG:
refCG = Serial.parseFloat();
- EEPROM.put(P_REF_CG, refCG);
+ saveRefCG();
menuPage = 0;
updateMenu = true;
break;
case MENU_AUTO_CALIBRATE:
if (Serial.read() == 'J') {
- Serial.print(F("Autocalibration is running"));
- for (int i = 0; i <= 20; i++) {
- Serial.print(F("."));
- delay(100);
- }
- // calculate weight
- float toWeightLoadCell2 = ((refCG - distanceX1) * refWeight) / distanceX2;
- float toWeightLoadCell1 = refWeight - toWeightLoadCell2;
- float toWeightLoadCell3 = 0;
- if (nLoadcells > 2) {
- toWeightLoadCell1 = toWeightLoadCell1 / 2;
- toWeightLoadCell3 = toWeightLoadCell1;
- }
- // calculate calibration factors
- calFactorLoadcell1 = calFactorLoadcell1 / (toWeightLoadCell1 / weightLoadCell1);
- calFactorLoadcell2 = calFactorLoadcell2 / (toWeightLoadCell2 / weightLoadCell2);
- if (nLoadcells > 2) {
- calFactorLoadcell3 = calFactorLoadcell3 / (toWeightLoadCell3 / weightLoadCell3);
- }
- saveCalFactor1();
- saveCalFactor2();
- saveCalFactor3();
- // finish
- Serial.println(F("done"));
+ auto_calibrate();
menuPage = 0;
updateMenu = true;
}
@@ -471,13 +625,25 @@ void loop() {
menuPage = 0;
updateMenu = true;
break;
+ case MENU_RESISTOR_R1:
+ resistorR1 = Serial.parseFloat();
+ saveResistorR1();
+ menuPage = 0;
+ updateMenu = true;
+ break;
+ case MENU_RESISTOR_R2:
+ resistorR2 = Serial.parseFloat();
+ saveResistorR2();
+ menuPage = 0;
+ updateMenu = true;
+ break;
case MENU_BATTERY_MEASUREMENT:
if (Serial.read() == 'J') {
enableBatVolt = true;
} else {
enableBatVolt = false;
}
- EEPROM.put(P_ENABLE_BATVOLT, enableBatVolt);
+ saveEnableBatVolt();
menuPage = 0;
updateMenu = true;
break;
@@ -490,10 +656,13 @@ void loop() {
//chr = Serial.read();
if (Serial.read() == 'J') {
// reset eeprom
- for (int i = 0; i < 100; i++) {
+ for (int i = 0; i < EEPROM_SIZE; i++) {
EEPROM.write(i, 0xFF);
}
Serial.end();
+#ifdef ARDUINO_ESP8266_NODEMCU
+ EEPROM.commit();
+#endif
resetCPU();
}
menuPage = 0;
@@ -530,13 +699,17 @@ void loop() {
Serial.print(calFactorLoadcell2);
Serial.print(F(")\n10 - Set calibration factor of load cell 3 ("));
Serial.print(calFactorLoadcell3);
- Serial.print(F(")\n11 - Enable battery voltage measurement ("));
+ Serial.print(F(")\n11 - Set value of resistor R1 ("));
+ Serial.print(resistorR1);
+ Serial.print(F("ohm)\n12 - Set value of resistor R2 ("));
+ Serial.print(resistorR2);
+ Serial.print(F("ohm)\n13 - Enable battery voltage measurement ("));
if (enableBatVolt) {
Serial.print(F("enabled)\n"));
} else {
Serial.print(F("disabled)\n"));
}
- Serial.print(F("12 - Show actual values\n13 - Reset to factory defaults\n\n"));
+ Serial.print(F("14 - Show actual values\n15 - Reset to factory defaults\n\n"));
Serial.print(F("Please choose the menu number:"));
updateMenu = false;
break;
@@ -603,6 +776,18 @@ void loop() {
Serial.print(newValueText);
updateMenu = false;
break;
+ case MENU_RESISTOR_R1:
+ Serial.print(F("\n\nValue of resistor R1: "));
+ Serial.println(resistorR1);
+ Serial.print(newValueText);
+ updateMenu = false;
+ break;
+ case MENU_RESISTOR_R2:
+ Serial.print(F("\n\nValue of resistor R2: "));
+ Serial.println(resistorR2);
+ Serial.print(newValueText);
+ updateMenu = false;
+ break;
case MENU_BATTERY_MEASUREMENT:
Serial.print(F("\n\nEnable battery voltage measurement (J/N)?\n"));
updateMenu = false;
@@ -642,4 +827,369 @@ void loop() {
updateMenu = true;
}
}
+
+#ifdef ARDUINO_ESP8266_NODEMCU
+ server.handleClient();
+#endif
+
}
+
+
+#ifdef ARDUINO_ESP8266_NODEMCU
+void main_page()
+{
+ char buff[8];
+ String webPage = "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "CG scale by M. Lehmann";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "
";
+ webPage += "";
+ webPage += "";
+
+ // print weight
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ dtostrf(weightTotal, 5, 1, buff);
+ webPage += buff;
+ webPage += "g
";
+ webPage += "
";
+ webPage += "
";
+
+ // print cg
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ dtostrf(CG_length, 5, 1, buff);
+ webPage += buff;
+ webPage += "mm
";
+ webPage += "
";
+ webPage += "
";
+
+ // print cg trans
+ if (nLoadcells > 2) {
+ //webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ dtostrf(CG_trans, 5, 1, buff);
+ webPage += buff;
+ webPage += "mm
";
+ webPage += "
";
+ webPage += "
";
+
+ }
+
+ // print battery
+ if (enableBatVolt) {
+ //webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ webPage += "
";
+ webPage += batVolt;
+ webPage += "V
";
+ webPage += "
";
+ webPage += "
";
+ }
+ webPage += "
";
+ webPage += "";
+ webPage += "(c) 2019 M. Lehmann - Version: ";
+ webPage += CGSCALE_VERSION;
+ webPage += "
";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+
+ server.send(200, "text/html", webPage);
+
+}
+
+void settings_page()
+{
+ if ( server.hasArg("nLoadcells")) {
+ nLoadcells = server.arg("nLoadcells").toFloat();
+ saveLoadcells();
+ }
+ if ( server.hasArg("distanceX1")) {
+ distanceX1 = server.arg("distanceX1").toFloat();
+ saveDistanceX1();
+ }
+ if ( server.hasArg("distanceX2")) {
+ distanceX2 = server.arg("distanceX2").toFloat();
+ saveDistanceX2();
+ }
+ if ( server.hasArg("distanceX3")) {
+ distanceX3 = server.arg("distanceX3").toFloat();
+ saveDistanceX3();
+ }
+ if ( server.hasArg("refWeight")) {
+ refWeight = server.arg("refWeight").toFloat();
+ saveRefWeight();
+ }
+ if ( server.hasArg("refCG")) {
+ refCG = server.arg("refCG").toFloat();
+ saveRefCG();
+ }
+ if ( server.hasArg("calFactorLoadcell1")) {
+ calFactorLoadcell1 = server.arg("calFactorLoadcell1").toFloat();
+ saveCalFactor1();
+ }
+ if ( server.hasArg("calFactorLoadcell2")) {
+ calFactorLoadcell2 = server.arg("calFactorLoadcell2").toFloat();
+ saveCalFactor2();
+ }
+ if ( server.hasArg("calFactorLoadcell3")) {
+ calFactorLoadcell3 = server.arg("calFactorLoadcell3").toFloat();
+ saveCalFactor3();
+ }
+ if ( server.hasArg("resistorR1")) {
+ resistorR1 = server.arg("resistorR1").toFloat();
+ saveResistorR1();
+ }
+ if ( server.hasArg("resistorR2")) {
+ resistorR2 = server.arg("resistorR2").toFloat();
+ saveResistorR2();
+ }
+ if ( server.hasArg("enableBatVolt")) {
+ if (server.arg("enableBatVolt") == "ON") {
+ enableBatVolt = true;
+ } else {
+ enableBatVolt = false;
+ }
+ }
+ if ( server.hasArg("calibrate")) {
+ auto_calibrate();
+ }
+
+
+ String webPage = "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "CG scale by M. Lehmann";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "
";
+ webPage += "";
+
+ webPage += "";
+
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "
";
+
+ webPage += "
";
+
+ webPage += "";
+ webPage += "(c) 2019 M. Lehmann - Version: ";
+ webPage += CGSCALE_VERSION;
+ webPage += "";
+ webPage += "";
+ webPage += "";
+ webPage += "";
+
+ server.send(200, "text/html", webPage);
+}
+
+void settingsImg()
+{
+ File file = SPIFFS.open("/settings.png", "r");
+ size_t sent = server.streamFile(file, "text/css");
+}
+
+void weightImg()
+{
+ File file = SPIFFS.open("/weight.png", "r");
+ size_t sent = server.streamFile(file, "text/css");
+}
+
+void cgImg()
+{
+ File file = SPIFFS.open("/cg.png", "r");
+ size_t sent = server.streamFile(file, "text/css");
+}
+
+void cgLRimg()
+{
+ File file = SPIFFS.open("/cglr.png", "r");
+ size_t sent = server.streamFile(file, "text/css");
+}
+
+void batteryImg()
+{
+ File file = SPIFFS.open("/battery.png", "r");
+ size_t sent = server.streamFile(file, "text/css");
+}
+
+void mechanicsImg()
+{
+ File file = SPIFFS.open("/CG_scale_mechanics.png", "r");
+ size_t sent = server.streamFile(file, "text/css");
+}
+
+void bootstrap()
+{
+ File file = SPIFFS.open("/bootstrap.min.css.gz", "r");
+ size_t sent = server.streamFile(file, "text/css");
+}
+
+void popper()
+{
+ File file = SPIFFS.open("/popper.min.js.gz", "r");
+ size_t sent = server.streamFile(file, "application/javascript");
+}
+
+void bootstrapmin()
+{
+ File file = SPIFFS.open("/bootstrap.min.js.gz", "r");
+ size_t sent = server.streamFile(file, "application/javascript");
+}
+#endif
diff --git a/data/CG_scale_mechanics.png b/data/CG_scale_mechanics.png
new file mode 100644
index 0000000..249ca62
Binary files /dev/null and b/data/CG_scale_mechanics.png differ
diff --git a/data/battery.png b/data/battery.png
new file mode 100644
index 0000000..c3fd449
Binary files /dev/null and b/data/battery.png differ
diff --git a/data/bootstrap.css.map.gz b/data/bootstrap.css.map.gz
new file mode 100755
index 0000000..1ffe194
Binary files /dev/null and b/data/bootstrap.css.map.gz differ
diff --git a/data/bootstrap.min.css.gz b/data/bootstrap.min.css.gz
new file mode 100755
index 0000000..5c56faf
Binary files /dev/null and b/data/bootstrap.min.css.gz differ
diff --git a/data/bootstrap.min.js.gz b/data/bootstrap.min.js.gz
new file mode 100755
index 0000000..368d3d1
Binary files /dev/null and b/data/bootstrap.min.js.gz differ
diff --git a/data/bootstrap.min.js.map.gz b/data/bootstrap.min.js.map.gz
new file mode 100755
index 0000000..7ec8159
Binary files /dev/null and b/data/bootstrap.min.js.map.gz differ
diff --git a/data/cg.png b/data/cg.png
new file mode 100644
index 0000000..d0866d2
Binary files /dev/null and b/data/cg.png differ
diff --git a/data/cglr.png b/data/cglr.png
new file mode 100644
index 0000000..2601837
Binary files /dev/null and b/data/cglr.png differ
diff --git a/data/settings.png b/data/settings.png
new file mode 100644
index 0000000..0a23d1d
Binary files /dev/null and b/data/settings.png differ
diff --git a/data/weight.png b/data/weight.png
new file mode 100644
index 0000000..19309bb
Binary files /dev/null and b/data/weight.png differ
diff --git a/settings.h b/settings.h
index 5222660..e107dc3 100644
--- a/settings.h
+++ b/settings.h
@@ -44,6 +44,8 @@ CG scale with 3 Loadcells:
|---X1---|---------X2----------|
*/
+
+#ifdef __AVR__ // if CPU is ATmega32u4 or Atmega328, use this pins
#define PIN_LOADCELL1_DOUT A2
#define PIN_LOADCELL1_PD_SCK A3
@@ -52,6 +54,18 @@ CG scale with 3 Loadcells:
#define PIN_LOADCELL3_DOUT A9
#define PIN_LOADCELL3_PD_SCK A10
+#endif
+
+#ifdef ARDUINO_ESP8266_NODEMCU // if CPU is ESP8266, use this pins
+#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 D8
+#define PIN_LOADCELL3_PD_SCK D7
+#endif
@@ -82,9 +96,15 @@ CG scale with 3 Loadcells:
// Please UNCOMMENT the display used
+#ifdef __AVR__ // if CPU is ATmega32u4 or Atmega328, use this display
U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
+#endif
+#ifdef ARDUINO_ESP8266_NODEMCU // if CPU is ESP8266, use this display
+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 ****
@@ -93,14 +113,20 @@ U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NON
#define ENABLE_VOLTAGE true
// analog input pin
+#ifdef __AVR__ // if CPU is ATmega32u4 or Atmega328, use this pin
#define VOLTAGE_PIN A7
+#endif
+
+#ifdef ARDUINO_ESP8266_NODEMCU // if CPU is ESP8266, use this pin
+#define VOLTAGE_PIN A0
+#endif
// supply voltage
#define V_REF 5000 // set supply voltage from 1800 to 5500mV
// voltage divider
-#define RESISTOR_R1 10000 // Ohms
-#define RESISTOR_R2 10000 // Ohms
+#define RESISTOR_R1 10000 // ohm
+#define RESISTOR_R2 10000 // ohm
/*
voltage input
@@ -119,3 +145,15 @@ U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NON
|
GND
*/
+
+
+
+// **** Web server settings ****
+
+// Wifi works as an access point
+const char* ssid = "CG scale"; // wifi name
+const char* password = ""; // wifi password
+
+const char ip[4] = {1,1,1,1}; // default IP address
+
+#define REFRESH_TIME 3 // [s], reload the main page