forked from adafruit/Adafruit_nRF52_Arduino
-
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.
Add MAX1704x fuel gauge library and examples as of 6ea1765a513dde65e4…
…33dde12a70fced73b65fed Sparkfun's upstream is https://github.com/sparkfun/SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library and the library is available under the MIT License
- Loading branch information
Showing
11 changed files
with
1,965 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
libraries/SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library/.gitattributes
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,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
21 changes: 21 additions & 0 deletions
21
libraries/SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library/LICENSE
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 SparkFun Electronics | ||
|
||
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. |
59 changes: 59 additions & 0 deletions
59
libraries/SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library/README.md
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,59 @@ | ||
SparkFun MAX1704x Fuel Gauge Arduino Library | ||
======================================== | ||
|
||
<table class="table table-hover table-striped table-bordered"> | ||
<tr align="center"> | ||
<td><a href="https://www.sparkfun.com/products/20680"><img src="https://cdn.sparkfun.com//assets/parts/2/0/5/1/7/20680-_TOL_SparkFun_LiPo_Fuel_Gauge-_01.jpg" alt="SparkFun LiPo Fuel Gauge - MAX17043 "></a></td> | ||
<td><a href="https://www.sparkfun.com/products/17715"><img src="https://cdn.sparkfun.com//assets/parts/1/6/8/2/0/17715-Qwiic_Fuel_Gauge-01.jpg" alt="SparkX Qwiic Fuel Gauge - MAX17048"></a></td> | ||
</tr> | ||
<tr align="center"> | ||
<td><i>SparkFun LiPo Fuel Gauge - MAX17043 [<a href="https://www.sparkfun.com/products/20680">TOL-20680</a>]</i></td> | ||
<td><i>SparkX Qwiic Fuel Gauge - MAX17048 [<a href="https://www.sparkfun.com/products/17715">SPX-17715</a>]</i></td> | ||
</tr> | ||
</table> | ||
|
||
|
||
The MAX17043/MAX17044 are ultra-compact, low-cost, | ||
host-side fuel-gauge systems for lithium-ion (Li+) batteries | ||
in handheld and portable equipment. The MAX17043 | ||
is configured to operate with a single lithium cell and the | ||
MAX17044 is configured for a dual-cell 2S pack. | ||
|
||
The MAX17048/MAX17049 ICs are tiny, micropower current | ||
fuel gauges for lithium-ion (Li+) batteries in handheld | ||
and portable equipment. The MAX17048 operates with | ||
a single lithium cell and the MAX17049 with two lithium | ||
cells in series. | ||
|
||
This Arduino library provides support for all four devices. | ||
|
||
## Thanks | ||
|
||
Parts of this library were inspired by [Daniel Porrey's max1704x library](https://github.com/porrey/max1704x). Thank you Daniel. | ||
|
||
## 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. | ||
|
||
## Products That Use This Library | ||
|
||
- [Qduino Mini - Arduino Dev Board (DEV-13614)](https://www.sparkfun.com/products/13614) - Built in MAX17048 | ||
- [SparkFun IoT RedBoard - ESP32 Development Board (WRL-19177)](https://www.sparkfun.com/products/19177) - Built in MAX17048 | ||
- [SparkX Qwiic Fuel Gauge - MAX17048 (SPX-17715) ](https://www.sparkfun.com/products/17715) | ||
- [SparkFun LiPo Fuel Gauge - MAX17043 (TOL-20680)](https://www.sparkfun.com/products/20680) | ||
- [SparkFun LiPo Fuel Gauge - MAX17043 (TOL-10617)](https://www.sparkfun.com/products/10617) | ||
|
||
|
||
## Documentation | ||
|
||
- **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. | ||
- **[LiPo Fuel Gauge (MAX1704X) Hookup Guide](https://learn.sparkfun.com/tutorials/lipo-fuel-gauge-max1704x-hookup-guide)** - Basic hookup guide for the MAX1704X (i.e. MAX1703 and MAX17048). | ||
|
||
|
||
|
||
## License Information | ||
|
||
Please see [LICENSE.md](./LICENSE.md) for the license information. |
88 changes: 88 additions & 0 deletions
88
...SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library/examples/Example1_Simple/Example1_Simple.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,88 @@ | ||
/****************************************************************************** | ||
Example1_Simple | ||
By: Paul Clark | ||
Date: October 23rd 2020 | ||
Based extensively on: | ||
MAX17043_Simple_Serial.cpp | ||
SparkFun MAX17043 Example Code | ||
Jim Lindblom @ SparkFun Electronics | ||
Original Creation Date: June 22, 2015 | ||
This file demonstrates the simple API of the SparkFun MAX17043 Arduino library. | ||
This example will print the gauge's voltage and state-of-charge (SOC) readings | ||
to Serial (115200 baud) | ||
This code is released under the MIT license. | ||
Distributed as-is; no warranty is given. | ||
******************************************************************************/ | ||
|
||
#include <Wire.h> // Needed for I2C | ||
|
||
#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library | ||
|
||
SFE_MAX1704X lipo; // Defaults to the MAX17043 | ||
|
||
//SFE_MAX1704X lipo(MAX1704X_MAX17043); // Create a MAX17043 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17044); // Create a MAX17044 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17048); // Create a MAX17048 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17049); // Create a MAX17049 | ||
|
||
double voltage = 0; // Variable to keep track of LiPo voltage | ||
double soc = 0; // Variable to keep track of LiPo state-of-charge (SOC) | ||
bool alert; // Variable to keep track of whether alert has been triggered | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); // Start serial, to output debug data | ||
while (!Serial) | ||
; //Wait for user to open terminal | ||
Serial.println(F("MAX17043 Example")); | ||
|
||
Wire.begin(); | ||
|
||
lipo.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial | ||
|
||
// Set up the MAX17043 LiPo fuel gauge: | ||
if (lipo.begin() == false) // Connect to the MAX17043 using the default wire port | ||
{ | ||
Serial.println(F("MAX17043 not detected. Please check wiring. Freezing.")); | ||
while (1) | ||
; | ||
} | ||
|
||
// Quick start restarts the MAX17043 in hopes of getting a more accurate | ||
// guess for the SOC. | ||
lipo.quickStart(); | ||
|
||
// We can set an interrupt to alert when the battery SoC gets too low. | ||
// We can alert at anywhere between 1% - 32%: | ||
lipo.setThreshold(20); // Set alert threshold to 20%. | ||
} | ||
|
||
void loop() | ||
{ | ||
// lipo.getVoltage() returns a voltage value (e.g. 3.93) | ||
voltage = lipo.getVoltage(); | ||
// lipo.getSOC() returns the estimated state of charge (e.g. 79%) | ||
soc = lipo.getSOC(); | ||
// lipo.getAlert() returns a 0 or 1 (0=alert not triggered) | ||
alert = lipo.getAlert(); | ||
|
||
// Print the variables: | ||
Serial.print("Voltage: "); | ||
Serial.print(voltage); // Print the battery voltage | ||
Serial.println(" V"); | ||
|
||
Serial.print("Percentage: "); | ||
Serial.print(soc); // Print the battery state of charge | ||
Serial.println(" %"); | ||
|
||
Serial.print("Alert: "); | ||
Serial.println(alert); | ||
Serial.println(); | ||
|
||
delay(500); | ||
} |
92 changes: 92 additions & 0 deletions
92
...x_Fuel_Gauge_Arduino_Library/examples/Example2_AlternatePorts/Example2_AlternatePorts.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,92 @@ | ||
/****************************************************************************** | ||
Example2_AlternatePorts | ||
By: Paul Clark | ||
Date: October 23rd 2020 | ||
Based extensively on: | ||
MAX17043_Simple_Serial.cpp | ||
SparkFun MAX17043 Example Code | ||
Jim Lindblom @ SparkFun Electronics | ||
Original Creation Date: June 22, 2015 | ||
This file demonstrates the simple API of the SparkFun MAX17043 Arduino library using non-standard Wire and Serial ports. | ||
This example will print the gauge's voltage and state-of-charge (SOC) readings | ||
to serial (115200 baud) | ||
This code is released under the MIT license. | ||
Distributed as-is; no warranty is given. | ||
******************************************************************************/ | ||
|
||
#include <Wire.h> // Needed for I2C | ||
|
||
#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library | ||
|
||
SFE_MAX1704X lipo; // Defaults to the MAX17043 | ||
|
||
//SFE_MAX1704X lipo(MAX1704X_MAX17043); // Create a MAX17043 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17044); // Create a MAX17044 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17048); // Create a MAX17048 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17049); // Create a MAX17049 | ||
|
||
// Define our non-standard ports: | ||
#define mySerial Serial1 | ||
TwoWire myWire(0); | ||
|
||
double voltage = 0; // Variable to keep track of LiPo voltage | ||
double soc = 0; // Variable to keep track of LiPo state-of-charge (SOC) | ||
bool alert; // Variable to keep track of whether alert has been triggered | ||
|
||
void setup() | ||
{ | ||
mySerial.begin(115200); // Start serial, to output debug data | ||
while (!mySerial) | ||
; //Wait for user to open terminal | ||
mySerial.println(F("MAX17043 Example")); | ||
|
||
myWire.begin(); | ||
|
||
lipo.enableDebugging(mySerial); // Uncomment this line to enable helpful debug messages on non-standard serial | ||
|
||
// Set up the MAX17043 LiPo fuel gauge: | ||
if (lipo.begin(myWire) == false) // Connect to the MAX17043 using non-standard wire port | ||
{ | ||
mySerial.println(F("MAX17043 not detected. Please check wiring. Freezing.")); | ||
while (1) | ||
; | ||
} | ||
|
||
// Quick start restarts the MAX17043 in hopes of getting a more accurate | ||
// guess for the SOC. | ||
lipo.quickStart(); | ||
|
||
// We can set an interrupt to alert when the battery SoC gets too low. | ||
// We can alert at anywhere between 1% - 32%: | ||
lipo.setThreshold(20); // Set alert threshold to 20%. | ||
} | ||
|
||
void loop() | ||
{ | ||
// lipo.getVoltage() returns a voltage value (e.g. 3.93) | ||
voltage = lipo.getVoltage(); | ||
// lipo.getSOC() returns the estimated state of charge (e.g. 79%) | ||
soc = lipo.getSOC(); | ||
// lipo.getAlert() returns a 0 or 1 (0=alert not triggered) | ||
alert = lipo.getAlert(); | ||
|
||
// Print the variables: | ||
mySerial.print("Voltage: "); | ||
mySerial.print(voltage); // Print the battery voltage | ||
mySerial.println(" V"); | ||
|
||
mySerial.print("Percentage: "); | ||
mySerial.print(soc); // Print the battery state of charge | ||
mySerial.println(" %"); | ||
|
||
mySerial.print("Alert: "); | ||
mySerial.println(alert); | ||
mySerial.println(); | ||
|
||
delay(500); | ||
} |
87 changes: 87 additions & 0 deletions
87
...kFun_MAX1704x_Fuel_Gauge_Arduino_Library/examples/Example3_MAX17044/Example3_MAX17044.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,87 @@ | ||
/****************************************************************************** | ||
Example3_MAX17044 | ||
By: Paul Clark | ||
Date: October 23rd 2020 | ||
Based extensively on: | ||
MAX17043_Simple_Serial.cpp | ||
SparkFun MAX17043 Example Code | ||
Jim Lindblom @ SparkFun Electronics | ||
Original Creation Date: June 22, 2015 | ||
This file demonstrates how to talk to the MAX17044 using the SparkFun MAX17043 Arduino library. | ||
This example will print the gauge's voltage and state-of-charge (SOC) readings | ||
to Serial (115200 baud) | ||
This code is released under the MIT license. | ||
Distributed as-is; no warranty is given. | ||
******************************************************************************/ | ||
|
||
#include <Wire.h> // Needed for I2C | ||
|
||
#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library | ||
|
||
SFE_MAX1704X lipo(MAX1704X_MAX17044); // Create a MAX17044 | ||
|
||
//SFE_MAX1704X lipo(MAX1704X_MAX17043); // Create a MAX17043 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17048); // Create a MAX17048 | ||
//SFE_MAX1704X lipo(MAX1704X_MAX17049); // Create a MAX17049 | ||
|
||
double voltage = 0; // Variable to keep track of LiPo voltage | ||
double soc = 0; // Variable to keep track of LiPo state-of-charge (SOC) | ||
bool alert; // Variable to keep track of whether alert has been triggered | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); // Start serial, to output debug data | ||
while (!Serial) | ||
; //Wait for user to open terminal | ||
Serial.println(F("MAX17044 Example")); | ||
|
||
Wire.begin(); | ||
|
||
lipo.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial | ||
|
||
// Set up the MAX17044 LiPo fuel gauge: | ||
if (lipo.begin() == false) // Connect to the MAX17044 using the default wire port | ||
{ | ||
Serial.println(F("MAX17044 not detected. Please check wiring. Freezing.")); | ||
while (1) | ||
; | ||
} | ||
|
||
// Quick start restarts the MAX17044 in hopes of getting a more accurate | ||
// guess for the SOC. | ||
lipo.quickStart(); | ||
|
||
// We can set an interrupt to alert when the battery SoC gets too low. | ||
// We can alert at anywhere between 1% - 32%: | ||
lipo.setThreshold(20); // Set alert threshold to 20%. | ||
} | ||
|
||
void loop() | ||
{ | ||
// lipo.getVoltage() returns a voltage value (e.g. 7.86) | ||
voltage = lipo.getVoltage(); | ||
// lipo.getSOC() returns the estimated state of charge (e.g. 79%) | ||
soc = lipo.getSOC(); | ||
// lipo.getAlert() returns a 0 or 1 (0=alert not triggered) | ||
alert = lipo.getAlert(); | ||
|
||
// Print the variables: | ||
Serial.print("Voltage: "); | ||
Serial.print(voltage); // Print the battery voltage | ||
Serial.println(" V"); | ||
|
||
Serial.print("Percentage: "); | ||
Serial.print(soc); // Print the battery state of charge | ||
Serial.println(" %"); | ||
|
||
Serial.print("Alert: "); | ||
Serial.println(alert); | ||
Serial.println(); | ||
|
||
delay(500); | ||
} |
Oops, something went wrong.