Situation:
I made/developing this controller (with many functions) with use of a Pro Micro (ATMega32u4) and want to extend it with a wake-up functionality when touching it (with use of a touch sensor). This all to save some energy when not used. So when the device is picked up/touched, the device woke up. When there is no contact, it will go to sleep after a while. The reach distance of the touch sensor will be extended with a small strip of copper around the case.
Picture of the device:
I use pin 9 of the touch sensor and the pin 16 of the IR-sensor to wake up but it doesn't work. Both device functions works OK, I can read the touch state (low=untouched or high=touched) and I can receive IR-commands because it is already fully implemented. When receiving a signal, those pins will be high for some period.
Software question:
Is there something wrong with my code (wrong parameters?)? The device goes to sleep when executing this code (but never woke up):
#include <avr/sleep.h> // To enter sleep mode, save power
#include <LowPower.h> // To enter sleep mode, save power
......
#define TEP_IR_RECV_PIN 16
#define TEP_PIN_TOUCHSENSOR 9
......
......
void sleep()
{
attachInterrupt( TEP_PIN_TOUCHSENSOR, wakeup, HIGH );
attachInterrupt( TEP_IR_RECV_PIN, wakeup, HIGH );
// Enter power down state with ADC and BOD module disabled.
// Wake up when wake up pin is high.
LowPower.powerDown( SLEEP_FOREVER, ADC_OFF, BOD_OFF );
// Disable external pin interrupt on wake up pin.
detachInterrupt( TEP_PIN_TOUCHSENSOR );
detachInterrupt( TEP_IR_RECV_PIN );
}
Sleep function of my EnjoyPad class (will be triggered when pushing power button on remote control or when reach timeout when not touched or doing anything):
void TEnjoyPad::setSleepMode()
{
// Notify user device entering sleep mode, beep twice
setBeep( 200 );
setBeep( 200, 100, false );
// To be sure: Trigger end / unhandled down events and reset states
reset(init);
// Handle sleep event
eventSleep();
// Stop all peripherals
end();
// Finally go to sleep, code stops here
TEP_LIB_FUNCS::sleep();
// Device woke up
setBeep( 500, 100, false );
// Restart all peripherals
begin();
// Handle wake up event
eventAwake();
}
Any ideas what could be wrong? If I need to change a pin for the touch sensor, it is possible but I want to be sure it is the correct pin because I need to solder it (not on a breadboard). Pins left: 10, 14 and A3
NOTICE: I have tested, with just a delay replacement instead of going to sleep, the functions after the sleep are working just fine. So I can hear a beep and device comes on again. There is no problem with the code after sleep(), it just doesn't want to wake-up.