By dave | March 21, 2016

In this article we’ll discuss building a low power Arduino menu using tcMenu library. We will use a TFT screen and a rotary encoder connected to a PCF8574 device. The device will be SAMD MKR board.

I’ve picked this choice purposely, because it’s non-trivial, and requires a lot of digging to make sure power usage is a low as possible.

Running an Arduino menu on battery

If the device can be powered from the mains, then power usage is probably not the biggest issue. However. if we want to use as little power as possible because the application needs to run on batteries and is limited in size, then we must avoid polling and put the chip into low power states when not in immediate use. For menu projects, where there’s always user input, this is a bit more complex. Let’s investigate each component in more detail. Although out of the box Arduino is not setup to be power efficient (loop based polling), our libraries can counter this and make battery running possible.

Low power Arduino menu with TaskManagerIO and IoAbstraction

Let’s break down this into a number of steps, we’re assuming you’re using Arduino here, but this also works with any of our supported environments. We also assume you’ve got an embedded menu project based on TcMenu. Which means we also have IoAbstraction button/switch/rotary encoder support library and TaskManagerIO event scheduler available to us.

Ensure “switches” is using interrupts for rotary encoders and buttons

IoAbstraction switches will need to run in interrupt mode for any rotary encoders or buttons to have any chance of success (as polling an I2C device many times a second could never be considered power efficient). So when setting up the code generator make sure to use interrupt mode with your input plugin.

Note that some Arduino’s have very limited interrupt pin availability so consult your guide carefully.

Turn off the display in the menu code

Also, we’ll need to turn the display when it’s not in use and stop the rendering loop. Stopping the menu render loop is fairly straight-forward, and would normally be done before going into low power mode. First, turn off the display by consulting the library you’re using, then tell the renderer to stop updating the display:

renderer.turnOffDisplayUpdates(true);

Later to re-enable the menu rendering:

renderer.setUpdatesPerSecond(updatesSec);

And that is the display sorted.

TaskManagerIO lower power support

Next, we’ll need to use the low power support in task manager to put the chip into a low power state between tasks running. This guide explains exactly how to do this for SAMD and has a more general discussion but in short here is a simple example showing a modified Arduino run loop:

// assuming Arduino use with loop function, if this is a C++/CMake project adjust as needed.
void loop() {
    // call run loop as usual
    taskManager.runLoop();
    
    // then work out how long to the next task
    int millisDelay = (taskManager.microsToNextTask() / 1000UL);
    
    // let's say we use 1 second as the threshold to go into low power
    // assuming you have already turned off screen etc.
    if(millisDelay > 1000) {
        // here you'd call your low power function for millisDelay. For example
        // if you had a function called myLowPowerFunction that kept interrupts
        // enabled but lowered power consuption, we'd call it here.
        myLowPowerFunction(millisDelay);
    }
}

Summary

So in summary, polling must be avoided when idle if we want to save power. We need to ensure any hardware connected to the device is also put into a low power state, and also stop TcMenu from trying to render. With these things done, a reasonably low power menu should be quite possible.

Other pages within this category

comments powered by Disqus

This site uses cookies to analyse traffic, and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.

Send a message
X

Please use the forum for help with UI & libraries.

This message will be securely transmitted to our servers.