Skip to main content

Battery, Sleep & Power Management

For a portable or wearable project — a wireless button box, a BLE wheel, an IMU-on-radio sensor — three power-side questions matter: what kind of battery is plugged in, how do I report its state, and how do I save energy while idle. NodeBlue ships specific modules for each piece.

Reading a battery voltage​

For most simple cases, the simplest answer is best: wire the battery through a resistor divider to an analog pin and use nAnalogInput → nRange → a percentage. A typical 3.7 V LiPo with a 100 kΩ / 100 kΩ divider feeds an ADC pin a voltage half the cell's — a single Range remap is enough to turn the raw ADC code into a 0..100 % charge estimate.

Some boards do this for you on a dedicated pin:

  • Adafruit Feather M0 / nRF52840 Feather Express: the on-board Bat pin (no external divider needed) — already half-Vbat via an internal divider.
  • XIAO BLE: the Bat-/Bat+ pins expose the JST battery connector; you tap an analog pin off them through your own divider.
Voltage (LiPo 3.7 V cell)State
4.2 VFull
3.7 VMid (≈ 50 %)
3.4 VLow — start warning the user
3.0 VCell cutoff — anything below risks damaging the cell

The cell-voltage-to-percentage curve is not linear; for a rough indicator the linear Range is fine, for a real "% charge remaining" you'd add an nCubicSpline after the Range and shape the curve to the discharge profile.

See Examples/Measure/TM637_RGB_Battery_Level for a typical voltage→display chain and any of the XIAO_BLE_*_Battery.txt or NRF52840_Express_*_Battery.txt examples for ready-to-use battery dividers on Adafruit boards.

Power-management ICs​

For boards that include a dedicated charger / boost IC, NodeBlue has higher-level modules that hide the I²C register dance.

nIP5306 — single-cell LiPo manager​

The IP5306 is a popular all-in-one I²C charger + 5 V boost found on a lot of "power bank" reference boards and Maker-style USB-LiPo modules. nIP5306 drives its registers directly:

ParameterDescription
BoostEnable the 5 V boost output.
ChargerEnable the charging stage.
Boost OutputEnable the boost output pin (separate gate).
Stop Charging CurrentThe trickle-current threshold below which the IC declares the cell full (CURRENT_400 = 400 mA, etc.).
Charge VoltageTarget charge voltage offset — usually VOUT_6.
Battery Voltage / Voltage PressureInternal calibration knobs for the IC's voltage-measurement state machine — leave at defaults unless your part variant requires it.

Inputs Boost Off / Boost On toggle the boost output from your project logic (handy for "go to sleep on user inactivity").

outputs is currently 0 — the IP5306's battery-state readback isn't exposed in this module version yet (the Bat output port is declared but disabled in code). Read the battery voltage via the analog-pin route if you need a percentage.

nBQ24295 — Texas Instruments charger + 5 V boost​

The BQ24295 is the charging IC used on the ElectroSeed MMWB RB boards. It does two things in one chip: charges a single-cell LiPo from USB, and boosts the cell voltage (3.0..4.2 V depending on state of charge) to a clean 5 V rail — useful for powering 5 V-only peripherals like a Nextion display or a TM1637 7-segment module directly off the battery, without an external boost converter.

nBQ24295 drives its register set:

ParameterDescription
Input CurrentLimit on USB-side draw (BQ24295_IINLIM_3_A = 3 A, etc.). Keep this consistent with the charger you're plugging into — 500 mA for a stock USB-2 port, 1.5 A for "fast charge" wall warts, 3 A for a beefy USB-C PD source.
Minimum In VoltageThe minimum USB voltage below which the IC stops drawing from input ("DPM" — dynamic power management).
Minimum SYSFloor of the system rail — the IC won't let the system bus dip below this even if the cell is sagging.
Boost / Charger / Battery FETThe three master enables (OTG boost, charger stage, battery-to-system FET).

Output is a Buffer carrying the IC's status registers — wire it into a buffer-split chain (or directly into a Nextion display for diagnostics) to see charge state, fault flags, input present, etc.

Powering the board itself​

