This library interfaces with the Texas Instruments BQ27441 Battery Fuel Gauge using software (bit-bang) I2C. This allows the device to be connected to any two available I/O pins instead of the hardware-specific I2C peripheral pins on your microcontroller.
SparkFun has a library available when using hardware I2C.
This library depends on a specific SWI2C library.
Be sure to review the example sketch included with the library.
-
Install the SWI2C library in addition to this library.
-
Include the library header file:
#include <BQ27441_SWI2C.h>
Note that this library depends on the SWI2C library.
-
Instantiate a BQ27441_SWI2C object.
sda_pin
is the pin number for the SDA signal,scl_pin
is the pin number for the SCL signal.BQ27441_SWI2C myBQ27441(uint8_t sda_pin, uint8_t scl_pin); // Default I2C address 0x55
The library assumes an I2C device address of 0x55. If for some reason you need to use a different device address, then a third parameter can be used in the constructor:
BQ27441_SWI2C myBQ27441(uint8_t sda_pin, uint8_t scl_pin, uint8_t device_address);
-
Access the various device registers using the library methods listed below.
The library includes specific methods to read the various device values.
Standard Commands (see Technical Reference Chapter 4.2 - 4.19):
uint16_t getTemperature(); // Result in 0.1 Kelvins
uint16_t getTemperatureC(); // Result in 0.1 Celsius
int16_t getTemperatureF(); // Result in 0.1 Fahrenheit
int16_t getVoltage();
uint16_t getFlags();
uint16_t getNominalAvailableCapacity();
uint16_t getFullAvailableCapacity();
uint16_t getRemainingCapacity();
uint16_t getFullChargeCapacity();
int16_t getAverageCurrent();
int16_t getStandbyCurrent();
int16_t getMaxLoadCurrent();
int16_t getAveragePower();
uint16_t getStateOfCharge();
uint16_t getInternalTemperature(); // Result in 0.1 Kelvins
int16_t getInternalTemperatureC(); // Result in 0.1 Celsius
int16_t getInternalTemperatureF(); // Result in 0.1 Fahrenheit
uint16_t getStateOfHealth();
uint16_t getRemainingCapacityUnfiltered();
uint16_t getRemainingCapacityFiltered();
uint16_t getFullChargeCapacityUnfiltered();
uint16_t getFullChargeCapacityFiltered();
uint16_t getStateOfChargeUnfiltered();
Extended Data Commands (see Technical Reference Chapter 5.1 - 5.2):
uint16_t getOpConfig();
uint16_t getDesignCapacity();
Control Subcommands (see Technical Reference Chapter 4.1.1 - 4.1.6):
uint16_t getControlStatus();
uint16_t getDeviceType();
uint16_t getFWVersion();
uint16_t getDMCode();
uint16_t getPrevMacwrite();
uint16_t getChemID();
Since this library was designed as a simple interface to use software I2C to access battery status (e.g. voltage, current, temperature), other commands which configure or control the BQ27441 are left unimplemented.
The library also provides access to the underlying SWI2C
oject and its public methods. This can be useful for debugging and other specialized situations:
SWI2C* getSWI2CObject();
- Texas Instruments BQ27441 product page.
- BQ27441 Datasheet.
- BQ27441 User's Guide.
- BQ27441 Technical Reference.
- SparkFun BQ27441 library implemented with hardware I2C.
- SWI2C library.
The software and other files in this repository are released under what is commonly called the MIT License. See the file LICENSE
in this repository.