Click here to Skip to main content
15,886,807 members
Articles / Internet of Things / Arduino
Tip/Trick

Save Your IoT Battery with LCD Miser

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
21 Jul 2022MIT1 min read 5.1K   38   3  
Easily blank the screen after a timeout period
One of the biggest battery killers is the backlight on your LCD. Here's a simple to use library which allows it to timeout after a specified period, until it is awoken again.

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:

C++
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.

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

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
United States United States
Just a shiny lil monster. Casts spells in C++. Mostly harmless.

Comments and Discussions

 
-- There are no messages in this forum --