sensors: INA219 sleeps between telemetry reads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-12 12:51:40 +01:00
1 parent 6fe0c0f8e1
commit b1e4e65c52
1 file changed
+14 -1
@@ -328,14 +328,27 @@ static void query_ina3221(uint8_t ch, uint8_t sub_ch, CayenneLPP& lpp) {
static Adafruit_INA219 INA219_ALT((TELEM_INA219_ADDRESS == 0x40) ? 0x41 : 0x40);
static Adafruit_INA219* active_ina219 = &INA219;
// CUSTOM (TeTeHacko): the INA219 sleeps between reads. begin() leaves it in
// continuous conversion, ~0.7 mA typ / 1 mA max (datasheet), for a value that is
// read only when someone asks for telemetry; power-down is ~6 uA and keeps the
// calibration. On a 0.5 W solar node in December that is 15-20 % of the budget.
// Idea and first patch: Alkel Brostl.
static uint8_t init_ina219(TwoWire* wire, uint8_t addr) {
active_ina219 = (addr == TELEM_INA219_ADDRESS) ? &INA219 : &INA219_ALT;
return active_ina219->begin(wire) ? 1 : 0;
if (!active_ina219->begin(wire)) return 0;
active_ina219->powerSave(true);
return active_ina219->success() ? 1 : 0;
}
static void query_ina219(uint8_t ch, uint8_t, CayenneLPP& lpp) {
active_ina219->powerSave(false);
if (!active_ina219->success()) return; // bus gone: report nothing rather than stale zeros
// begin() selects 12-bit single-sample bus and shunt conversions, 532 us each:
// 3 ms covers the wake-up and one fresh pair with margin.
delay(3);
lpp.addVoltage(ch, active_ina219->getBusVoltage_V());
lpp.addCurrent(ch, active_ina219->getCurrent_mA() / 1000.0f);
lpp.addPower(ch, active_ina219->getPower_mW() / 1000.0f);
active_ina219->powerSave(true);
}
#endif