Skip to content

Commit bb4f47c

Browse files
authored
Merge pull request #3 from arduino-libraries/interrupt-handler
Use wake up pin that is not dependent on analog power
2 parents 9c979bc + 4e057cb commit bb4f47c

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

.github/workflows/arduino-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
uses: arduino/arduino-lint-action@v1
2323
with:
2424
compliance: specification
25-
library-manager: submit
25+
library-manager: update
2626
# Always use this setting for official repositories. Remove for 3rd party projects.
2727
official: true
2828
project-type: library

examples/WakeFromPin/WakeFromPin.ino

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
* - Select the Portenta C33's USB port from the Tools menu
2020
* - Upload the code to your Portenta C33
2121
* - Connect a button to pin D0 and ground with a pull-up resistor to 3.3V
22-
* - Connect a button to pin A3 and ground with a pull-up resistor to 3.3V
22+
* - Connect a button to pin D4 and ground with a pull-up resistor to 3.3V
23+
*
24+
* For maximum power saving use external pull-up resistors.
25+
* You will need to power them separately as the 3.3V pin on the board
26+
* is turned off when the device goes to sleep and TURN_PERIPHERALS_OFF is enabled.
27+
* Alternatively, use pinMode(<pin>, INPUT_PULLUP) for the pins and connect the buttons to ground.
2328
* (If you need information about how to wire the buttons check this link: https://docs.arduino.cc/built-in-examples/digital/Button/)
2429
*
2530
* Initial author: C. Dragomir
@@ -29,9 +34,17 @@
2934

3035
// #define TURN_PERIPHERALS_OFF // Uncomment this line to turn off the peripherals before going to sleep
3136
#define SLEEP_PIN D0 // Pin used to put the device to sleep
32-
#define WAKE_PIN A3 // Pin used to wake up the device
37+
38+
/*
39+
The following pins can be used to wake up the device: A0, A1, A2, A3, A4, A5, D4, D7
40+
However turnPeripheralsOff() in this sketch turns off the power lane of the analog pins.
41+
This means they cannot sink current and therefore cannot be used to wake up the device.
42+
Hency only D4 and D7 can be used to wake up the device in this configuration.
43+
*/
44+
#define WAKE_PIN D4
3345

3446
LowPower lowPower;
47+
bool shouldSleep = false;
3548

3649
#ifdef TURN_PERIPHERALS_OFF
3750
#include "Arduino_PMIC.h"
@@ -56,17 +69,11 @@ LowPower lowPower;
5669
#endif
5770

5871
void goToSleep(){
59-
// Turn off the built-in LED before going to sleep
60-
digitalWrite(LED_BUILTIN, HIGH);
61-
62-
#ifdef TURN_PERIPHERALS_OFF
63-
turnPeripheralsOff();
64-
#endif
65-
lowPower.deepSleep();
72+
shouldSleep = true;
6673
}
6774

6875
void setup(){
69-
// External pull-up resistor used for the buttons
76+
// External pull-up resistor used for the buttons for maximum power saving
7077
pinMode(SLEEP_PIN, INPUT);
7178
pinMode(WAKE_PIN, INPUT);
7279

@@ -83,6 +90,17 @@ void setup(){
8390
}
8491

8592
void loop(){
93+
if(shouldSleep){
94+
// Turn off the built-in LED before going to sleep
95+
digitalWrite(LED_BUILTIN, HIGH);
96+
97+
#ifdef TURN_PERIPHERALS_OFF
98+
turnPeripheralsOff();
99+
#endif
100+
lowPower.deepSleep();
101+
shouldSleep = false;
102+
}
103+
86104
// Blink the built-in LED every 500ms when the device is not sleeping
87105
digitalWrite(LED_BUILTIN, LOW);
88106
delay(500);

0 commit comments

Comments
 (0)