From ce058ed4242f61797b50c82bb7fd23e35b9a347c Mon Sep 17 00:00:00 2001 From: richonguzman Date: Fri, 19 Apr 2024 11:06:26 -0400 Subject: [PATCH] HELTEC V3 battery input fix --- src/LoRa_APRS_iGate.cpp | 4 ++-- src/battery_utils.cpp | 15 +++++++++------ src/pins_config.h | 12 +++++++++--- src/power_utils.cpp | 7 +++++++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 4d99df0..bec578b 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -60,8 +60,8 @@ String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seven void setup() { Serial.begin(115200); - #if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(HELTEC_HTCT62) - pinMode(batteryPin, INPUT); + #ifdef BATTERY_PIN + pinMode(BATTERY_PIN, INPUT); #endif #ifdef HAS_INTERNAL_LED pinMode(internalLedPin, OUTPUT); diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index 8e9160a..c4ac6a6 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -25,19 +25,22 @@ namespace BATTERY_Utils { int sample; int sampleSum = 0; for (int i = 0; i < 100; i++) { - #if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(HELTEC_HTCT62) - sample = analogRead(batteryPin); + #if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(HELTEC_HTCT62) || defined(HELTEC_V3) + sample = analogRead(BATTERY_PIN); #endif - #if defined(HELTEC_V3) || defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) + #if defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) sample = 0; #endif sampleSum += sample; delayMicroseconds(50); } - float voltage = (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; - - return voltage; // raw voltage without mapping + #ifdef HELTEC_V3 + 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 } diff --git a/src/pins_config.h b/src/pins_config.h index 3973b2d..b7cda79 100644 --- a/src/pins_config.h +++ b/src/pins_config.h @@ -104,15 +104,21 @@ #endif #ifdef HELTEC_HTCT62 -#define batteryPin 1 +#define BATTERY_PIN 1 #endif #if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) #define internalLedPin 25 // Green Led -#define batteryPin 35 +#define BATTERY_PIN 35 #endif -#if defined(HELTEC_V3) || defined(HELTEC_WS) +#if defined(HELTEC_WS) #define internalLedPin 35 #endif +#if defined(HELTEC_V3) +#define internalLedPin 35 +#define BATTERY_PIN 1 +#define VExt_CTRL 36 +#define ADC_CTRL 37 +#endif #if defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) #define internalLedPin 2 #endif diff --git a/src/power_utils.cpp b/src/power_utils.cpp index 12ec140..5fc6dc4 100644 --- a/src/power_utils.cpp +++ b/src/power_utils.cpp @@ -125,6 +125,13 @@ namespace POWER_Utils { PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_800MA); PMU.setSysPowerDownVoltage(2600); #endif + + #if defined(HELTEC_V3) + pinMode(VExt_CTRL,OUTPUT); // this is for GPS and TFT screen on Wireless_Tracker and only for Oled in Heltec V3 + digitalWrite(VExt_CTRL, HIGH); + pinMode(ADC_CTRL, OUTPUT); + digitalWrite(ADC_CTRL, HIGH); + #endif } } \ No newline at end of file