From 1c30fb44e8d68c26237b7d3f859317e74a19d0c5 Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Fri, 5 Jun 2026 17:32:29 +0100 Subject: [PATCH] HeltecV4: Use ADC_2_5db attenuation for battery reading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The resistor divider (390kΩ/100kΩ) keeps the ADC pin voltage in the 0.61-0.86V range across the full LiPoly range (3.0–4.2V). ADC_2_5db (~1250mV full-scale) uses ~70% of the ADC range at full charge, giving better resolution than the default ADC_11db (~20%) while maintaining headroom over ADC_0db (~950mV) to handle chip-to-chip ADC variation --- variants/heltec_v4/HeltecV4Board.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/heltec_v4/HeltecV4Board.cpp b/variants/heltec_v4/HeltecV4Board.cpp index a50948778..7feb95583 100644 --- a/variants/heltec_v4/HeltecV4Board.cpp +++ b/variants/heltec_v4/HeltecV4Board.cpp @@ -63,6 +63,7 @@ void HeltecV4Board::begin() { uint16_t HeltecV4Board::getBattMilliVolts() { analogReadResolution(12); + analogSetPinAttenuation(PIN_VBAT_READ, ADC_2_5db); // divider puts pin at 0.61-0.86V so this attenuation should cover it with some room to spare digitalWrite(PIN_ADC_CTRL, HIGH); delay(10); uint32_t raw_mv = 0;