Skip to content

Commit 249760b

Browse files
fixed WakeFromRTC_C33
1 parent 6bbce31 commit 249760b

File tree

3 files changed

+95
-6
lines changed

3 files changed

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

Diff for: examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino

+11-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void blinkLed(int ledPin, int delayTime = 1000){
1414
}
1515

1616
void setup() {
17-
board.setAllPeripheralsPower(true); // TODO: Check if this is necessary
17+
1818

1919
pinMode(LEDR, OUTPUT); // Used to indicate errors
2020
digitalWrite(LEDR, HIGH); // Turn off the red LED
@@ -24,14 +24,17 @@ void setup() {
2424
digitalWrite(LED_BUILTIN, HIGH); // Turn off the built-in LED
2525
pinMode(LEDB, OUTPUT); // Used to indicate that the board is awake
2626

27-
// Turn on the blue LED to show that the board is still awake
28-
digitalWrite(LEDB, LOW);
27+
2928

3029
if(!board.begin()){
3130
while (true){
3231
blinkLed(LEDR);
3332
}
3433
}
34+
35+
board.setAllPeripheralsPower(true); // TODO: Check if this is necessary
36+
// Turn on the blue LED to show that the board is still awake
37+
digitalWrite(LEDB, LOW);
3538

3639
RTC.begin();
3740
if (!RTC.isRunning()) {
@@ -43,8 +46,11 @@ void setup() {
4346
}
4447

4548
board.enableWakeupFromRTC(0, 0, 10, [](){}, &RTC); // Sleep for 10 seconds
46-
// board.setAllPeripheralsPower(false);
49+
50+
delay(1000); // Let the user see that the board is ready to sleep
51+
52+
board.setAllPeripheralsPower(false);
4753
board.standByUntilWakeupEvent();
4854
}
4955

50-
void loop(){}
56+
void loop(){}

Diff for: src/Board.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,4 @@ bool Board::setReferenceVoltage(float voltage) {
319319

320320

321321
return UNKNOWN_VALUE;
322-
}
322+
}

0 commit comments

Comments
 (0)