Schematic-only s* modules describe the physical wiring of the power tree — they don't generate firmware on their own, but they document the connections for the schematic export:

  • sBattery — the cell, with Gnd and Vcc rails.
  • sAdafruitMiniBoost5V — 5 V boost converter (Adafruit Mini Boost). Takes Vin from the cell, outputs 5 V — useful for WS2812 strips and other 5 V-only loads on a 3.3 V system.

Both are pure schematic nodes (no RED.nodes.registerType flow ports) — they only matter for the schematic export.

Reporting battery level over BLE​

The HID-BLE modules (nBLEGamePad and nBLEKeyboard) both have a Battery input. Wire your battery-percentage value (0..100 u8) into it and the BLE Battery Service is automatically advertised to the host — Windows / iOS / Android display the battery icon next to the device name without any extra setup.

ModuleHow
nBLEGamePadWire 0..100 into the Battery input. The module auto-detects the connection (pHasBattery is set when something is wired) and enables the BLE Battery Service.
nBLEKeyboardSame idea, same Battery input.

A typical chain:

nAnalogInput (battery divider pin) → nRange (ADC counts → 0..100) → nBLEGamePad.Battery input.

For periodic reporting (say every 30 s), drive the chain via an nSoftwareTimer connected to the analog reader's Sync — you save battery (and ADC noise on the BLE link) by not reading the divider every loop.

See Examples/BLE/BLEKeyboard_Batt and Examples/BLE/BLEGamePad_15B_4EN_A1_Batt.

Saving energy — nSleep​

nSleep is the firmware-side power-down primitive. It accepts two pulse inputs and dispatches the MCU's deepest available sleep mode:

InputEffect
SleepPulse to enter sleep. The MCU stops the MainLoop and parks in the lowest-power state available for the configured mode (SNOOZE_MODE_SLEEP for stop, SNOOZE_MODE_DEEP_SLEEP for deep-sleep where supported).
WakeWired to whatever wakeup source you want — typically a button press through an interrupt-capable nDigitalInt. The pulse exits sleep.

Parameters:

ParameterDescription
ModeSleep depth. SNOOZE_MODE_SLEEP for a quick-wakeup low-power state; deeper modes are board-dependent.
Check Period (ms)How often the firmware wakes itself up internally to check whether anything is happening (a timer expired, a sensor crossed a threshold).
Awake Duration (ms)After a wakeup, how long to stay awake before considering re-sleeping. Too short = the user's button press is half-handled before re-sleep; too long = wasted energy.

The Snooze depth and what peripherals stay on during sleep are MCU-specific. Read the data-sheet for your part before trusting "sleep" to actually mean microamps: the same nSleep mode on a SAMD21 ≈ 5 µA, but on a Teensy 4.0 ≈ 50 mA because the chip's idle floor is much higher.

A radio-wake setup: the receiving radio chip is left on while the MCU sleeps, and a pin from the radio's interrupt line (mapped through nDigitalInt) wakes the MCU when a packet arrives.

Software reset — nReset​

nReset is the "kick the MCU" module. A pulse on its input triggers a full software reset — equivalent to pressing the on-board reset button. Useful for:

  • A "reboot to bootloader" path (combined with bootloader-specific magic bytes).
  • A user-facing "reset to defaults" sequence (combined with NBIC_CLEAR_STORAGE via the NBI protocol).
  • A watchdog-style recovery from a known-bad state.

No parameters — just wire a pulse source into its input and it resets when that pulse fires.

Composing a low-power BLE controller​

A wireless button box on an XIAO BLE with battery reporting and idle sleep, sketch:

Buttons → nButton × N → nBitPacker → nSerializer → nBLEGamePad

Battery monitor: nAnalogInput (bat divider) → nRange (ADC → 0..100) → nBLEGamePad.Battery

Idle detector: an activity detector → nSleep.Sleep when no input has changed for N seconds

Wakeup: any of the buttons → nDigitalInt → nSleep.Wake

That's a typical 2025-style BLE controller in NodeBlue — about ten modules end-to-end.

For the BLE link itself and the rest of the wireless transports, see Wireless transports.