https://github.com/pilotak/bq35100
Mbed library for BQ35100 primary battery fuel gauge
https://github.com/pilotak/bq35100
battery-gauge bq35100 mbed-os
Last synced: 13 days ago
JSON representation
Mbed library for BQ35100 primary battery fuel gauge
- Host: GitHub
- URL: https://github.com/pilotak/bq35100
- Owner: pilotak
- License: apache-2.0
- Created: 2020-08-29T15:43:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-14T17:48:17.000Z (almost 2 years ago)
- Last Synced: 2025-03-28T03:41:21.480Z (about 1 month ago)
- Topics: battery-gauge, bq35100, mbed-os
- Language: C++
- Homepage:
- Size: 270 KB
- Stars: 6
- Watchers: 1
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BQ35100
[](https://os.mbed.com/)
Mbed library for BQ35100 primary battery fuel gauge. Originally written by [u-blox](https://os.mbed.com/teams/ublox/code/battery-gauge-bq35100) but rewritten (no backwards compatibility) with added calibration functions and other important stuff. Compatible with OS 6, where the original one fails.
## Basic setting
```cpp
#include "mbed.h"
#include "BQ35100.h"BQ35100 gauge(I2C_SDA, I2C_SCL, D7);
int main() {
if (!gauge.init()) {
return 0;
}gauge.setGaugeMode(BQ35100::ACCUMULATOR_MODE);
gauge.useInternalTemp(true);
gauge.setDesignCapacity(3800);
gauge.setBatteryAlert(0); // as we are not using ALERT pin
gauge.setSecurityMode(BQ35100::SECURITY_SEALED);
}
```## Calibration
```cpp
#include "mbed.h"
#include "BQ35100.h"BQ35100 gauge(I2C_SDA, I2C_SCL, D7);
int main() {
// next four step are mandatory for calibration
if (gauge.init(&i2c)) {
debug("Init OK\n");} else {
debug("Could not init the gauge\n");
return 0;
}if (gauge.setSecurityMode(BQ35100::SECURITY_UNSEALED)) {
debug("Device unsealed\n");} else {
debug("Unseal failed\n");
return 0;
}if (gauge.setGaugeMode(BQ35100::ACCUMULATOR_MODE)) {
debug("Gauge mode set\n");} else {
debug("Set gauge mode failed\n");
return 0;
}if (gauge.startGauge()) {
debug("Gauge started\n");} else {
debug("Could not start the gauge\n");
return 0;
}if (gauge.calibrateVoltage(3600)) { // mV
debug("Voltage calibration successful\n");} else {
debug("Voltage calibration failed\n");
return 0;
}if (gauge.performCCOffset()) {
debug("CC offset successful\n");} else {
debug("CC offset failed\n");
return 0;
}if (gauge.performBoardOffset()) {
debug("Board offset successful\n");} else {
debug("Board offset failed\n");
return 0;
}if (gauge.calibrateCurrent(100)) { // mA
debug("Current calibration successful\n");} else {
debug("Current calibration failed\n");
return 0;
}if (gauge.useInternalTemp(true) && gauge.calibrateTemperature(2962)) { // 23.05°C
debug("Internal temperature calibration successful\n");} else {
debug("Internal temperature calibration failed\n");
return 0;
}if (gauge.useInternalTemp(false) && gauge.calibrateTemperature(2962)) { // 23.05°C
debug("External temperature calibration successful\n");} else {
debug("External temperature calibration failed\n");
return 0;
}gauge.setSecurityMode(BQ35100::SECURITY_SEALED);
}
```