Browse Source

Merge pull request #124 from recrof/dev

added battery voltage support for Heltec T114
pull/131/head
ripplebiz 1 year ago
committed by GitHub
parent
commit
0a5a115875
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 20
      src/helpers/nrf52/T114Board.h

20
src/helpers/nrf52/T114Board.h

@ -18,7 +18,8 @@
// built-ins
#define PIN_VBAT_READ 4
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
#define PIN_BAT_CTL 6
#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
class T114Board : public mesh::MainBoard {
protected:
@ -37,17 +38,18 @@ public:
}
#endif
#define BATTERY_SAMPLES 8
uint16_t getBattMilliVolts() override {
int adcvalue = 0;
analogReadResolution(12);
uint32_t raw = 0;
for (int i = 0; i < BATTERY_SAMPLES; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / BATTERY_SAMPLES;
analogReference(AR_INTERNAL_3_0);
pinMode(PIN_BAT_CTL, OUTPUT); // battery adc can be read only ctrl pin 6 set to high
digitalWrite(PIN_BAT_CTL, 1);
delay(10);
adcvalue = analogRead(PIN_VBAT_READ);
digitalWrite(6, 0);
return (ADC_MULTIPLIER * raw) / 4096;
return (uint16_t)((float)adcvalue * MV_LSB * 4.9);
}
const char* getManufacturerName() const override {

Loading…
Cancel
Save