Skip to content

Commit

Permalink
Implemented battery voltage measurement for Heltec WiFi LoRa 32 V3 (#16)
Browse files Browse the repository at this point in the history
Added voltage divider and ADC input control pin for ARDUINO_heltec_wifi_lora_32_V3
  • Loading branch information
matthias-bs authored May 2, 2024
1 parent f602a04 commit 3d6ee32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion BresserWeatherSensorLWCfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
// 20240410 Removed obsolete defines
// 20240413 Refactored ADC handling
// 20240423 Added define ARDUINO_heltec_wifi_lora_32_V3
// 20240427 Added BLE configuration/status via LoRaWAN
// 20240427 Added voltage divider and ADC input control pin
// for ARDUINO_heltec_wifi_lora_32_V3
// Added BLE configuration/status via LoRaWAN
// 20240430 Modified battery voltage measurement
//
// Note:
Expand Down Expand Up @@ -500,6 +502,10 @@ const uint8_t ADC3_SAMPLES = 10;
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
#if defined(ARDUINO_THINGPULSE_EPULSE_FEATHER)
const float UBATT_DIV = 0.6812;
#elif defined(ARDUINO_heltec_wifi_32_lora_V3) || defined(ARDUINO_heltec_wifi_lora_32_V3)
#define ADC_CTRL 37
// R17=100k, R14=390k => 100k / (100k + 390 k)
const float UBATT_DIV = 0.2041;
#else
const float UBATT_DIV = 0.5;
#endif
Expand Down
12 changes: 11 additions & 1 deletion src/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
// 20240414 Added ESP32-S3 PowerFeather
// Added getSupplyVoltage()
// 20240423 Added define ARDUINO_heltec_wifi_lora_32_V3
// 20240427 Added ADC input control and battery voltage measurement
// for ARDUINO_heltec_wifi_lora_32_V3
// 20240430 Modified getBatteryVoltage()
//
// ToDo:
Expand Down Expand Up @@ -81,7 +83,15 @@ uint16_t getBatteryVoltage(void)
defined(ARDUINO_THINGPULSE_EPULSE_FEATHER)
// Here come the good guys...
return getVoltage();

#elif defined(ARDUINO_heltec_wifi_32_lora_V3) || defined(ARDUINO_heltec_wifi_lora_32_V3)
// Enable ADC input switch, measure voltage and disable ADC input switch
uint16_t voltage;
pinMode(ADC_CTRL, OUTPUT);
digitalWrite(ADC_CTRL, LOW);
delay(100);
voltage = getVoltage();
pinMode(ADC_CTRL, INPUT);
return voltage;
#elif defined(ARDUINO_ARCH_RP2040)
// Not implemented - no default VBAT input circuit (connect external divider to A0)
return 0;
Expand Down

0 comments on commit 3d6ee32

Please sign in to comment.