Hi.
Arduino Newbie here. This is my very first Arduino project and I’m stuck with a basic thing.
I want to put my rp2040 to deep sleep mode and wake it up using an external interrupt using a GPIO pin.
My query is in 2 parts.
-
Can we use the same pin to receive a signal and be used as an interrupt pin?
(For example, pin 2 receives a signal from photodiode capturing light, and then this pin sends interrupt to wake the mcu up. ) -
Does _wfi() function actually put the mcu to sleep?
I used this code and I see no difference in the behaviour. The functionality in loop() still executes.
#include <Arduino.h>
// Define the pin connected to the photodiode
const int photodiodePin = 2;
// Interrupt Service Routine (ISR)
void handleInterrupt() {
// This function will be called when the interrupt occurs
// Wake up the device
}
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
delay(1000); // Wait for serial to be ready
// Initialize the photodiode pin as an input
pinMode(photodiodePin, INPUT);
// Attach interrupt to the photodiode pin
// This will call the handleInterrupt function when a rising edge is detected
attachInterrupt(digitalPinToInterrupt(photodiodePin), handleInterrupt, RISING);
Serial.println("Setup complete. Going to sleep...");
}
void loop() {
// Go to sleep using WFI (Wait For Interrupt)
__wfi();
// Code here will run after the device wakes up
Serial.println("Woke up!");
delay(1000); // Add a delay to avoid rapid prints
}
While doing some googling, I found out that since it is an pi based mcu, I’d need pico sdk to achieve this behaviour. But I’m kinda lost here. That is much complicated for me.
I would appreciate if experts here can point me to any potential solutions/ resources I can follow.
Also, please be kind if my explanation wasn’t so good. I just started learning arduino so I have a very limited technical vocabulary regarding arduino.
Thanks in advance for any help.