-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeepSleep_WakeFromRTC_H7.ino
83 lines (63 loc) · 2.56 KB
/
DeepSleep_WakeFromRTC_H7.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Charger Demo
This sketch demonstrates how to use the PowerManagement library enable low power modes on the Arduino Portenta H7.
* In the setup() function, it enters standby mode and waits for a wakeup event from the RTC.
* The loop() functionit is not used in this sketch.
IMPORTANT: Please note that this sketch has to be uploaded to the M4 core too in order to achieve the lowest power consumption.
Requirements:
- Arduino Arduino Portenta H7
- Arduino IDE
- PowerManagement library (installable from the Arduino Library Manager)
Usage:
1. Connect a battery to the board.
2. Upload the Sketch to the M4 core:
- Open the provided sketch in the Arduino IDE.
- Select your board type and port from the "Tools" menu.
- Select the M4 core from the "Tools" menu.
- Click the "Upload" button to upload the sketch to your board.
3. Upload the Sketch to the M7 core:
- Select the M7 core from the "Tools" menu.
- Click the "Upload" button to upload the sketch to your board.
4. Observer LED behavior:
- The blue LED will turn on when the board is awake.
- The blue LED will turn off when the board goes to sleep.
- The red LED will blink if the board fails to initialize.
*/
#include "Arduino_PowerManagement.h"
#include "MAX1726Driver.h"
Board board;
Charger charger;
MAX1726Driver fuelgauge(&Wire1);
void setup() {
// When uploading this sketch to the M4 core, it just goes to standby mode.
#if defined(ARDUINO_GENERIC_STM32H747_M4)
board.standByUntilWakeupEvent();
return;
#endif
charger.begin();
// Turn off the built-in LED
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// Turn on the blue LED to show that the board is still awake
pinMode(LEDB, OUTPUT);
digitalWrite(LEDB, LOW);
if(!board.begin()){
// If the board fails to initialize, it will blink the red LED
pinMode(LEDR, OUTPUT);
while (true){
digitalWrite(LEDR, LOW);
delay(1000);
digitalWrite(LEDR, HIGH);
delay(1000);
}
}
charger.setEnabled(false); // -> Please measure if it makes a difference
delay(10000); // -> Give time to take the measurement
// Takes 45s to get into shutdown mode
fuelgauge.setOperationMode(FuelGaugeOperationMode::shutdown);
// The LED should go off when the board goes to sleep
board.setAllPeripheralsPower(false);
board.enableWakeupFromRTC(0, 0, 60); // Go to standby for 60 seconds
board.standByUntilWakeupEvent();
}
void loop() {}