-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
2,109 additions
and
1 deletion.
There are no files selected for viewing
Submodule SparkFun_BQ27441
deleted from
65fcd5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
idf_component_register(SRCS "src/SparkFunBQ27441.cpp" | ||
INCLUDE_DIRS "src/." | ||
REQUIRES "arduino" | ||
) | ||
|
||
project(SparkFun_BQ27441) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
SparkFun License Information | ||
============================ | ||
|
||
SparkFun uses two different licenses for our files - one for hardware and one for code. | ||
|
||
Hardware | ||
--------- | ||
|
||
**SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).** | ||
|
||
Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode). | ||
|
||
You are free to: | ||
|
||
Share — copy and redistribute the material in any medium or format | ||
Adapt — remix, transform, and build upon the material | ||
for any purpose, even commercially. | ||
The licensor cannot revoke these freedoms as long as you follow the license terms. | ||
Under the following terms: | ||
|
||
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. | ||
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. | ||
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. | ||
Notices: | ||
|
||
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation. | ||
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material. | ||
|
||
|
||
Code | ||
-------- | ||
|
||
**SparkFun code, firmware, and software is released under the [MIT License](http://opensource.org/licenses/MIT).** | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 SparkFun Electronics, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
SparkFun BQ27441-G1A LiPo Fuel Gauge Arduino Library | ||
======================================== | ||
|
||
[![SparkFun Battery Babysitter](https://cdn.sparkfun.com/assets/parts/1/1/3/3/1/13777-01.jpg)](https://www.sparkfun.com/products/13777) | ||
|
||
[*SparkFun Battery Babysitter (featuring the BQ27441-G1A LiPo Fuel Gauge) (PRT-13777)*](https://www.sparkfun.com/products/13777) | ||
|
||
Texas Instrument's [BQ27441-G1A](http://www.ti.com/product/BQ27441-G1) is a self-calibrating, I2C-based fuel gauge for lithium polymer (LiPo) batteries -- it measures your battery's voltage to estimate its charge percentage and remaining capacity. The chip is also hooked up to a current-sensing resistor, which allows it to measure current and power! The fuel gauge makes up half of the [SparkFun Battery Babysitter](https://www.sparkfun.com/products/13777). | ||
|
||
This Arduino library abstracts away all of the low-level I2C communication, so you can easily initialize the fuel gauge then read voltage, state-of-charge, current, power, and capacity. It also implements all of the chip's low-battery, and SoC-change alerts on the GPOUT pin. | ||
|
||
Thanks to: | ||
|
||
* [keton](https://github.com/keton) for adding extended config methods and an example showing how to use them | ||
|
||
Repository Contents | ||
------------------- | ||
|
||
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE. | ||
* **/src** - Source files for the library (.cpp, .h). | ||
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE. | ||
* **library.properties** - General library properties for the Arduino package manager. | ||
|
||
Documentation | ||
-------------- | ||
|
||
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. | ||
* **[Product Repository](https://github.com/sparkfun/Battery_Babysitter)** - Main repository (including hardware files) for the SparkFun Battery Babysitter (which features the BQ27441-G1A ). | ||
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/battery-babysitter-hookup-guide)** - Basic hookup guide for the SparkFun Battery Babysitter. | ||
|
||
Products that use this Library | ||
--------------------------------- | ||
|
||
* [SparkFun Battery Babysitter - PRT-13777](https://www.sparkfun.com/products/13777)- The Battery Babysitter is an all-in-one battery-charger and monitor, featuring the BQ27441-G1A and BQ24075 charger. | ||
|
||
Version History | ||
--------------- | ||
|
||
* [1.0.0](https://github.com/sparkfun/SparkFun_BQ27441_Arduino_Library/releases/tag/V_1.0.0) - Initial release of the BQ27441 Arduino Library. | ||
|
||
License Information | ||
------------------- | ||
|
||
This product is _**open source**_! | ||
|
||
Please review the LICENSE.md file for license information. | ||
|
||
If you have any questions or concerns on licensing, please contact techsupport@sparkfun.com. | ||
|
||
Distributed as-is; no warranty is given. | ||
|
||
- Your friends at SparkFun. | ||
|
||
_<COLLABORATION CREDIT>_ |
81 changes: 81 additions & 0 deletions
81
components/SparkFun_BQ27441/examples/BQ27441_Basic/BQ27441_Basic.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/****************************************************************************** | ||
BQ27441_Basic | ||
BQ27441 Library Basic Example | ||
Jim Lindblom @ SparkFun Electronics | ||
May 9, 2016 | ||
https://github.com/sparkfun/SparkFun_BQ27441_Arduino_Library | ||
Demonstrates how to set up the BQ27441 and read state-of-charge (soc), | ||
battery voltage, average current, remaining capacity, average power, and | ||
state-of-health (soh). | ||
After uploading, open up the serial monitor to 115200 baud to view your | ||
battery's stats. | ||
Hardware Resources: | ||
- Arduino Development Board | ||
- SparkFun Battery Babysitter | ||
Development environment specifics: | ||
Arduino 1.6.7 | ||
SparkFun Battery Babysitter v1.0 | ||
Arduino Uno (any 'duino should do) | ||
******************************************************************************/ | ||
#include <SparkFunBQ27441.h> | ||
|
||
// Set BATTERY_CAPACITY to the design capacity of your battery. | ||
const unsigned int BATTERY_CAPACITY = 850; // e.g. 850mAh battery | ||
|
||
void setupBQ27441(void) | ||
{ | ||
// Use lipo.begin() to initialize the BQ27441-G1A and confirm that it's | ||
// connected and communicating. | ||
if (!lipo.begin()) // begin() will return true if communication is successful | ||
{ | ||
// If communication fails, print an error message and loop forever. | ||
Serial.println("Error: Unable to communicate with BQ27441."); | ||
Serial.println(" Check wiring and try again."); | ||
Serial.println(" (Battery must be plugged into Battery Babysitter!)"); | ||
while (1) ; | ||
} | ||
Serial.println("Connected to BQ27441!"); | ||
|
||
// Uset lipo.setCapacity(BATTERY_CAPACITY) to set the design capacity | ||
// of your battery. | ||
lipo.setCapacity(BATTERY_CAPACITY); | ||
} | ||
|
||
void printBatteryStats() | ||
{ | ||
// Read battery stats from the BQ27441-G1A | ||
unsigned int soc = lipo.soc(); // Read state-of-charge (%) | ||
unsigned int volts = lipo.voltage(); // Read battery voltage (mV) | ||
int current = lipo.current(AVG); // Read average current (mA) | ||
unsigned int fullCapacity = lipo.capacity(FULL); // Read full capacity (mAh) | ||
unsigned int capacity = lipo.capacity(REMAIN); // Read remaining capacity (mAh) | ||
int power = lipo.power(); // Read average power draw (mW) | ||
int health = lipo.soh(); // Read state-of-health (%) | ||
|
||
// Now print out those values: | ||
String toPrint = String(soc) + "% | "; | ||
toPrint += String(volts) + " mV | "; | ||
toPrint += String(current) + " mA | "; | ||
toPrint += String(capacity) + " / "; | ||
toPrint += String(fullCapacity) + " mAh | "; | ||
toPrint += String(power) + " mW | "; | ||
toPrint += String(health) + "%"; | ||
|
||
Serial.println(toPrint); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
setupBQ27441(); | ||
} | ||
|
||
void loop() | ||
{ | ||
printBatteryStats(); | ||
delay(1000); | ||
} |
103 changes: 103 additions & 0 deletions
103
...arkFun_BQ27441/examples/BQ27441_Extended_Configuration/BQ27441_Extended_Configuration.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <SparkFunBQ27441.h> | ||
|
||
// Set BATTERY_CAPACITY to the design capacity of your battery in mAh. | ||
const uint16_t BATTERY_CAPACITY = 2850; | ||
|
||
//lowest operational voltage in mV | ||
const uint16_t TERMINATE_VOLTAGE = 3000; | ||
|
||
//current at which charger stops charging battery in mA | ||
//in case of Sparkfun Battery Babysitter board: | ||
// 100mA charge current --> 12mA | ||
// 500mA charge current --> 60mA | ||
const uint16_t TAPER_CURRENT = 60; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
if (!lipo.begin()) // begin() will return true if communication is successful | ||
{ | ||
// If communication fails, print an error message and loop forever. | ||
Serial.println("Error: Unable to communicate with BQ27441."); | ||
Serial.println(" Check wiring and try again."); | ||
Serial.println(" (Battery must be plugged into Battery Babysitter!)"); | ||
while (1) | ||
; | ||
} | ||
Serial.println("Connected to BQ27441!"); | ||
|
||
if (lipo.itporFlag()) //write config parameters only if needed | ||
{ | ||
Serial.println("Writing gague config"); | ||
|
||
lipo.enterConfig(); // To configure the values below, you must be in config mode | ||
lipo.setCapacity(BATTERY_CAPACITY); // Set the battery capacity | ||
|
||
/* | ||
Design Energy should be set to be Design Capacity × 3.7 if using the bq27441-G1A or Design | ||
Capacity × 3.8 if using the bq27441-G1B | ||
*/ | ||
lipo.setDesignEnergy(BATTERY_CAPACITY * 3.7f); | ||
|
||
/* | ||
Terminate Voltage should be set to the minimum operating voltage of your system. This is the target | ||
where the gauge typically reports 0% capacity | ||
*/ | ||
lipo.setTerminateVoltage(TERMINATE_VOLTAGE); | ||
|
||
/* | ||
Taper Rate = Design Capacity / (0.1 * Taper Current) | ||
*/ | ||
lipo.setTaperRate(10 * BATTERY_CAPACITY / TAPER_CURRENT); | ||
|
||
lipo.exitConfig(); // Exit config mode to save changes | ||
} | ||
else | ||
{ | ||
Serial.println("Using existing gague config"); | ||
} | ||
} | ||
|
||
void printBatteryStats() | ||
{ | ||
// Read battery stats from the BQ27441-G1A | ||
unsigned int soc = lipo.soc(); // Read state-of-charge (%) | ||
unsigned int volts = lipo.voltage(); // Read battery voltage (mV) | ||
int current = lipo.current(AVG); // Read average current (mA) | ||
unsigned int fullCapacity = lipo.capacity(FULL); // Read full capacity (mAh) | ||
unsigned int capacity = lipo.capacity(REMAIN); // Read remaining capacity (mAh) | ||
int power = lipo.power(); // Read average power draw (mW) | ||
int health = lipo.soh(); // Read state-of-health (%) | ||
|
||
// Assemble a string to print | ||
String toPrint = "[" + String(millis() / 1000) + "] "; | ||
toPrint += String(soc) + "% | "; | ||
toPrint += String(volts) + " mV | "; | ||
toPrint += String(current) + " mA | "; | ||
toPrint += String(capacity) + " / "; | ||
toPrint += String(fullCapacity) + " mAh | "; | ||
toPrint += String(power) + " mW | "; | ||
toPrint += String(health) + "%"; | ||
|
||
//fast charging allowed | ||
if (lipo.chgFlag()) | ||
toPrint += " CHG"; | ||
|
||
//full charge detected | ||
if (lipo.fcFlag()) | ||
toPrint += " FC"; | ||
|
||
//battery is discharging | ||
if (lipo.dsgFlag()) | ||
toPrint += " DSG"; | ||
|
||
// Print the string | ||
Serial.println(toPrint); | ||
} | ||
|
||
void loop() | ||
{ | ||
printBatteryStats(); | ||
delay(1000); | ||
} |
Oops, something went wrong.