Low Power mode. Wake up periodic + Wake up manually

Hi there!

I need your help clarifying how to use Low Power library: GitHub - rocketscream/Low-Power: Low Power Library for Arduino

Currently I'm working on an irrigation project with Arduino Pro Mini. This setup is stand-alone, no connections to external apps or servers. This is challenging since I have buttons for:

button 1: enter programming mode while pressed
button 2: while on programming mode, switch from max moisture to min (swap values shown on LED display)
button 3: increment value
button 4: decrement value

Routine works as follows while awake (always on now):

loop () {
Read sensor
Show soil moisture on a LED display
Read buttons states
If button1 is pressed
enter programming mode
If button1 is released
exit programming mode
wait for 30min
}

I'm going to use the low power library mentioned above to read sensors every 30min and put the Arduino to sleep as described in:

I also need a way to manually awake the device from sleep just in case I need to re-set max moisture and min moisture. For that purpose, I will be using another button (wake from sleep), but was wondering if this is feasible, using this example:

Routine would work as follows while awake (always on now):

loop () {
Read sensor
Show soil moisture on a LED display
Read buttons states
If button1 is pressed
enter programming mode
If button1 is released
exit programming mode
sleep for 30min
}
While in sleep mode, if button 5 is pressed, wake up for 1 min (so that I can change settings)

Thoughts?

TIA

You tell You use "Ardiono" but there are several of that kind. Check data sheets for the possibility to put them into sleep mode and waking them up the way You want.
Explore that library, read all You can read how to use it.

Railroader:
You tell You use "Ardiono" but there are several of that kind.

My bad, Arduino Pro Mini. Will update original post

Appreciate that whilst the low power library will put the processor to sleep, the Pro Mini might still take 3mA or more.

Must be modified to remove regulator, remove resistor for pilot light.

You can also consider the TPL5111 from Adafruit too. You can set the sleep time in hardware. It also includes a button that will manually wake up your device.

From that library example:
powerDownWakeExternalInterrupt

What would happen if you substituted :
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
With
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
Leaving the rest of the interrupt code in?

Did you consider coding the entire system to just use 1 button and 1 LED?
By using mills for timing, state variables, and not using delays you can have “holding” down the button for “short, medium, and long durations” do different things.

Slumpert:
From that library example:
powerDownWakeExternalInterrupt

What would happen if you substituted :
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
With
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
Leaving the rest of the interrupt code in?

Sorry, did not follow your reasoning

Slumpert:
Did you consider coding the entire system to just use 1 button and 1 LED?
By using mills for timing, state variables, and not using delays you can have “holding” down the button for “short, medium, and long durations” do different things.

Yes, I thought about that. In fact, I'm using a library that supports detecting the length (in seconds) a button has been pressed, so I will probably reduce the number of buttons in the future. IE: pressed once: action1, pressed for 2sec: action2 and so on. (GitHub - evert-arias/EasyButton: Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.)

vazquezjm:
Sorry, did not follow your reasoning

That’s not my reasoning, that’s the limit of the “sleep” library you choose.

Either it can sleep for a max of 8secs a cycle(likely not accurate) or it can sleep until a interrupt.
I was thinking it might be able to do both.

Did you somehow think that library supports one continuous 30min nap?

I managed to make it wake up from both "regular" sleep mode and from an interrupt, using the library mentioned above. Here's the code:

#include "LowPower.h"

// Use pin 2 as wake up pin
const int wakeUpPin = 2;

// Used to determine if board woke up from an interrupt
bool interrupt = false;

void wakeUp() 
{
	// Just a handler for the pin interrupt
	interrupt = true;
}

void setup() 
{
	Serial.begin(115200);
	// Configure wake up pin as input. This will consumes few uA of current.
	pinMode(wakeUpPin, INPUT_PULLUP);
	delay(50);
}


void loop() 
{
	// Allow wake up pin to trigger interrupt on low
	attachInterrupt(0, wakeUp, LOW);

	// Enter power down state with ADC and BOD module disabled. Wake up when wake up pin is low
	Serial.println("Sleep for 8s....");
	delay(100);
	LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

	// Disable external pin interrupt on wake up pin
	detachInterrupt(0);

 	// Do something here
	if (interrupt) {
    	// Woke up from an interrupt
    	interrupt = false;
	} else {
    	// Woke up from sleep
	}
}

Set up:

Slumpert:
Did you somehow think that library supports one continuous 30min nap?

Hmm, not exactly, but can be done somehow: Sleep for 4 hours · Issue #43 · rocketscream/Low-Power · GitHub