You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/01.mkr/01.boards/mkr-wifi-1010/tutorials/mkr-battery-app-note/mkr-battery-app-note.md
+35-19Lines changed: 35 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ software:
18
18
While you can run your MKR board from USB, you can make best use of it when your MKR board is able to operate independantly of your computer and a USB cable. This is particulary useful for many IoT applications, use of relays with high current draw and remote sensing. Batteries can help us in this regard and a special connector is included in the MKR products for this end. In this application note, we will take a closer look at the battery capabilities of the MKR boards.
19
19
20
20
### Goals
21
-
The goals of this project are:
21
+
The goals of this project are to:
22
22
- Understand what the terms `charging capacity` and `charging current`
23
23
- Distinguish between LiPo and Li-Ion batteries
24
24
- Learn how to identify connector polarity
@@ -33,7 +33,7 @@ The goals of this project are:
33
33
- Arduino IoT Cloud
34
34
35
35
### LiPo vs Fe vs Li-ion batteries
36
-
Several different chemistries of rechargeable batteries are commerically avalible. The two main types are Li-Po and Li-Ion. Lithium Ion batteries have been around for a longer time and are generally cheaper. Lithium Polymer batteries have a higher energy density, allowing you to run your board for longer with a similar sized battery.
36
+
Several different chemistries of rechargeable batteries are commerically avalible. The two main types are Li-Po and Li-Ion. Lithium Ion batteries have been around for a longer time and are generally cheaper. Lithium Polymer batteries have a higher energy density, allowing you to run your board longer with a similar sized battery.
37
37
You can see a comparison between these three in the table below.
38
38
39
39
| Battery Chemistry | Cost | Energy Density (mass) | Energy density (size) | Stability | Nominal voltage (single cell) |
@@ -46,9 +46,13 @@ You can see a comparison between these three in the table below.
46
46
Apart from being a single cell (3.7V), a key factor to selecting the correct battery is that the connector is compatible.
47
47
48
48
### Connector
49
+
<<<<<<< HEAD
49
50
You can connect a battery to the MKR WIFI 1010 via a 2-pin JST-PH female connector. The PH varient of JST connectors are identified by a pin-to-pin distance of 2 mm. Here are several examples of LiPo batteries with a 2-pin JST-PH connector. Each individual connector is made of one plastic housing and two metal crimp terminals. A crimping device may be required. Note that when looking from above (with the notch facing you), the red (positive) wire should be on your left.
50
51
51
52

