GPIO RAK19003, is it possible?

Hello!
I am currently writing a program for a BLE remote control with media keyboard and mouse support.
I have slightly rewritten the BlueMicro_BLE (Pierre Constantineau) library code for the rak4631 and it works great.
I am also using the mpr121 touch buttons, they work well too.
To reduce power consumption, I use Bernd Giesecke’s method
The infinite loop is controlled by a semaphore, the semaphore is turned on by an interrupt from the accelerometer.


#define WORK_CYCLES 500
void loop()
{
    uint16_t counter = 0;
/* sleep until we are woken up by an event */
    api_wait_wake();
/* keyboard polling loop */
    while (counter <= WORK_CYCLES)
      {
#if MPR121_DEBUG == 0
	  digitalWrite(LED_GREEN, HIGH);
#endif
/* keyboard event handler */
	  reading_keys();
/* clear accelerometer interrupt */
	  if (acc_interrupt == true)
	    {
		get_acc_int();
	    }
/* BLE polling time (>10) */
	  delay(20);
	  counter++;
#if MPR121_DEBUG == 0
	  digitalWrite(LED_GREEN, LOW);
#endif
      }
    g_task_event_type = 0;
}

After some time, the program automatically switches off the loop. However, the mpr121 chip has its own interrupt pin, which can also be used to optimize power consumption
I have several rak4631 boards, I thought I could remap the RX & TX pins of the RAK19003
as GPIO (since I am not using a UART).
I saw the conversation between Bernd Giesecke, as I understand it, it is easy to do and not to rewrite the variant.h file

/ TXD0 RXD0 on Base Board
#define PIN_SERIAL2_RX (***)
#define PIN_SERIAL2_TX (***)

// Set the interrupt callback function
attachInterrupt(???, int_callback, RISING);

I would be grateful if someone would tell me how to assign GPIO RX or TX to work with interrupt mpr121.

Sorry, I write badly in English.

It is as simple as

// Attach RX pin to interrupt
attachInterrupt(PIN_SERIAL2_RX, int_callback, RISING);

Only limitation, you should not open Serial2 at any time to have this working.

1 Like

Thank you very much, Bernd! Your advice always help me out!