From b1e4e65c527144e111543bf9e393ee712295411f Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Thu, 12 Nov 2026 12:51:40 +0100 Subject: [PATCH] sensors: INA219 sleeps between telemetry reads Co-Authored-By: Claude Opus 5.5 --- src/helpers/sensors/EnvironmentSensorManager.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index ceda7b6b..3c7c9cd2 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -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