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 () {}
0 commit comments