RAK4631 deep sleep with dio interrupt

I have a project running based on the RAK4631_DeepSleep_LoRaWan example.

I am familar with attaching and consuming interrupts in basic arduino sketches.

However, I am not sure how to implement DIO interrupt that can cause a wakeup (and processing) in the RAK4631_DeepSleep_LoRaWan freertos example. I would like to add the DIO interrupt in addition to the existing periodic timer interrupt in the above example.

Looking for any existing examples or suggestions.

Hi John

I need to be able to the same (wake up on interrupt) but using cellular rather than lora/lorawan.

You say the project is base on the RAK4631_DeepSleep_LoRaWan can you describe your power consumption in deep sleep?

After spending a bit of time with the RAK4631-DeepSleep-LoRaWan.ino, the following modifications/additions will add a DIO interrupt wakeup to the example.

In RAK4631-DeepSleep-LoRaWan.ino;

Define a interrupt pin;

#define interruptPin WB_IO6

Add your interupt pin configuration to setup;

void setup(void)
{
  //setup DIO interrupt
  pinMode(interruptPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(interruptPin), DIOInterruptHandler, FALLING );
  ...
}

Add an interrupt handler, that sets a new eventype to be used in the loop;

void DIOInterruptHandler() {
	eventType = 2;
	// Give the semaphore, so the loop task will wake up
	xSemaphoreGiveFromISR(taskEvent, pdFALSE);
}

In the loop, add processing for to a new switch/case;

void loop(void){
	...
	
	if (xSemaphoreTake(taskEvent, portMAX_DELAY) == pdTRUE)	{
	    ...
		
		// Check the wake up reason
		switch (eventType)
		{
		case 0: // Wakeup reason is package downlink arrived
			...
			break;
		case 1: // Wakeup reason is timer
			...
			break;


		case 2: // Wakeup reason is DIO interrupt
			//Do custom processing before sending Lora
			if (sendLoRaFrame())
			{
				Serial.println("LoRaWan package sent successfully");
			}
			else
			{
				Serial.println("LoRaWan package send failed");
				/// \todo maybe you need to retry here?
			}
			break;
		default:
			break;
		}

		...
	}
}

I have striped all the #ifndef MAX_SAVE / #endif for clarity, but they should remain in your code for max power savings.
With the above additions, the original periodic wakeup still function, in addition to the new DIO interrupt wakeup.

1 Like