Save Your IoT Battery with LCD Miser

Updated on 2022-07-21

Easily blank the screen after a timeout period

Introduction

In IoT, battery life is king. These widgets aren't very useful if you have to charge them every other hour. Due to this, most IoT devices have sometimes elaborate power saving schemes, but there's no built in facility for one of the biggest battery killers of them all - your screen's backlight.

Enter LCD Miser. This is a simple to use Platform IO library (although it can be copied into your libraries in the Arduino IDE) that takes over your screen's backlight and provides a timeout.

On the ESP32, it fades just like a smartphone will. On other platforms, it simply blanks.

Using the Code

Using the code is simple:

lcd_miser<PIN_NUM_BCKL,BCKL_HIGH> lcd_power;
...
void setup() {
  Serial.begin(115200);
  // Must initialize the class
  lcd_power.initialize();
  // uncomment to change the timeout
  // to 10 seconds
  //lcd_power.timeout(10000);
  // set up the button callback
  button0.callback([](bool pressed,void* state) 
    {lcd_power.wake();});
  // fill the screen
  lcd.fill(lcd.bounds(),color_t::white);

}

void loop() {
  // IMPORTANT: You must always
  // pump the lcd_power so it can
  // have a chance to time out
  lcd_power.update();
  // ensure button callbacks
  // get fired
  button0.update();
}

This example is using htcw_gfx and htcw_button to do much of the heavy lifting not directly related to the screen's backlight. You can see all you need are initialize(), update() and wake(). Calling wake() resets the timer so you can keep calling it to prevent the screen from turning off.

htcw_gfx htcw_button

One thing to note is you should tell whichever graphics library you use that there is no backlight on your display, usually by setting the pin assignment to -1. This way, you don't have two things fighting over the same pin, which can cause problems.

You include this in your project by adding this to your platformio.ini:

lib_ldf_mode = deep
lib_deps = 
    codewitch-honey-crisis/htcw_lcd_miser

History

  • 21st July, 2022 - Initial submission