Skip to content

Commit

Permalink
Merge pull request #3 from arduino-libraries/interrupt-handler
Browse files Browse the repository at this point in the history
Use wake up pin that is not dependent on analog power
  • Loading branch information
sebromero authored Aug 30, 2024
2 parents 9c979bc + 4e057cb commit bb4f47c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: arduino/arduino-lint-action@v1
with:
compliance: specification
library-manager: submit
library-manager: update
# Always use this setting for official repositories. Remove for 3rd party projects.
official: true
project-type: library
38 changes: 28 additions & 10 deletions examples/WakeFromPin/WakeFromPin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
* - Select the Portenta C33's USB port from the Tools menu
* - Upload the code to your Portenta C33
* - Connect a button to pin D0 and ground with a pull-up resistor to 3.3V
* - Connect a button to pin A3 and ground with a pull-up resistor to 3.3V
* - Connect a button to pin D4 and ground with a pull-up resistor to 3.3V
*
* For maximum power saving use external pull-up resistors.
* You will need to power them separately as the 3.3V pin on the board
* is turned off when the device goes to sleep and TURN_PERIPHERALS_OFF is enabled.
* Alternatively, use pinMode(<pin>, INPUT_PULLUP) for the pins and connect the buttons to ground.
* (If you need information about how to wire the buttons check this link: https://docs.arduino.cc/built-in-examples/digital/Button/)
*
* Initial author: C. Dragomir
Expand All @@ -29,9 +34,17 @@

// #define TURN_PERIPHERALS_OFF // Uncomment this line to turn off the peripherals before going to sleep
#define SLEEP_PIN D0 // Pin used to put the device to sleep
#define WAKE_PIN A3 // Pin used to wake up the device

/*
The following pins can be used to wake up the device: A0, A1, A2, A3, A4, A5, D4, D7
However turnPeripheralsOff() in this sketch turns off the power lane of the analog pins.
This means they cannot sink current and therefore cannot be used to wake up the device.
Hency only D4 and D7 can be used to wake up the device in this configuration.
*/
#define WAKE_PIN D4

LowPower lowPower;
bool shouldSleep = false;

#ifdef TURN_PERIPHERALS_OFF
#include "Arduino_PMIC.h"
Expand All @@ -56,17 +69,11 @@ LowPower lowPower;
#endif

void goToSleep(){
// Turn off the built-in LED before going to sleep
digitalWrite(LED_BUILTIN, HIGH);

#ifdef TURN_PERIPHERALS_OFF
turnPeripheralsOff();
#endif
lowPower.deepSleep();
shouldSleep = true;
}

void setup(){
// External pull-up resistor used for the buttons
// External pull-up resistor used for the buttons for maximum power saving
pinMode(SLEEP_PIN, INPUT);
pinMode(WAKE_PIN, INPUT);

Expand All @@ -83,6 +90,17 @@ void setup(){
}

void loop(){
if(shouldSleep){
// Turn off the built-in LED before going to sleep
digitalWrite(LED_BUILTIN, HIGH);

#ifdef TURN_PERIPHERALS_OFF
turnPeripheralsOff();
#endif
lowPower.deepSleep();
shouldSleep = false;
}

// Blink the built-in LED every 500ms when the device is not sleeping
digitalWrite(LED_BUILTIN, LOW);
delay(500);
Expand Down

0 comments on commit bb4f47c

Please sign in to comment.