Hi,
I am sure this is obvious... however I cannot get it to work! I am building an add on to a large project wihich requires battery backup when not powered externally. when the external power fails I want to retain the state of the processor/memory and resume when normal power is restored.
The board is a leonardo. I do not seem to be able to get the board to wake up on external interupt. I know the interupt is working, and I know the board is going to sleep.
I have explored a number of online examples, and those provided with the lowerpower library, but to no avail.
The external interupt I am using is int 4 on pin 7.
My test code
#include "LowPower.h"
volatile bool triggered=false;
void wakeUp() {triggered=true;}
void setup()
{
pinMode(7, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
delay(10000) ; //so as not to brick it!
attachInterrupt( 4, wakeUp,RISING);
triggered=false;
}
void loop()
{
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
USBCON = 0;
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
USBDevice.attach();
triggered=false;
digitalWrite(LED_BUILTIN, HIGH);
delay(5000);
}
// from testing the interrupt was fired
// if (triggered) Serial.println("interrupted!");
// else {Serial.println("normal");}
// triggered=false;
the bit commented out, and the volatile 'triggered' were part of testing that the interrupt is seen.
as it stands, the processor goes to sleep... and never wakes up - the led never comes on
As the project uses serial comms (both Serial1 UART and Serial via USB) I have included the usb on/off stuff to make sure the leonardo USB set up is happy.
Thankfully I had the forsight to put a 10second window in the setup to allow for reprogramming!
Electrically, for this test, I am powering the board via USB, pin 7 has a 10k pull down to ground, and the trigger is from the 5v pin on the leonardo.
Any thoughts please
Thanks Ian