Skip to content

examples(bq27441): Add practical usage examples. #73#188

Open
DumontALINE wants to merge 7 commits into
mainfrom
feat/bq27441-example
Open

examples(bq27441): Add practical usage examples. #73#188
DumontALINE wants to merge 7 commits into
mainfrom
feat/bq27441-example

Conversation

@DumontALINE
Copy link
Copy Markdown
Contributor

@DumontALINE DumontALINE commented May 28, 2026

Summary

Add two example sketches for the BQ27441 fuel gauge driver.

close #73

Changes

  • Add battery_status — prints voltage (mV), state of charge (%),
    remaining capacity (mAh) and state of health (%) to the serial
    monitor every 3 seconds.

  • Add low_battery_alert — blinks the red LED when the battery drops
    below 20 % and sounds the on-board buzzer when it falls below 5 %.

Checklist

  • make lint passes (clang-format)
  • make build passes (PlatformIO)
  • make test-native passes (if native tests exist)
  • make test-hardware passes on a connected STeaMi (if hardware tests exist)
  • README updated (if adding/changing public API)
  • Examples added/updated (if applicable)
  • Commit messages follow conventional commits format

Copilot AI review requested due to automatic review settings May 28, 2026 08:02
@github-actions github-actions Bot added this to the Phase 3 — Drivers simples milestone May 28, 2026
@DumontALINE DumontALINE requested a review from nedseb May 28, 2026 08:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two BQ27441 fuel-gauge example sketches addressing issue #73: one prints periodic battery telemetry to serial, the other triggers visual/audible alerts on low charge. Both wire the gauge to the STeaMi internal I2C bus.

Changes:

  • New BatteryStatus example printing voltage, SOC, remaining capacity and SOH every 3 s.
  • New LowBatteryAlert example blinking LED_RED below 20 % SOC and beeping SPEAKER below 5 % SOC.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
lib/bq27441/examples/BatteryStatus/BatteryStatus.cpp Baseline telemetry sketch for the BQ27441
lib/bq27441/examples/LowBatteryAlert/LowBatteryAlert.cpp Low-SOC alert sketch using LED + buzzer

Notes: Both files use a .cpp extension and PascalCase folders, which conflict with the example layout required by CONTRIBUTING.md (lower snake-case folders and matching .ino sketch file) — the PR description itself uses battery_status / low_battery_alert. Also, neither sketch prints a diagnostic when sensor.begin() fails, diverging from the established sibling examples.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,44 @@
// SPDX-License-Identifier: GPL-3.0-or-later
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : 598d855
Rename example files to snake_case.

@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0-or-later
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : 598d855
Rename example files to snake_case.

Comment on lines +23 to +27
if (!sensor.begin()) {
while (true) {
delay(1000);
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : 8131689
Print an error message before the infinite loop so the user knows the sensor was not detected instead of silently blocking.

Comment on lines +36 to +40
if (!sensor.begin()) {
while (true) {
delay(1000);
}
}
Copy link
Copy Markdown
Contributor Author

@DumontALINE DumontALINE May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : 4e8401b
Print an error message before the infinite loop so the user knows the sensor was not detected instead of silently blocking.

Comment on lines +46 to +56
void loop() {
if (sensor.stateOfCharge() <= 20) {
blink();
delay(200);
}
if (sensor.stateOfCharge() <= 5) {
buzzAlert();
delay(1000);
} else {
delay(1000);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : 4e8401b
Cache stateOfCharge() once at the top of loop() to avoid two I2C transactions per iteration — both reads could straddle a threshold and produce inconsistent results.

Comment on lines +33 to +42
Serial.print("mV \n");
Serial.print("State of Charge: ");
Serial.print(sensor.stateOfCharge());
Serial.print("% \n");
Serial.print("Remaining Capacity: ");
Serial.print(sensor.capacityRemaining());
Serial.print("mAh \n");
Serial.print("State of Health: ");
Serial.print(sensor.stateOfHealth());
Serial.println("% \n");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : 8131689
Replace Serial.print(...) + "\n" with Serial.println(...) to follow Arduino convention and remove the trailing space before the newline. Also remove the extra blank line produced by the last Serial.println("% \n").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples(bq27441): Add practical usage examples.

3 participants