19
19
* - Select the Portenta C33's USB port from the Tools menu
20
20
* - Upload the code to your Portenta C33
21
21
* - 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.
23
28
* (If you need information about how to wire the buttons check this link: https://docs.arduino.cc/built-in-examples/digital/Button/)
24
29
*
25
30
* Initial author: C. Dragomir
29
34
30
35
// #define TURN_PERIPHERALS_OFF // Uncomment this line to turn off the peripherals before going to sleep
31
36
#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
33
45
34
46
LowPower lowPower;
47
+ bool shouldSleep = false ;
35
48
36
49
#ifdef TURN_PERIPHERALS_OFF
37
50
#include " Arduino_PMIC.h"
@@ -56,17 +69,11 @@ LowPower lowPower;
56
69
#endif
57
70
58
71
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 ;
66
73
}
67
74
68
75
void setup (){
69
- // External pull-up resistor used for the buttons
76
+ // External pull-up resistor used for the buttons for maximum power saving
70
77
pinMode (SLEEP_PIN, INPUT);
71
78
pinMode (WAKE_PIN, INPUT);
72
79
@@ -83,6 +90,17 @@ void setup(){
83
90
}
84
91
85
92
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
+
86
104
// Blink the built-in LED every 500ms when the device is not sleeping
87
105
digitalWrite (LED_BUILTIN, LOW);
88
106
delay (500 );
0 commit comments