melkati / CO2-Gadget

An advanced CO2 Monitor/Meter firmware for ESP32 with Android and iOS App for real time visualization and charting of air data, data logger, a variety of communication options (BLE, WIFI, MQTT, ESP-Now) and many supported sensors.
https://emariete.com/medidor-co2-gadget/
GNU General Public License v3.0
59 stars 13 forks source link

Add low power mode functionality #188

Open melkati opened 4 months ago

melkati commented 4 months ago

Add low power modes to CO2 Gadget,

Starting with SCD41 sensor (not too expensive and widely available).

Nothing too complex but with different low power modes the user can select in preferences:

  1. None = No power savings, as working now.
  2. Basic = Use the sensors on low power mode (one shot measurement instead of continuous measurement).
  3. Medium = Basic + Deep Sleep between measurements. Also, the option to connect to WiFi, MQTT or ESPNow each x measurements (for example time between measurements = 5 minutes and send data each 6 measurements).
  4. Maximum = every possibility to save power (TBD: Possible it will only measure and display on demand, when not working on external power, for maximum autonomy on battery).

Some of the options will work also for SCD40 and SCD30 (no real low power measurement but support a pseudo low power mode).

This is linked also to eInk (ePaper) display support. (There is already work in parallel at #190)

Tasks to implement:

TO DO/FIX:

As for the cleanup code there are multiple tasks to do:

IMPORTANT NOTES:

Warning! Take care. Some CO2 sensors need re-calibration after changing sample time interval.

melkati commented 4 months ago

First preliminary data on my tests with a Low Power CO2 Gadget:

Test rig:

The facts:

Current consumption measurements:

One reading + one display fast update

image

One reading + one complete display redraw + WiFi connection + MQTT sending

image

Forecast with a 2700mA Li-Ion battery:

Given Information: Power of Battery: 2700 mAh Discharge Safety: 20% Average Power Consumption per Hour: 1.71 mAh Duration of Code Execution: 3.1 seconds Sleep Time: 295.65 seconds Consumption During Code Execution: 69 mA Consumption in Sleep Mode: 1000 µA (or 1 mA)

image

Results:

The estimated battery life with these updated calculations is approximately 1266 hours, or around 52 days and 18 hours. This estimate considers the average power consumption during code execution and sleep time, along with the total battery capacity and discharge safety.

N.B.: Test were done with the development version at that time. Probably (almost certainly) it will change in the future, as development continues, to better or worse...

melkati commented 4 months ago

I just uploaded the first version with e-Ink and Low Power support to branch: https://github.com/melkati/CO2-Gadget/tree/low-power-eink

Now I will remove the old individual e-Ink and Low Power branches.

THIS IS A PRE-ALPHA VERSION (it's intended only for active development)

It is not a version for you to report things to me because there are many and you would block me (although you can tell me anything you want, of course!)... now, what I am doing is going quickly to have a stable and functional skeleton as soon as possible.

Nor to comment on options because now the important thing is that it works well and then decisions will come about how it should work for the user.

There are still many things to do, to fix and to test until we can merge this on the master version... It is a Work In Progress version for you to know and participate.

The Sensirion SCD30 sensor is partially supported (SCD40, SCD41 and CM1106SL-NS are already supported for the most part).

There are four power modes: HIGH_PERFORMANCE, BASIC_LOWPOWER, MEDIUM_LOWPOWER, MAXIMUM_LOWPOWER Only NO_LOWPOWER and MEDIUM_LOWPOWER are implemented (partially).

Some examples of things you can help me with, and would be very useful for me...

BUTTONS:

There is a wakeup pin that wakes up CO2 Gadget and puts it in interactive mode for a time. This has meant many changes in the treatment of buttons and GPIOs that have been very little tested (especially the different combinations that there may be)... All of this is taken "with a grain of salt". The idea is that a short press takes a measurement, displays it (if it is not eInk, turns on the display for two or three seconds) and returns to deep sleep. A long press (keep the button pressed once the meter is initialized) enters interactive mode (with everything: menu, wifi, mqtt, web server, etc.) and will return to deep sleep after a while (which will reset each time pressing a button, entering through the serial menu or interacting with the web server). That the serial port on the Lilygo T-Display S3 board disappears every time it goes into deep sleep is not helping... 😤

EINK:

The structure of the TFT must be copied so that it is similar in EINK (and OLED, which is very similar to EINK). EINK times must be optimized as much as possible because it will make a big difference in autonomy. Display updates take a long time and the meter has to be awake, consuming battery.

For example, a screen redraw with the GDEM029T94 display takes about 1 second while the same with the DEPG0213BN display takes almost 1.6 seconds, that difference will suppose half the autonomy with the DEPG0213BN display. Probably both can be optimized.

Please, if you plan to work on anything, tell me first so I can take it into account when making other changes because I'm going very fast and I could change parts you're working on because I don't know...

melkati commented 4 months ago

Beta testing

This version is not open to beta testing yet, but you can collaborate, if you want.

If you can compile your own CO2 Gadget from source and you have a SCD41 sensor (and ideally an e-Ink board or display) you can collaborate. 😀 Just drop me a message here!

If you want to collaborate with testing, please, click here: https://github.com/melkati/CO2-Gadget/issues/198

melkati commented 3 months ago

MORE ON WORKING MODES

The actual state on the low-power-eink branch is as follows:

Working modes:

HIGH_PERFORMANCE

BASIC_LOWPOWER

MEDIUM_LOWPOWER

MAXIMUM_LOWPOWER

melkati commented 3 months ago

In preparation for the general availability of CO2 Gadget with the new functionality I published a post to build a "Low Power CO2 monitor with a Lilygo TTGO T5 board and the SCD41 Sensor".

It includes some calculations in battery autonomy (I estimate it should be around 90 days, depending on configuration). https://emariete.com/en/co2-meter-co2-gadget-low-power-with-lilygo-ttgo-t5-epaper-and-sensor-sensirion-scd41/

242365-Boxed-CO2-Gadget_Lilygo_TTGO-T5_SCD41