Fix battery voltage readouts

This commit is contained in:
Nik Rozman
2026-03-02 15:45:01 +01:00
parent ee1d13f177
commit c41a2932ba
3 changed files with 8 additions and 3 deletions

View File

@@ -20,7 +20,8 @@ void initBatteryADC() {
float readBatteryVoltage() {
// 8 quick reads, no delay() calls, no analogReference() change
int32_t raw=0; for (int i=0; i<8; i++) raw += analogRead(PIN_VBAT_READ); raw /= 8;
return (raw / 4096.0f) * 3.0f * 2.0f;
// Seeed XIAO nRF52840 Sense: 1MΩ + 510kΩ voltage divider on VBAT → multiply by 1510/510
return (raw / 4096.0f) * 3.0f * (1510.0f / 510.0f);
}
int batteryPercent(float v) {