Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add low power mode functionality #188

Open
8 of 19 tasks
melkati opened this issue Mar 1, 2024 · 5 comments
Open
8 of 19 tasks

Add low power mode functionality #188

melkati opened this issue Mar 1, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@melkati
Copy link
Owner

melkati commented Mar 1, 2024

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:

  • Add structures to store data for Low Power Mode
  • Add user configurable data to preferences
  • Implement One Shot measurements for SCD41/SCD40
  • Implement One Shot measurements for CM1106SL-NS
  • Add Deep Sleep functionality (with data storage between sleep and wake up)
  • Add hysteresis (thresholds) to filter new readings handling to save energy #212
  • Add support logic for sample time coherency in the different working phases
  • Add functionality and needed logic for CO2 sensor calibration in low power
  • Add configuration to menu
  • Add configuration to web config
  • Test with as many hardware combinations as possible
  • Document on GitHub
  • Document on Blog

TO DO/FIX:

  • Support for Sensirion SCD30 Sensor (WIP. Half implemented. Partially Working. Non optimized)
  • Cleanup code

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

  • Deal with third party dependencies (apport pull request or fork, depending on case)
  • Internal code structure (each code where it should be (Sensors, DeepSleep, e-Ink, etc)
  • Reduce mess and duplicity
  • Improve code readability, reusability and maintainability

IMPORTANT NOTES:

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

@melkati melkati changed the title Low power mode Add low power mode functionality Mar 1, 2024
@melkati melkati self-assigned this Mar 1, 2024
@melkati melkati added the enhancement New feature or request label Mar 1, 2024
@melkati melkati added this to the Low power mode milestone Mar 1, 2024
@melkati melkati pinned this issue Mar 1, 2024
@melkati
Copy link
Owner Author

melkati commented Mar 11, 2024

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

Test rig:

  • Lilygo T7 board (with on board LED)
  • Waveshare 2.9" e-Ink display
  • Sensirion SCD41 CO2/Temp/Humidity sensor

The facts:

  • 1mAh while in deep sleep (probably ~500µA without LED)
  • 4.5mAh average over 1 minute with one sensor reading and one display fast update
  • 6.5mAh average over 1 minute with one reading + one complete display redraw + WiFi connection + MQTT sending

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
Copy link
Owner Author

melkati commented Mar 14, 2024

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
Copy link
Owner Author

melkati commented Mar 14, 2024

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: #198

@melkati melkati added the help wanted Extra attention is needed label Mar 17, 2024
@melkati
Copy link
Owner Author

melkati commented Mar 25, 2024

MORE ON WORKING MODES

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

Working modes:

HIGH_PERFORMANCE

  • 100% implemented and working
  • Normal working mode without power savings.
  • Sensors work in continuous sampling mode and CO2 Gadget is always ON.
  • All CO2 Gadget's functionality is available.

BASIC_LOWPOWER

  • 0% implemented and working
  • Most of the functionality TBD.
  • Probably it will be a mode for sensors without special power saving modes where CO2 Gadget will implement some power saving techniques like a longer sampling period (where sensors permit it) or short light sleep periods).
  • All CO2 Gadget's functionality is available.

MEDIUM_LOWPOWER

  • 75% implemented and working
  • Normal low power working mode, only available for monitors with sensors that support a real working mode (as one-shot measurements).
  • At power ON CO2 Gadget will be in HIGH_PERFORMANCE so the user has an opportunity to interact with it via web pages, on-display menu (if a display is available) or serial menu. CO2 Gadget will keep working on HIGH_PERFORMANCE for a user defined time then go into low power mode.
  • In low power mode, CO2 Gadget will be sleeping most of the time.
  • Each number of seconds (configured by user) CO2 Gadget will take a reading from the sensor. After EVERY number of readings (configured by user) CO2 Gadget will connect to WiFi and send the readings via MQTT or ESP-Now.
  • For example, users can configure CO2 Gadget to take a measurement every 60 seconds and every 5 readings (once every 5 minutes) connect to WiFi and send the measurements.
  • At any time, the user can press a button to enter an "interactive mode" where CO2 Gadget will work almost as in HIGH_PERFORMANCE and the user can do almost everything: access web pages, use menu, etc. Sensor will still take one shot measurements (for example every 30 or 60 seconds.

MAXIMUM_LOWPOWER

  • 0% implemented and working
  • Most of the functionality TBD. Probably CO2 Gadget will be turn off completely, with the help of some external circuit (like a MOSFET or a RTC board), so with almost zero current consumption, and work for a very short time (user-defined) to take a new measurement.
  • The user can press a button at any time to see the display.

@melkati
Copy link
Owner Author

melkati commented Mar 31, 2024

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

@melkati melkati unpinned this issue Apr 8, 2024
@melkati melkati pinned this issue Jun 9, 2024
@melkati melkati unpinned this issue Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: In review
Development

No branches or pull requests

1 participant