1
1
/*
2
- Charger Demo
2
+ Charger Demo
3
3
4
- This sketch demonstrates how to write charging parameters,read charger state and monitor charging using the PowerManagement library:
5
- * In the setup() function, it sets the charging parameters
6
- * In the loop() functionit prints the battery's voltage, current, percentage and the charger's state allowing you to monitor charging.
4
+ This sketch demonstrates how to write charging parameters,read charger state and monitor charging using the PowerManagement library:
5
+ * In the setup() function, it sets the charging parameters
6
+ * In the loop() functionit prints the battery's voltage, current, percentage and the charger's state allowing you to monitor charging.
7
7
8
8
Requirements:
9
9
- Arduino Portenta C33, Arduino Portenta H7, Arduino Nicla Vision
10
10
- Arduino IDE
11
11
- PowerManagement library (installable from the Arduino Library Manager)
12
12
13
13
Usage:
14
- 1. Install the required library:
15
- - Open the Arduino IDE.
16
- - Go to "Sketch" -> "Include Library" -> "Manage Libraries..."
17
- - Search for "PowerManagement" and install it.
18
14
15
+ 1. Connect the Battery:
16
+
19
17
2. Upload the Sketch:
20
- - Open the provided sketch in the Arduino IDE.
21
- - Select your board type and port from the "Tools" menu.
22
- - Click the "Upload" button to upload the sketch to your board.
18
+ - Open the provided sketch in the Arduino IDE.
19
+ - Select your board type and port from the "Tools" menu.
20
+ - Click the "Upload" button to upload the sketch to your board.
23
21
24
22
3. Monitor Serial Output:
25
- - Open the Serial Monitor in the Arduino IDE.
26
- - Set the baud rate to 115200.
27
- - You will see the sketch continuously printing battery status and charger state.
23
+ - Open the Serial Monitor in the Arduino IDE.
24
+ - Set the baud rate to 115200.
25
+ - You will see the sketch continuously printing charger state information .
28
26
*/
29
27
#include " Arduino_PowerManagement.h"
30
28
@@ -75,34 +73,34 @@ String getChargerState(){
75
73
ChargingState status = charger.getState ();
76
74
77
75
switch (status) {
78
- case ChargingState::PreCharge :
76
+ case ChargingState::preCharge :
79
77
return " precharge" ;
80
78
break ;
81
- case ChargingState::FastChargeConstantCurrent :
79
+ case ChargingState::fastChargeConstantCurrent :
82
80
return " fast-charge constant current" ;
83
81
break ;
84
- case ChargingState::FastChargeConstantVoltage :
82
+ case ChargingState::fastChargeConstantVoltage :
85
83
return " fast-charge constant voltage" ;
86
84
break ;
87
- case ChargingState::EndOfCharge :
85
+ case ChargingState::endOfCharge :
88
86
return " end-of-charge" ;
89
87
break ;
90
- case ChargingState::Done :
88
+ case ChargingState::done :
91
89
return " done" ;
92
90
break ;
93
- case ChargingState::TimerFaultError :
91
+ case ChargingState::timerFaultError :
94
92
return " timer fault" ;
95
93
break ;
96
- case ChargingState::ThermistorSuspendError :
94
+ case ChargingState::thermistorSuspendError :
97
95
return " thermistor suspend" ;
98
96
break ;
99
- case ChargingState::ChargerDisabled :
97
+ case ChargingState::chargerDisabled :
100
98
return " off" ;
101
99
break ;
102
- case ChargingState::BatteryOvervoltageError :
100
+ case ChargingState::batteryOvervoltageError :
103
101
return " overvoltage condition" ;
104
102
break ;
105
- case ChargingState::ChargerBypassed :
103
+ case ChargingState::chargerBypassed :
106
104
return " disabled" ;
107
105
break ;
108
106
default :
@@ -112,7 +110,7 @@ String getChargerState(){
112
110
}
113
111
114
112
void loop (){
115
- static ChargingState status = ChargingState::None ;
113
+ static ChargingState status = ChargingState::none ;
116
114
117
115
if (status != charger.getState ()) {
118
116
status = charger.getState ();
0 commit comments