53
+
=======
54
+
You can connect a battery to the MKR WIFI 1010 via a 2-pin JST-PH female connector. The PH varient of JST connectors are identified by a pin-to-pin distance of 2mm. Here are several examples of LiPo batteries with a 2-pin JST-PH connector. Each individual connector is made of one plastic housing and two metal crimp terminals. A crimping device may be required. Note that when looking from above (with the notch facing you), the red (positive) wire should be on your left.
55
+
>>>>>>> 3faaafb6a75ff2500f060d68e60406d769408434
52
56
53
57
### Protection circuit
54
58
A protection circuit cuts off the battery if overcurrent or under/over voltage is detected. This adds an additional layer of safety.
@@ -79,11 +83,11 @@ Continuing with the waterfall analogy, the volume of water passing through a wat
79
83
While the MKR boards do not provide a mechanism for identifying capacity, we can get a general idea of the current status by mapping the voltage to the capacity. A more precise value can be obtained with the help of a fuel gauge IC (Integrated Circuit), avaliable in the Portenta X8 and H7.
80
84
81
85
**Discharge rating**
82
-
When the battery is fully charged, or when it is near to discharge the discharge rate changes considerably. Yet, there is a region where the discharge rate constant (change in voltage over change in discharge capacity does not flunctuate). Within this region, the maximum current draw is defined as:
86
+
When the battery is fully charged or when it is near to discharge, the discharge rate changes considerably. Yet, there is a region where the discharge rate is constant (change in voltage over change in discharge capacity does not flunctuate). Within this region, the maximum current draw is defined as:
The discharge rating (C) is often provided in the datasheet of the battery. If the C rating of a battery is 1, then it can discharge the maximum current for one hour before running out. As a rule of thumb, higher discharge rates lead reduce the effective capacity and lifetime of the battery.
90
+
The discharge rating (C) is often provided in the datasheet of the battery. If the C rating of a battery is 1, then it can discharge the maximum current for one hour before running out. As a rule of thumb, higher discharge rates lead to the reduction of the effective capacity and lifetime of the battery.
87
91
88
92
## Multimeter battery measurements
89
93
@@ -98,9 +102,9 @@ You should notice that the voltage of VCC is about 3.3V, regardless of the batte
98
102
99
103
## Read battery values over Serial
100
104
101
-
We will go through the lines needed to create a Sketch to read the battery values over Serial and give a short descipriotn of what part does. At the end, the full code will be provided so you can copy and paste into your IDE and upload to your Arduino board.
105
+
We will go through the lines needed to create a Sketch to read the battery values over Serial and give a short description of what each part does. At the end, the full code will be provided so you can copy and paste it into your IDE and upload it to your Arduino board.
102
106
103
-
**1.** Open a new sketch in the Arduino IDE. We will create a sketch to read the ADC voltage that is sensed by the SAMD controller. As a first step, we will We will call the library to be included in the sketch.
107
+
**1.** Open a new sketch in the Arduino IDE. We will create a sketch to read the ADC voltage that is sensed by the SAMD controller. As a first step, we will call the library to be included in the sketch.
104
108
```arduino
105
109
#include <BQ24195.h>
106
110
```
@@ -145,7 +149,7 @@ void setup() {
145
149
analogReadResolution(12);
146
150
```
147
151
148
-
**7.** Now we can establish the SAMD21-BQ24195 connection over I2C and enable the boost mode. By default, the PMIC provides an output close to 3.3V to reduce the power loss over the 3.3V linear regulator. By enabling boost mode, we can access 5V on VCC pin.
152
+
**7.** Now we can establish the SAMD21-BQ24195 connection over I2C and enable the boost mode. By default, the PMIC provides an output close to 3.3V to reduce the power loss over the 3.3V linear regulator. By enabling boost mode, we can access 5V on the VCC pin.
149
153
```arduino
150
154
PMIC.begin();
151
155
PMIC.enableBoostMode();
@@ -157,7 +161,7 @@ void setup() {
157
161
PMIC.setChargeVoltage(batteryFullVoltage);
158
162
```
159
163
160
-
**9.** As a rule of thumb, we can now set the maximum charging current to half the battery capacity. With the configurations made for the battery, we can now enable the charging circuit
164
+
**9.** As a rule of thumb, we can now set the maximum charging current to half of the battery capacity. With the configurations made for the battery, we can now enable the charging circuit.
**12.** With the variables and setup function clearly defined, we will now specify the loop function. These commands will continuously run and provide information about the battery status to the Serial Monitor in the PC. First, we read the value of PB09 (specified internally as `ADC_BATTERY`). The valure represented by `rawADC` is a number between 0 to 4094, given that it has 12 bit resolution.
181
+
**12.** With the variables and setup function clearly defined, we will now specify the loop function. These commands will continuously run and provide information about the battery status to the Serial Monitor in the PC. First, we read the value of PB09 (specified internally as `ADC_BATTERY`). The value represented by `rawADC` is a number between 0 to 4094, given that it has 12 bit resolution.
178
182
179
183
```arduino
180
184
void loop()
@@ -183,18 +187,18 @@ void loop()
183
187
rawADC = analogRead(ADC_BATTERY);
184
188
```
185
189
186
-
**13.** In order to convert `rawADC` into a voltage reading (`voltADC`) we will divide `rawADC` by 4095 and then multiply by the analog reference voltage (3.3V).
190
+
**13.** In order to convert `rawADC` into a voltage reading (`voltADC`) we will divide `rawADC` by 4095 and then multiply it by the analog reference voltage (3.3V).
187
191
188
192
```arduino
189
193
voltADC = rawADC * (3.3/4095.0);
190
194
```
191
195
192
-
**14.** The `voltADC` variable gives us the voltage sensed directly on the PB09 pin. This voltage is passed through the voltage divider, so it is a fraction of the actually battery voltage. We can then calculate the equivilanet battery voltage as follows.
196
+
**14.** The `voltADC` variable gives us the voltage sensed directly on the PB09 pin. This voltage is passed through the voltage divider, so it is a fraction of the actual battery voltage. We can then calculate the equivilanet battery voltage as follows.
193
197
```arduino
194
198
voltBat = voltADC * (max_Source_voltage/3.3);
195
199
```
196
200
197
-
**15.** We can approximate the battery voltage to be propotional to the capacity level. Since the `map()` function does not work with float variables, we manually map the values.
201
+
**15.** We can approximate the battery voltage to be propotional to the capacity level. Since the `map()` function does not work with float variables, we will manually map the values.
@@ -212,7 +216,7 @@ int new_batt = (voltBat - batteryEmptyVoltage) * (100) / (batteryFullVoltage - b
212
216
Serial.println("%.");
213
217
```
214
218
215
-
**17.** Finally, we will add a half second delay at the end of the `loop()` function to allow variables to come slowly through the Serial Monitor.
219
+
**17.** Finally, we will add a half a second delay at the end of the `loop()` function to allow variables to come slowly through the Serial Monitor.
216
220
```arduino
217
221
delay(500);
218
222
}
@@ -337,19 +341,19 @@ void loop()
337
341
338
342
Since we had connected the board via USB, the board is charging. In order to better realise the status of the battery in a more realistic environment, we will use the Arduino IoT Cloud. We will use three different dashboard elements to display the data.
339
343
340
-
**1.** In order to evaluate the performance of the device in a real world setting, we need to be able to test it remotely. To do so, we will use the Arduino Cloud to transfer data. The Arduino IoT Cloud makes it easy ton create IoT solutions. In the free plan, you have to connect the board to the cable, but in the money money tier, you can program the board wirelessley.
344
+
**1.** In order to evaluate the performance of the device in a real world setting, we need to be able to test it remotely. To do so, we will use the Arduino Cloud to transfer data. The Arduino IoT Cloud makes it easy to create IoT solutions. In the free plan, you have to connect the board to the cable, but in a subscription plan, you can program the board wirelessly.
341
345
342
346
**2.** First, we will create a simple digital output to display the value of the ADC. Go to https://create.arduino.cc/iot/dashboards and click on **Create** to make a new dashboard and give it a name. Here, we are calling our dashboard MKR Remote Battery Status.
343
347
344
-
**3.** Click on the Add button and in the list select the Value widget. You can also search by entering the name in the box. Click it in order to add it.
348
+
**3.** Click on the Add button and in the list and select the Value widget. You can also search by entering the name in the box. Click it in order to add it.
345
349
346
350
**4.** Name the widget raw ADC value. Then click on **Done**.
347
351
348
-
**5.** In order for the ADC value to be shown on the widget, we need to first configure the sketch to create a linked variable. A linked variable is a variable that is sent by your Arduino device to the cloud.
352
+
**5.** In order for the ADC value to be shown on the widget, we first need to configure the sketch to create a linked variable. A linked variable is a variable that is sent by your Arduino device to the cloud.
349
353
350
354
**6.** Go to the Devices tab and click on Add. Then Select Setup an Arduino device. Make sure your board is connected via a USB cable. If you have not done already, you may be requested to install the Arduino Create Adgent. Install it if needed.
351
355
352
-
**7.** After you have setup the device, go the the things tab. Click on the device you linked and add the sketch as well as the rawADC varaible.
356
+
**7.** After you have setup the device, go the the things tab. Click on the device you linked and add the sketch as well as the rawADC variable.
353
357
354
358
**8.** Upload the sketch
355
359
@@ -365,6 +369,18 @@ Since we had connected the board via USB, the board is charging. In order to bet
365
369
366
370
**13.** You now can view the battery status through a wide range of widgets.
367
371
372
+
<<<<<<< HEAD
373
+
=======
374
+
## Extract plots
375
+
376
+
**1.** In the Dashboard, click on the download historical data button to the right of your screen.
377
+
378
+
**2.** Click
379
+
380
+
**2.** Plot with Google Sheets
381
+
382
+
after i the usb port, the battery is disconnected as well? I have to reconnect battery for it to work? How are you supposed to charge it in a practical setting
383
+
>>>>>>> 3faaafb6a75ff2500f060d68e60406d769408434
368
384
369
385
### Troubleshoot
370
386
- You cannot upload OTA with
@@ -373,7 +389,7 @@ Since we had connected the board via USB, the board is charging. In order to bet
373
389
374
390
## Further Ideas
375
391
376
-
- Try disableing the charging circuit with `code()` in order to read the voltage via serial without a WiFi connections
392
+
- Try disabling the charging circuit with `code()` in order to read the voltage via serial without a WiFi connections
377
393
- Save the values from the IoT cloud, and plot the change in voltage over time. What shape does the discharge function have?
378
394
- Try experimenting with different battery capacities, and see how long it can power your application.
379
395
-## Extract plots
@@ -388,4 +404,4 @@ after i the usb port, the battery is disconnected as well? I have to reconnect b
388
404
389
405
390
406
## References
391
-
battery charge level is tied to the voltage. don't need a table, but have explanation. depending on a battery used. from 4.2 to 4.0 and from 3.5 to 3.3 very little energy is released.
407
+
battery charge level is tied to the voltage. don't need a table, but have explanation. depending on a battery used. from 4.2 to 4.0 and from 3.5 to 3.3 very little energy is released.
0 commit comments