diff --git a/README.md b/README.md index 3107134..dab26aa 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ ____________________________________________________ ____________________________________________________ ## Timeline (Versions): +- 2023.05.27 Battery Monitor for internal and External Voltages (to make board sleep and avoid low discharge of batterys) T-Beam boards now with Battery readings as well. - 2024.05.23 Forced Reboot Mode added. - 2024.05.22 Experimental backup-Digirepeater-Mode when "only" iGate mode loses WiFi connection added. - 2024.05.20 WebConfig update to control whether Messages and Objects should be Tx to RF. diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 8571834..547586b 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -37,7 +37,7 @@ ________________________________________________________________________________ #include "A7670_utils.h" #endif -String versionDate = "2024.05.24"; +String versionDate = "2024.05.27"; Configuration Config; WiFiClient espClient; diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index aaa48ea..b33f12e 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -1,6 +1,7 @@ #include "battery_utils.h" #include "configuration.h" #include "boards_pinout.h" +#include "power_utils.h" #include "utils.h" extern Configuration Config; @@ -25,42 +26,50 @@ namespace BATTERY_Utils { } float checkInternalVoltage() { - int sample; - int sampleSum = 0; - #ifdef ADC_CTRL - #if defined(HELTEC_WSL_V3) || defined(HELTEC_WIRELESS_TRACKER) - digitalWrite(ADC_CTRL, HIGH); - #endif - #if defined(HELTEC_V3) || defined(HELTEC_V2) - digitalWrite(ADC_CTRL, LOW); - #endif - #endif - - for (int i = 0; i < 100; i++) { - #ifdef BATTERY_PIN - sample = analogRead(BATTERY_PIN); - #endif - #if defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) - sample = 0; - #endif - sampleSum += sample; - delayMicroseconds(50); - } - - #ifdef ADC_CTRL - #if defined(HELTEC_WSL_V3) || defined(HELTEC_WIRELESS_TRACKER) - digitalWrite(ADC_CTRL, LOW); - #endif - #if defined(HELTEC_V3) || defined(HELTEC_V2) - digitalWrite(ADC_CTRL, HIGH); - #endif - double inputDivider = (1.0 / (390.0 + 100.0)) * 100.0; // The voltage divider is a 390k + 100k resistor in series, 100k on the low side. - return (((sampleSum/100) * adcReadingTransformation) / inputDivider) + 0.285; // Yes, this offset is excessive, but the ADC on the ESP32s3 is quite inaccurate and noisy. Adjust to own measurements. + #if defined(HAS_AXP192) || defined(HAS_AXP2101) + if(POWER_Utils::isBatteryConnected()) { + return POWER_Utils::getBatteryVoltage(); + } else { + return 0.0; + } #else - return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; // raw voltage without mapping - #endif + int sample; + int sampleSum = 0; + #ifdef ADC_CTRL + #if defined(HELTEC_WSL_V3) || defined(HELTEC_WIRELESS_TRACKER) + digitalWrite(ADC_CTRL, HIGH); + #endif + #if defined(HELTEC_V3) || defined(HELTEC_V2) + digitalWrite(ADC_CTRL, LOW); + #endif + #endif - // return mapVoltage(voltage, 3.34, 4.71, 3.0, 4.2); // mapped voltage + for (int i = 0; i < 100; i++) { + #ifdef BATTERY_PIN + sample = analogRead(BATTERY_PIN); + #endif + #if defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) + sample = 0; + #endif + sampleSum += sample; + delayMicroseconds(50); + } + + #ifdef ADC_CTRL + #if defined(HELTEC_WSL_V3) || defined(HELTEC_WIRELESS_TRACKER) + digitalWrite(ADC_CTRL, LOW); + #endif + #if defined(HELTEC_V3) || defined(HELTEC_V2) + digitalWrite(ADC_CTRL, HIGH); + #endif + double inputDivider = (1.0 / (390.0 + 100.0)) * 100.0; // The voltage divider is a 390k + 100k resistor in series, 100k on the low side. + return (((sampleSum/100) * adcReadingTransformation) / inputDivider) + 0.285; // Yes, this offset is excessive, but the ADC on the ESP32s3 is quite inaccurate and noisy. Adjust to own measurements. + #else + return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; // raw voltage without mapping + #endif + + // return mapVoltage(voltage, 3.34, 4.71, 3.0, 4.2); // mapped voltage + #endif } float checkExternalVoltage() { diff --git a/src/power_utils.cpp b/src/power_utils.cpp index 2037238..1056f98 100644 --- a/src/power_utils.cpp +++ b/src/power_utils.cpp @@ -21,6 +21,22 @@ extern Configuration Config; namespace POWER_Utils { + double getBatteryVoltage() { + #if defined(HAS_AXP192) || defined(HAS_AXP2101) + return (PMU.getBattVoltage() / 1000.0); + #else + return 0.0; + #endif + } + + bool isBatteryConnected() { + #if defined(HAS_AXP192) || defined(HAS_AXP2101) + return PMU.isBatteryConnect(); + #else + return false; + #endif + } + void activateMeasurement() { #if defined(HAS_AXP192) || defined(HAS_AXP2101) PMU.disableTSPinMeasure(); diff --git a/src/power_utils.h b/src/power_utils.h index c887834..78e42fb 100644 --- a/src/power_utils.h +++ b/src/power_utils.h @@ -11,6 +11,8 @@ namespace POWER_Utils { + double getBatteryVoltage(); + bool isBatteryConnected(); void activateMeasurement(); void activateLoRa(); void deactivateLoRa(); diff --git a/src/utils.cpp b/src/utils.cpp index f5822fd..1dff34e 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -122,7 +122,7 @@ namespace Utils { beaconPacket += Config.beacon.comment; secondaryBeaconPacket += Config.beacon.comment; - #ifdef BATTERY_PIN + #if defined(BATTERY_PIN) || defined(HAS_AXP192) || defined(HAS_AXP2101) if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) { float internalVoltage = BATTERY_Utils::checkInternalVoltage(); String internalVoltageInfo = String(internalVoltage,2) + "V";