Skip to content

Commit 8b466ba

Browse files
committed
Add images
1 parent 284ff62 commit 8b466ba

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

content/hardware/01.mkr/01.boards/mkr-wifi-1010/tutorials/mkr-battery-app-note/mkr-battery-app-note.md

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ software:
1818
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.
1919

2020
### Goals
21-
The goals of this project are:
21+
The goals of this project are to:
2222
- Understand what the terms `charging capacity` and `charging current`
2323
- Distinguish between LiPo and Li-Ion batteries
2424
- Learn how to identify connector polarity
@@ -33,7 +33,7 @@ The goals of this project are:
3333
- Arduino IoT Cloud
3434

3535
### 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.
3737
You can see a comparison between these three in the table below.
3838

3939
| 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.
4646
Apart from being a single cell (3.7V), a key factor to selecting the correct battery is that the connector is compatible.
4747

4848
### Connector
49+
<<<<<<< HEAD
4950
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.
5051

5152
![JST-PH connector connected to the MKR WiFi 1010. Note that the positive terminal (red wire) is to the left, towards the PMIC](assets/battery-in-mkr.png)
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
5256
5357
### Protection circuit
5458
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
7983
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.
8084

8185
**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:
8387

8488
$$\text{maximum current draw } = \text{ battery capacity } \times \text{ discharge rating} $$
8589

86-
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.
8791

8892
## Multimeter battery measurements
8993

@@ -98,9 +102,9 @@ You should notice that the voltage of VCC is about 3.3V, regardless of the batte
98102

99103
## Read battery values over Serial
100104

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.
102106

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.
104108
```arduino
105109
#include <BQ24195.h>
106110
```
@@ -145,7 +149,7 @@ void setup() {
145149
analogReadResolution(12);
146150
```
147151

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.
149153
```arduino
150154
PMIC.begin();
151155
PMIC.enableBoostMode();
@@ -157,7 +161,7 @@ void setup() {
157161
PMIC.setChargeVoltage(batteryFullVoltage);
158162
```
159163

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.
161165
```arduino
162166
PMIC.setChargeCurrent(batteryCapacity/2);
163167
@@ -174,7 +178,7 @@ void setup() {
174178

175179
![Serial & BQ24196 Setup](assets/serial-BQ24195-setup.png)
176180

177-
**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.
178182

179183
```arduino
180184
void loop()
@@ -183,18 +187,18 @@ void loop()
183187
rawADC = analogRead(ADC_BATTERY);
184188
```
185189

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).
187191

188192
```arduino
189193
voltADC = rawADC * (3.3/4095.0);
190194
```
191195

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.
193197
```arduino
194198
voltBat = voltADC * (max_Source_voltage/3.3);
195199
```
196200

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.
198202
```arduino
199203
int new_batt = (voltBat - batteryEmptyVoltage) * (100) / (batteryFullVoltage - batteryEmptyVoltage);
200204
```
@@ -212,7 +216,7 @@ int new_batt = (voltBat - batteryEmptyVoltage) * (100) / (batteryFullVoltage - b
212216
Serial.println("%.");
213217
```
214218

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.
216220
```arduino
217221
delay(500);
218222
}
@@ -337,19 +341,19 @@ void loop()
337341

338342
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.
339343

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.
341345

342346
**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.
343347

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.
345349

346350
**4.** Name the widget raw ADC value. Then click on **Done**.
347351

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.
349353

350354
**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.
351355

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.
353357

354358
**8.** Upload the sketch
355359

@@ -365,6 +369,18 @@ Since we had connected the board via USB, the board is charging. In order to bet
365369

366370
**13.** You now can view the battery status through a wide range of widgets.
367371

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
368384
369385
### Troubleshoot
370386
- 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
373389

374390
## Further Ideas
375391

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
377393
- Save the values from the IoT cloud, and plot the change in voltage over time. What shape does the discharge function have?
378394
- Try experimenting with different battery capacities, and see how long it can power your application.
379395
- ## Extract plots
@@ -388,4 +404,4 @@ after i the usb port, the battery is disconnected as well? I have to reconnect b
388404

389405

390406
## 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

Comments
 (0)