48 Serial.println(
"Failed to BQ27220 - check your wiring!");
53 Serial.println(
"Init BQ27220 Sensor success!");
73 uint16_t newDesignCapacity = 3500;
74 uint16_t newFullChargeCapacity = 3500;
80 Serial.print(
"OperationConfigA Values:0x");
83 Serial.print(
"External Thermistor Selected: ");
84 Serial.println(config.
isTempsSet() ?
"YES" :
"NO");
86 Serial.print(
"BATT_GD Pin Polarity High: ");
89 Serial.print(
"BATT_GD Function Enabled: ");
92 Serial.print(
"Can Enter SLEEP State: ");
95 Serial.print(
"slpwakechg Function Enabled: ");
98 Serial.print(
"Write Temperature Function Enabled: ");
101 Serial.print(
"Battery Insertion Detection Enabled: ");
104 Serial.print(
"Battery Insertion Pin Pull - Up Enabled: ");
107 Serial.print(
"Pin Function Code (PFC) Mode: ");
110 Serial.print(
"Wake - Up Function Enabled: ");
113 Serial.print(
"Wake - Up Threshold 1: ");
116 Serial.print(
"Wake - Up Threshold 0: ");
120 Serial.print(
"\nOperationConfigB Values:0x");
123 Serial.print(
"Default Seal Option Enabled: ");
126 Serial.print(
"Non - Removable Option Set: ");
129 Serial.print(
"INT_BREM Function Enabled: ");
132 Serial.print(
"INT_BATL Function Enabled: ");
135 Serial.print(
"INT_STATE Function Enabled: ");
138 Serial.print(
"INT_OCV Function Enabled: ");
141 Serial.print(
"INT_OT Function Enabled: ");
144 Serial.print(
"INT_POL Function Enabled (High - Level Polarity): ");
147 Serial.print(
"INT_FOCV Function Enabled: ");
156 uint32_t startMeasTime = millis();
160 uint32_t endMesTime = millis();
162 Serial.print(
"Polling time: "); Serial.print(endMesTime - startMeasTime); Serial.println(
" ms");
164 Serial.println(
"\nStandard query:");
165 Serial.print(
"\t- AtRate:"); Serial.print(
gauge.
getAtRate()); Serial.println(
" mA");
167 Serial.print(
"\t- Temperature:"); Serial.print(
gauge.
getTemperature() ); Serial.println(
" ℃");
168 Serial.print(
"\t- BatteryVoltage:"); Serial.print(
gauge.
getVoltage()); Serial.println(
" mV");
169 Serial.print(
"\t- InstantaneousCurrent:"); Serial.print(
gauge.
getCurrent()); Serial.println(
" mAh");
173 Serial.print(
"\t- TimeToEmpty:"); Serial.print(
gauge.
getTimeToEmpty()); Serial.println(
" minutes");
174 Serial.print(
"\t- TimeToFull:"); Serial.print(
gauge.
getTimeToFull()); Serial.println(
" minutes");
180 Serial.print(
"\t- AveragePower:"); Serial.print(
gauge.
getAveragePower()); Serial.println(
" mW");
188 Serial.print(
"\t- BTPChargeSet:"); Serial.print(
gauge.
getBTPChargeSet()); Serial.println(
" mAh");
192 Serial.println(
"\nOperation Status:");
193 Serial.print(
"\t- getIsConfigUpdateMode:"); Serial.println(status.
getIsConfigUpdateMode() ?
"YES" :
"NO");
202 Serial.println(
"\nBattery Status:");
204 Serial.println(
"\t- Full discharge detected.");
207 Serial.println(
"\t- OCV measurement update is complete.");
210 Serial.println(
"\t- Status bit indicating that an OCV read failed due to current.");
211 Serial.println(
"\tThis bit can only be set if a battery is present after receiving an OCV_CMD().");
214 Serial.println(
"\t- The device operates in SLEEP mode");
217 Serial.println(
"\t- Over-temperature is detected during charging.");
220 Serial.println(
"\t- Over-temperature detected during discharge condition.");
223 Serial.println(
"\t- Full charge detected.");
226 Serial.println(
"\t- Charge Inhibit: If set, indicates that charging should not begin because the Temperature() is outside the range");
227 Serial.println(
"\t[Charge Inhibit Temp Low, Charge Inhibit Temp High]. ");
230 Serial.println(
"\t- Termination of charging alarm. This flag is set and cleared based on the selected SOC Flag Config A option.");
233 Serial.println(
"\t- A good OCV measurement was made.");
236 Serial.println(
"\t- Detects inserted battery.");
239 Serial.println(
"\t- Battery presence detected.");
242 Serial.println(
"\t- Termination discharge alarm. This flag is set and cleared according to the selected SOC Flag Config A option.");
245 Serial.println(
"\t- System shutdown bit indicating that the system should be shut down. True when set. If set, the SOC_INT pin toggles once.");
248 Serial.println(
"\t- When set, the device is in DISCHARGE mode; when cleared, the device is in CHARGING or RELAXATION mode.");
250 Serial.println(
"===============================================");
bool isInSleepMode() const
Check if the device is in sleep mode.
bool isBatteryPresent() const
Check if a battery is present.
bool isChargeInhibited() const
Check if charging is inhibited.
bool isInDischargeMode() const
Check if the device is in discharge mode.
bool isOverTemperatureDuringCharging() const
Check if over-temperature is detected during charging.
bool isDischargeTerminationAlarm() const
Check if the discharge termination alarm is triggered.
bool isFullChargeDetected() const
Check if full charge is detected.
bool isSystemShutdownRequired() const
Check if system shutdown is required.
bool isGoodOcvMeasurement() const
Check if a good OCV measurement was made.
bool isOcvReadFailedDueToCurrent() const
Check if the OCV read failed due to current.
bool isChargingTerminationAlarm() const
Check if the charging termination alarm is triggered.
bool isOverTemperatureDuringDischarge() const
Check if over-temperature is detected during discharge.
bool isFullDischargeDetected() const
Check if full discharge is detected.
bool isOcvMeasurementUpdateComplete() const
Check if the OCV measurement update is complete.
bool isBatteryInserted() const
Check if a battery is inserted.
bool getIsInitializationComplete() const
bool getIsCalibrationModeEnabled() const
bool getIsBatteryVoltageBelowEdv2() const
bool getIsBtpThresholdExceeded() const
bool getIsCapacityAccumulationThrottled() const
bool getIsDischargeCycleCompliant() const
uint8_t getSecurityAccessLevel() const
bool getIsConfigUpdateMode() const
uint16_t getMaxLoadTimeToEmpty() const
Get the estimated time until the battery is empty at maximum load current discharge rate.
uint16_t getTimeToFull() override
Get the estimated time until the battery is fully charged.
uint16_t getBTPDischargeSet() const
Get the BTP discharge set value.
uint16_t getStandbyTimeToEmpty() const
Get the estimated time until the battery is empty at standby discharge rate.
uint16_t getAtRateTimeToEmpty() const
Get the AtRateTimeToEmpty value.
uint16_t getFullChargeCapacity() const
Get the full charge capacity of the battery.
uint16_t getStateOfHealth() const
Get the state of health value.
uint16_t getStateOfCharge() override
Get the state of charge value.
uint16_t getRawCoulombCount() const
Get the raw coulomb count value.
OperationConfig getOperationConfig()
Retrieve the operation configuration of the device.
int16_t getAveragePower() const
Get the average power value.
BatteryStatus getBatteryStatus() const
Get the battery status.
uint16_t getRemainingCapacity() const
Get the remaining battery capacity.
uint16_t getCycleCount() const
Get the cycle count value.
uint16_t getRequestChargingCurrent() const
Get the requested charging current value.
bool refresh() override
Refresh the battery data by reading from the registers.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback)
float getTemperature() override
Get the temperature value.
uint16_t getAtRate() const
Get the AtRate value.
uint16_t getDesignCapacity() const
Get the design capacity value.
FuelGaugeOperationStatus getOperationStatus() const
Get the operation status.
uint16_t getRequestChargingVoltage() const
Get the requested charging voltage value.
float getCurrent() override
Get the instantaneous current value.
float getInternalTemperature() const
Get the internal temperature value.
int16_t getMaxLoadCurrent() const
Get the maximum load current value.
uint16_t getVoltage() override
Get the battery voltage value.
uint16_t getTimeToEmpty() override
Get the estimated time until the battery is empty.
bool setNewCapacity(uint16_t newDesignCapacity, uint16_t newFullChargeCapacity)
Set the new design capacity and full charge capacity of the battery.
uint16_t getBTPChargeSet() const
Get the BTP charge set value.
int16_t getStandbyCurrent() const
Get the standby current value.
bool isNonRemovableSet() const
Check if the non - removable option is set.
bool isIntBremEnabled() const
Check if the INT_BREM function is enabled.
bool isIntStateEnabled() const
Check if the INT_STATE function is enabled.
bool isTempsSet() const
Check if the external thermistor is selected for temperature measurement.
uint16_t getConfigB() const
Get the value in configuration register B.
bool canEnterSleep() const
Check if the fuel gauge can enter the SLEEP state.
bool isWakeEnEnabled() const
Check if the wake - up function is enabled.
bool isDefaultSealEnabled() const
Check if the default seal option is enabled (sealed after POR).
bool isIntBatLEnabled() const
Check if the INT_BATL function is enabled.
bool isWrtempEnabled() const
Check if the write temperature function is enabled.
int getPfcCfg() const
Get the Pin Function Code (PFC) mode.
bool isBlPupEnEnabled() const
Check if the battery insertion pin pull - up is enabled.
bool isIntFocvEnabled() const
Check if the INT_FOCV function is enabled.
uint16_t getConfigA() const
Get the value in configuration register A.
bool isIntPolHigh() const
Check if the INT_POL function is enabled (high - level polarity).
bool isBienableEnabled() const
Check if battery insertion detection is enabled.
int getWkTh0() const
Get the Wake - up threshold 0 value.
bool isBatgPolHigh() const
Check the BATT_GD pin polarity.
bool isBatgEnEnabled() const
Check if the BATT_GD function is enabled.
bool isIntOtEnabled() const
Check if the INT_OT function is enabled.
int getWkTh1() const
Get the Wake - up threshold 1 value.
bool isIntOcvEnabled() const
Check if the INT_OCV function is enabled.
bool isSlpwakechgEnabled() const
Check if the slpwakechg function is enabled.