logo elektroda
logo elektroda
X
logo elektroda

OpenBeken Battery_Setup Command for BK7231N: Calibration, Divider Ratio, and Battery Percentage

User question

Battery_Setup bk7231N

Artificial Intelligence Response

Direct answer to the question

  • Battery_Setup is an OpenBeken command that tells a BK7231N-based, battery-powered device how to translate the raw ADC reading on the BAT_ADC pin into a real battery voltage and a “battery-percentage” value.
  • Syntax (firmware ≥ 2023-09):
Battery_Setup <vmin_mV> <vmax_mV> [vdivider] [vref_mV] [adcbits]

Key points
vmin_mV – voltage at which the pack is considered empty
vmax_mV – voltage at which the pack is considered full
vdivider – ratio of the external resistor divider (default ≈ 2.29)
vref_mV – ADC reference (BK72xx is fixed ≈ 2400 mV but kept for future chips)
adcbits – ADC resolution (BK7231N: 4096 counts for 12-bit)

The command is recognised only when at least one GPIO is declared as BAT_ADC.


Detailed problem analysis

  1. How OpenBeken measures battery voltage
    • Every BAT_ADC sample returns a raw count adc_raw.
    • Voltage on the ADC pin

\[ V{ADC}= \frac{adc_raw}{2^{adcbits}-1}\times V{ref} \]

• Pack voltage

\[ V{BAT}=V{ADC}\times vdivider \]

• Percentage

\[ \%\;=\;\text{clamp}!\left(\frac{V{BAT}-v{min}}{v{max}-v{min}}\times100,\,0,\,100\right) \]

The values are advertised via MQTT/Home Assistant in the sensor.battery entity.

  1. Typical hardware
    • A high-value divider (≥ 1 MΩ top resistor) limits sleep current to ≈ 3 µA.
    • For ultra-low-power designs add a P-MOSFET or NPN to switch the divider on only during measurement.

  2. Measurement cadence
    Battery_cycle <N> sets the period; default 10 s (= 10 OpenBeken frames).
    • On deep-sleep devices you usually disable the periodic task and call Battery_MeasureNow in your wake-up script, saving tens of µA.

  3. Example calibrations
    • 2 × AAA Alkaline door sensor

    setPinRole 24 BAT_ADC ;GPIO24 wired to divider
    Battery_Setup 2000 3100 3.09 ;empty @2.0 V, full @3.1 V, divider 1 M/470 k
    Battery_cycle 120 ;measure every 2 min

    • 1-cell Li-Po with 1 MΩ/330 kΩ divider

    Battery_Setup 3000 4200 4.03

    • Lithium-thionyl (ER14250) 3 V primary

    Battery_Setup 2500 3400 2.29

Current information and trends

• The argument order (vmin vmax …) was unified across OpenBeken builds in Q4-2023; older tutorials show the legacy order.
• Deep-sleep patches (Oct-2023 → Jan-2024) reduced BK7231N sleep current to ≈ 7.5 µA when Wi-Fi/RTC are off, extending coin-cell life to > 1 year in sensor workloads.
• Home Assistant’s MQTT auto-discovery template now recognises the battery device-class automatically when the BAT_ADC role is present.


Supporting explanations and details

Voltage-divider design
• Divider ratio

\[ vdivider = 1+\frac{R{top}}{R{bottom}} \]

• Choose R_top ≥ 1 MΩ to keep divider current < 3 µA.
• Measure the exact ratio with a lab DMM; component tolerances easily introduce 2–3 % error, which becomes visible near the low-battery threshold.

Impact on battery life
• A permanent divider of 3 µA drains ≈ 26 mAh/month – acceptable for 2400 mAh AA cells but unacceptable for CR2032 (230 mAh). Use a switched divider there.


Ethical and legal aspects

• For rechargeable Li-ion/Li-Po cells incorporate proper charge/protection ICs (TP4056, DW01) to meet IEC 62133 and UN 38.3 transport rules.
• Accurate low-battery signalling avoids deep-discharging primary cells, preventing leakage and environmental harm.


Practical guidelines

Implementation checklist

  1. Add a divider to any BK7231N board meant for battery operation.
  2. Flash OpenBeken ≥ v1.17.120 or later.
  3. Assign the GPIO → BAT_ADC.
  4. Issue Battery_Setup with measured parameters.
  5. Verify with a bench supply sweeping the pack voltage; tune vdivider.
  6. Publish the configuration in your product datasheet / maintenance guide.

Typical challenges & mitigations
• ADC noise → add 100 nF from ADC pin to GND.
• Wrong percentage curve → mis-ordered parameters; confirm with Battery_Show.
• Unexpected drain → divider not switched; confirm with a µA-meter in sleep.


Possible disclaimers or additional notes

• BK7231N ADC absolute accuracy is ±2 %, so reported SoC is an estimate, not a coulomb count.
• Temperature dependence of alkaline cells can falsify low-battery reporting; compensate in firmware if used outdoors.


Suggestions for further research

• Evaluate integrating a fuel-gauge IC (e.g. MAX17048) for Li-Po packs where precise SoC is needed.
• Study the new BK7236 chip — expected to bring an on-chip LDO with nA-range Iq which may simplify future battery sensors.
• Investigate buck regulators such as TI TPS62840 (Iq = 60 nA) when the product spends > 5 % of the time in Wi-Fi Tx.


Brief summary

Battery_Setup calibrates how OpenBeken running on a BK7231N converts ADC readings into a true battery voltage and percentage. Provide vmin, vmax, and the exact resistor-divider ratio; verify with a meter; tune sampling frequency for the best compromise between accuracy and power. Correct calibration, together with deep-sleep firmware and low-leakage hardware, is the cornerstone of year-long battery life in BK7231N IoT sensors.

Ask additional question

Wait...(2min)
Disclaimer: The responses provided by artificial intelligence (language model) may be inaccurate and misleading. Elektroda is not responsible for the accuracy, reliability, or completeness of the presented information. All responses should be verified by the user.