How would I implement two separate interrupts for wake up by GPIO

How would I implement two separate interrupts for wake up by GPIO?
For example I want to use both GPIO6 and GPIO9 as interrupts to wake up from sleep.

Does anyone have an example they can post or an idea on how to get started?
I am using the 1/2 AA module.

Here is the code that works and wakes up from sleep with one GPIO interrupt - GPIO6

#include “Arduino.h”
#define INT_GPIO GPIO6
#define timetillsleep 1000
static TimerEvent_t sleep;
uint8_t lowpower=1;
#include “LoRaWan_APP.h”
#include “Arduino.h”


  • set LoraWan_RGB to 1,the RGB active in loraWan
  • RGB red means sending;
  • RGB green means received done;
    #ifndef LoraWan_RGB
    #define LoraWan_RGB 0

#define RF_FREQUENCY 915000000 // Hz

#define TX_OUTPUT_POWER 20 // dBm

#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 10 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_IQ_INVERSION_ON false

#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 30 // Define the payload size here

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

double txNumber;

int16_t rssi,rxSize;
void DoubleToString( char *str, double double_num,unsigned int len);


void onSleep()
Serial.printf(“Going into lowpower mode. Press user key to wake up\r\n”);
void onWakeUp()
if(digitalRead(INT_GPIO) == 0)
Serial.printf(“Woke up by GPIO, %d ms later into lowpower mode.\r\n”,timetillsleep);
//timetillsleep ms later into lowpower mode;
TimerSetValue( &sleep, timetillsleep );
TimerStart( &sleep );

void setup() {
// put your setup code here, to run once:
boardInitMcu( );


Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
                               LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                               LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                               true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); 

TimerInit( &sleep, onSleep );
Serial.printf(“Going into lowpower mode. Press user key to wake up\r\n”);

void loop() {
Radio.Sleep( );
//note that lowPowerHandler() runs six times before the mcu goes into lowpower mode;
// put your main code here, to run repeatedly:
Serial.printf(“woken up-with just this stops at 6 mcu cycles\r\n”);


//txNumber += 0.01;
txNumber += 1;
sprintf(txpacket,"%s",“Hello world number”); //start a package
sprintf(txpacket+strlen(txpacket),"%d",txNumber); //add to the end of package

DoubleToString(txpacket,txNumber,3); //add to the end of package

//turnOnRGB(COLOR_SEND,0); //change rgb color

Serial.printf("\r\nsending packet “%s” , length %d\r\n",txpacket, strlen(txpacket));

Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out



void DoubleToString( char *str, double double_num,unsigned int len) {
double fractpart, intpart;
fractpart = modf(double_num, &intpart);
fractpart = fractpart * (pow(10,len));
sprintf(str + strlen(str),"%d", (int)(intpart)); //Integer part
sprintf(str + strlen(str), “.%d”, (int)(fractpart)); //Decimal part

First a note: On Discourse-based forums, you can use triple backticks to ensure that source code is pretty-printed (and highlighted) as source code, rather than all indentation disappearing, like for instance:

int main() {
 // your code here

which would be shown as:

int main() {
 // your code here

To answer your question:
I’ve needed to do similar things in the past. (For me, it was a wakeup which could happen either from a timer or from a button press and I had to see which of the two it was).

The most pragmatic approach which to my knowledge is used frequently in these kinds of situations, is to (re-)read the GPIO-pin(s) once you’ve woken up, to check which one it was that triggered the wakeup.

Thanks for the tip on posting and my question.
My 1st interrupt is on the rising edge and stays high for 2 seconds.
The second interrupt is on a falling edge maybe low for a few hundred milliseconds so if I wait a second and then re-poll like you said in a one second this may work.

I’m not sure if this is possible in sleep (or even at all) - but have you tried using individual pins as interrupts? I can’t find a good manual for the ASR650x that tells me which pins support being interrupts - but you could try the following:

void onWakeUpGPIO1(){<insert_function_here>}

void onWakeUpGPIO2(){<insert_function_here>}

1 Like

Yes thanks for the suggestion - I did this and had to add some delays but it seems to be working okay now.