Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions variants/promicro/PromicroBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
#define SX126X_DIO2_AS_RF_SWITCH true
#define SX126X_DIO3_TCXO_VOLTAGE (1.8f)

#define PIN_VBAT_READ 17
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
// Default values for battery monitoring voltage divider
// To override, either:
// - set build flags in variant's platformio.ini file
// - use cli to 'set adc.multiplier' (repeaters / rooms)

#ifndef ADC_MULTIPLIER
#define ADC_MULTIPLIER (1.667f) // Dependent on voltage divider resistors. Default 1MOhm & 1.5MOhm divider
#endif

class PromicroBoard : public NRF52BoardDCDC {
protected:
Expand All @@ -32,14 +38,14 @@ class PromicroBoard : public NRF52BoardDCDC {
#define BATTERY_SAMPLES 8

uint16_t getBattMilliVolts() override {
analogReadResolution(12);
analogReadResolution(ADC_RESOLUTION);

uint32_t raw = 0;
for (int i = 0; i < BATTERY_SAMPLES; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / BATTERY_SAMPLES;
return (adc_mult * raw);
return (raw * (AREF_VOLTAGE * 1000) * adc_mult / (1 << (ADC_RESOLUTION)));
}

bool setAdcMultiplier(float multiplier) override {
Expand Down
1 change: 1 addition & 0 deletions variants/promicro/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ build_flags = ${nrf52_base.build_flags}
-D ENV_INCLUDE_BMP280=1
-D ENV_INCLUDE_INA3221=1
-D ENV_INCLUDE_INA219=1
; -D ADC_MULTIPLIER=1.667f
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/sensors>
+<../variants/promicro>
Expand Down
5 changes: 3 additions & 2 deletions variants/promicro/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#define PIN_EXT_VCC (21)
#define EXT_VCC (PIN_EXT_VCC)

#define BATTERY_PIN (17)
#define ADC_RESOLUTION 12
#define PIN_VBAT_READ (17)
#define ADC_RESOLUTION (14)
#define AREF_VOLTAGE (3.6f) // Using default analog reference (AR_INTERNAL), which maps ADC reading to 0 ... 3.6V

////////////////////////////////////////////////////////////////////////////////
// Number of pins
Expand Down