Browse Source
tweak getBattMilliVolts to report battery more accurately
pull/1071/head
Tomas P
7 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
14 additions and
7 deletions
-
variants/thinknode_m2/ThinknodeM2Board.cpp
|
|
|
@ -19,14 +19,21 @@ void ThinknodeM2Board::begin() { |
|
|
|
enterDeepSleep(0); |
|
|
|
} |
|
|
|
|
|
|
|
uint16_t ThinknodeM2Board::getBattMilliVolts() { |
|
|
|
uint16_t ThinknodeM2Board::getBattMilliVolts() { |
|
|
|
analogReadResolution(12); |
|
|
|
delay(10); |
|
|
|
float volts = (analogRead(PIN_VBAT_READ) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096; |
|
|
|
analogReadResolution(10); |
|
|
|
return volts * 1000; |
|
|
|
} |
|
|
|
analogSetPinAttenuation(PIN_VBAT_READ, ADC_11db); |
|
|
|
|
|
|
|
uint32_t mv = 0; |
|
|
|
for (int i = 0; i < 8; ++i) { |
|
|
|
mv += analogReadMilliVolts(PIN_VBAT_READ); |
|
|
|
delayMicroseconds(200); |
|
|
|
} |
|
|
|
mv /= 8; |
|
|
|
|
|
|
|
analogReadResolution(10); |
|
|
|
return static_cast<uint16_t>(mv * ADC_MULTIPLIER ); |
|
|
|
} |
|
|
|
|
|
|
|
const char* ThinknodeM2Board::getManufacturerName() const { |
|
|
|
return "Elecrow ThinkNode M2"; |
|
|
|
} |
|
|
|
} |
|
|
|
|