better battery code

This commit is contained in:
richonguzman 2024-05-02 13:41:21 -04:00
parent 04a7f89891
commit 611ea87264
2 changed files with 4 additions and 7 deletions

View File

@ -24,11 +24,11 @@ namespace BATTERY_Utils {
float checkBattery() {
int sample;
int sampleSum = 0;
#ifdef HELTEC_V3
#ifdef ADC_CTRL
digitalWrite(ADC_CTRL, LOW);
#endif
for (int i = 0; i < 100; i++) {
#if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(HELTEC_HTCT62) || defined(HELTEC_V3) || defined(ESP32_DIY_LoRa_A7670) || defined(TTGO_T_LORA32_V2_1_915)
#ifdef BATTERY_PIN
sample = analogRead(BATTERY_PIN);
#endif
#if defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa)
@ -38,7 +38,7 @@ namespace BATTERY_Utils {
delayMicroseconds(50);
}
#ifdef HELTEC_V3
#ifdef ADC_CTRL
digitalWrite(ADC_CTRL, HIGH);
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.

View File

@ -134,10 +134,7 @@
#define INTERNAL_LED_PIN 25 // Green Led
#define BATTERY_PIN 35
#endif
#if defined(HELTEC_WS)
#define INTERNAL_LED_PIN 35
#endif
#if defined(HELTEC_V3)
#if defined(HELTEC_V3) || defined(HELTEC_WS)
#define INTERNAL_LED_PIN 35
#define BATTERY_PIN 1
#define VEXT_CTRL 36