Skip to content

Commit

Permalink
HELTEC V3 battery input fix
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Apr 19, 2024
1 parent b00b29a commit ce058ed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions src/battery_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 9 additions & 3 deletions src/pins_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,20 @@
#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
Expand Down
7 changes: 7 additions & 0 deletions src/power_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

0 comments on commit ce058ed

Please sign in to comment.