@kiesel
Found on here:
Quote:
Commented by Manoraj Gnanadhas (Atmel)
2015-01-20 06:23:36 GMT
[Recipients: Nick Gammon]
Hello Nick,
Our design team has confirmed that βNote-3 mentioned under Table 10-1β is a datasheet bug. So you can use any type of interrupt (Rising edge/ Falling edge / Low level / Any logical change) to wake up from sleep mode. Sorry for the inconvenience caused.
Best Regards,
Manoraj Gnanadhas
Not responding to reed relay:
PRIMARY_BUTTON_PIN interrupt is active only in sleep. if you're (un)lucky enough to move magnet when cpu is awake it will ignore it.
More likely is that relay bounce longer than wake up time + 5ms in your loop.
Do away with pin reading, serial print and delay, shorter your loop, longer battery life.
In ISR (PCINT0_vect) set flag, then in a loop check for that flag.
If it's set it's secondary buttton pin that avoke your cpu,
if it's not set it's primary button .
I'm reusing your variables:
#include <avr/sleep.h>
#define DEBUG // coment out when ready to go into the box
#ifndef DEBUG //disable serial in production compile, potentially saves few uA in sleep mode
#define MY_DISABLED_SERIAL
#endif
ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
{
//delayMicroseconds(2);
valueSecondary = true; // ISRs need to finish very fast or the arduino crashes.
void loop()
{
// Sleep until something happens with the sensor
//sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
sleep_bod_disable();//disable BOD - saves~ 15uA
sleep(PRIMARY_BUTTON_PIN-2, CHANGE, 0);
#ifdef DEBUG //get rid of unnecessary slow downs when ready
Serial.println("Woken up");
#endif
if (valueSecondary == true){
valueSecondary = false;
#ifdef DEBUG //get rid of unnecessary slow downs when ready
Serial.print("Secondary:");
#endif
send(msg2.set(1)); //box emptied/mail in the box
}
else{
#ifdef DEBUG //get rid of unnecessary slow downs when ready
Serial.print("Primary:");
#endif
send(msg.set(1));//mail in the box/box emptied
}
}
Unless you really need to know if box was opened then closed, then check pin states in my if/else after 10-50ms delay, experiment until you get no bounce errors. BUT it will increase battery drain SIGNIFICANTLY.
You will have 2 messages sent per event, one per door opening and one per door closing.