diff --git a/include/mess_Ub.h b/include/mess_Ub.h index b46a741..0f803ef 100644 --- a/include/mess_Ub.h +++ b/include/mess_Ub.h @@ -1,24 +1,22 @@ -#include - -const float MinimalSpannung = 2.85; -float korectur = 1.02910; -char floatString[15] = {0}; -float AKKU; - -float getBattery(float kor = 1.000) -{ - #if (NOBATT == 1) - Serial.print("Batterie:\t\t 3.05 V\n"); - return 3.05; - #endif - float valA0 = analogRead(A0); - valA0 = valA0 * 3.7; // (R1 + r1 + r2) / r2 - // r1 und r2 Spannungsteiler - // r1 = 270k, r2 = 100k - // Spannungsbereich = 5.2 Volt - valA0= valA0 / 1024; - valA0 = valA0 * kor; - dtostrf(valA0,7,2,floatString); - Serial.printf("Batterie:\t\t %s V\n", floatString); - return valA0; +#include + +ADC_MODE(ADC_VCC); + +const float MinimalSpannung = 2.85; +float korectur = 9.2800899887514060742407199100112e-4; +char floatString[15] = {0}; +float AKKU; + +float getBattery() +{ + #if (NOBATT == 1) + Serial.print("Batterie:\t\t 3.05 V\n"); + return 3.05; + #endif + int Vcc = ESP.getVcc(); + float VCC = Vcc * korectur ; + Serial.printf("Rohdaten: %d, ", Vcc); + dtostrf(VCC,7,2,floatString); + Serial.printf("Vcc: %s V\n", floatString); + return VCC; } \ No newline at end of file diff --git a/include/mess_Ub_old.h b/include/mess_Ub_old.h new file mode 100644 index 0000000..b46a741 --- /dev/null +++ b/include/mess_Ub_old.h @@ -0,0 +1,24 @@ +#include + +const float MinimalSpannung = 2.85; +float korectur = 1.02910; +char floatString[15] = {0}; +float AKKU; + +float getBattery(float kor = 1.000) +{ + #if (NOBATT == 1) + Serial.print("Batterie:\t\t 3.05 V\n"); + return 3.05; + #endif + float valA0 = analogRead(A0); + valA0 = valA0 * 3.7; // (R1 + r1 + r2) / r2 + // r1 und r2 Spannungsteiler + // r1 = 270k, r2 = 100k + // Spannungsbereich = 5.2 Volt + valA0= valA0 / 1024; + valA0 = valA0 * kor; + dtostrf(valA0,7,2,floatString); + Serial.printf("Batterie:\t\t %s V\n", floatString); + return valA0; +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 58c282a..24d2d41 100644 --- a/platformio.ini +++ b/platformio.ini @@ -25,7 +25,7 @@ lib_deps = build_flags = -DTEMPTEST33=1 - -DNOBATT=1 + -DNOBATT=0 -DMaxErrCount=30 -DMQTT=0 diff --git a/src/main.cpp b/src/main.cpp index f4cf2b5..ce20b5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,7 +118,7 @@ void setup() { //initADS(); //init_MCP9808(); #endif - AKKU = getBattery(korectur); // ca. 170 ms + AKKU = getBattery(); // ca. 170 ms // ca. 280 ms if (F_HTU_21D == true){ read_HTU21D();