Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: battery-gauge-bq35100
Revision 1:390b13287bb7, committed 2017-11-10
- Comitter:
- RobMeades
- Date:
- Fri Nov 10 17:31:58 2017 +0000
- Parent:
- 0:921ceae3cd78
- Commit message:
- Example to go with latest BQ35100 driver code.
Changed in this revision
| battery-gauge-bq35100.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 921ceae3cd78 -r 390b13287bb7 battery-gauge-bq35100.lib --- a/battery-gauge-bq35100.lib Mon Jul 03 16:27:47 2017 +0000 +++ b/battery-gauge-bq35100.lib Fri Nov 10 17:31:58 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ublox/code/battery-gauge-bq35100/#cec745c014b7 +https://developer.mbed.org/teams/ublox/code/battery-gauge-bq35100/#4c699a813451
diff -r 921ceae3cd78 -r 390b13287bb7 main.cpp
--- a/main.cpp Mon Jul 03 16:27:47 2017 +0000
+++ b/main.cpp Fri Nov 10 17:31:58 2017 +0000
@@ -34,11 +34,67 @@
I2C i2C(I2C_SDA, I2C_SCL);
BatteryGaugeBq35100 gauge;
int32_t reading;
+ uint32_t capacity;
bool stop = false;
printf ("Starting up...\n");
- if (gauge.init(&i2C)) {
- printf ("BQ35100 battery gauge chip is initialised.\n");
+ if (gauge.init(&i2C) && gauge.setDesignCapacity(6500)) {
+ printf ("BQ35100 battery gauge chip is initialised assuming a 6500 mAh battery.\n");
+ while (!stop) {
+ if (!gauge.isGaugeEnabled()) {
+ gauge.enableGauge();
+ }
+ if (gauge.isGaugeEnabled()) {
+ // All is good, gauging is enabled, take a few readings
+ ledGreen = 0;
+ ledRed = 1;
+
+ if (gauge.getRemainingPercentage(&reading)) {
+ printf("Remaining battery percentage: %d%%.\n", (int) reading);
+ } else {
+ ledGreen = 1;
+ ledRed = 0;
+ wait_ms(1000);
+ }
+
+ if (gauge.getRemainingCapacity(&capacity)) {
+ printf("Remaining battery capacity: %.3f Ah.\n", ((float) capacity) / 1000);
+ } else {
+ ledGreen = 1;
+ ledRed = 0;
+ wait_ms(1000);
+ }
+
+ if (gauge.getVoltage(&reading)) {
+ printf("Battery voltage: %.3f V.\n", ((float) reading) / 1000);
+ } else {
+ ledGreen = 1;
+ ledRed = 0;
+ wait_ms(1000);
+ }
+
+ if (gauge.getCurrent(&reading)) {
+ printf("Current drawn from battery: %.3f A.\n", ((float) reading) / 1000);
+ } else {
+ ledGreen = 1;
+ ledRed = 0;
+ wait_ms(1000);
+ }
+
+ if (gauge.getTemperature(&reading)) {
+ printf("BQ27441 chip temperature: %d C.\n", (int) reading);
+ } else {
+ ledGreen = 1;
+ ledRed = 0;
+ wait_ms(1000);
+ }
+
+ } else {
+ printf("Battery gauging could not be enabled.\n");
+ stop = true;
+ }
+ wait_ms(5000);
+ }
}
ledGreen = 1;