logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

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 for BK7231N devices that converts raw ADC readings on the BAT_ADC pin into real battery voltage and a linear 0–100% “battery level.” It sets the min/max pack voltages and calibration parameters used by the battery driver. (elektroda.com)
  • Syntax (current OpenBeken builds): Battery_Setup [vdivider] [vref_mV] [adcbits]. Typical BK7231N values: vref_mV=2400, adcbits=4096. (elektroda.com)
  • Sampling cadence is set with Battery_cycle . The driver runs only if a GPIO is assigned as BAT_ADC (and optionally BAT_Relay/Bat_Relay_n). (elektroda.com)

Detailed problem analysis

  • Measurement chain
    • Hardware: The battery is fed to a high-value resistor divider into a BK7231N ADC pin. Many battery devices also gate the divider with a transistor or “BAT_Relay” pin to avoid constant leakage. (elektroda.com)
    • Firmware: When enabled, the battery driver periodically (or on demand) enables BAT_Relay (if present), waits a short settling time, samples the ADC, and reports voltage and percentage over MQTT/HTTP. (elektroda.com)
  • Signal conversion
    • ADC voltage: V_ADC = (adc_raw / (2^{adcbits}-1)) × V_ref, with V_ref ≈ 2400 mV and adcbits = 4096 on BK7231N. (elektroda.com)
    • Pack voltage: V_BAT = V_ADC × vdivider, where vdivider = 1 + R_top/R_bottom (true ratio should be measured, not assumed). A “typical” Tuya divider is ≈2.29 but varies with tolerances. (elektroda.com)
    • Percentage: linear map between vmin_mV (0%) and vmax_mV (100%), clipped outside that range. This is simple and robust, but does not model the non‑linear Li-ion curve. (elektroda.com)
  • Roles and prerequisites
    • You must assign at least one GPIO the BAT_ADC role; otherwise Battery_Setup is ignored. If your board has a FET or analog switch for the divider, assign BAT_Relay or Bat_Relay_n accordingly. (elektroda.com)
  • Sampling cadence and power
    • Battery_cycle sets measurement period in seconds (default ≈10 s). On deep‑sleep designs, disable periodic sampling and trigger a single measurement during each wake cycle to minimize µA‑level leakage. (elektroda.com)
  • Why calibration matters
    • A 2–3% divider error directly shifts reported voltage and low‑battery thresholds. Calibrate vdivider with a bench supply: sweep known voltages and adjust until the reported value matches. (elektroda.com)

Current information and trends

  • Argument order was unified to vmin, vmax, vdivider, vref, adcbits across builds in late 2023; older tutorials may show a legacy order. (elektroda.com)
  • For battery devices, recent OpenBeken workflows pair Battery_Setup with deep‑sleep scripting and BAT_Relay timing to cut sleep current to ≲10 µA on BK7231N‑based sensors. (elektroda.com)
  • Community examples show end‑to‑end setups (Battery_Setup + Battery_cycle + deep sleep scripting) in smoke detectors and door sensors, confirming field‑proven parameter ranges. (elektroda.com)

Supporting explanations and details

  • Picking vmin/vmax by chemistry (examples; adjust to your cell and cutoffs)
    • 2× AAA/AA alkaline: vmin 2000, vmax 3100 mV (divider depends on hardware). Battery_Setup 2000 3100 [vdivider]. (elektroda.com)
    • 1S Li‑ion/LiPo: vmin 3000, vmax 4200 mV. Battery_Setup 3000 4200 [vdivider]. Note: this config monitors a 1‑cell pack; it does not charge/protect it. (elektroda.com)
    • 3 V primary (e.g., ER14250 Li‑SOCl2): vmin 2500, vmax 3400 mV. Battery_Setup 2500 3400 [vdivider]. (elektroda.com)
    • Tip: Determine vdivider from your actual resistor pair; “2.29” is a common starting point on Tuya boards but must be verified. (elektroda.com)
  • Divider design for low leakage
    • Use ≥1 MΩ top resistor to keep measurement current in the 1–3 µA range; for coin cells, prefer a switched divider via BAT_Relay to eliminate idle drain altogether. (elektroda.com)
  • Timing and accuracy
    • If using BAT_Relay, allow a few milliseconds after enabling before sampling to let the divider and ADC settle; OpenBeken added such delays specifically to reduce wrong readings. (elektroda.com)

Ethical and legal aspects

  • Battery monitoring settings should prevent deep‑discharge of primary cells (environmental leakage risk) and honor manufacturer‑recommended cutoffs. For rechargeable Li‑ion/LiPo hardware, ensure your product also integrates certified charge/protection circuits to meet safety and transport rules (e.g., IEC 62133, UN 38.3). The Battery_Setup command itself does not enforce cell safety. (elektroda.com)

Practical guidelines

  • Minimal, robust setup flow (OpenBeken, BK7231N)
    1. Assign roles: setPinRole BAT_ADC; if present, setPinRole BAT_Relay (or Bat_Relay_n). (elektroda.com)
    2. Start with a safe divider guess (e.g., 2.29), then issue Battery_Setup 2400 4096. (elektroda.com)
    3. Set Battery_cycle to a sensible rate for your use (e.g., 60–300 s on mains‑powered sensors; “0” or scripted single‑shot on deep‑sleep devices). (elektroda.com)
    4. Calibrate vdivider using a bench supply sweep and compare reported voltage vs. actual; iterate until within ≤1%. (elektroda.com)
    5. For deep‑sleep devices, take one measurement at wake, publish it, then sleep. Community scripts demonstrate this pattern in production sensors. (elektroda.com)
  • Example command sets
    • 2× AAA door sensor with 1 MΩ/470 kΩ divider (vdivider≈3.09), sample every 2 minutes:
    • Battery_Setup 2000 3100 3.09 2400 4096
    • Battery_cycle 120 (elektroda.com)
    • 1S Li‑ion with 1 MΩ/330 kΩ divider (vdivider≈4.03), one‑shot per wake:
    • Battery_Setup 3000 4200 4.03 2400 4096
    • Battery_cycle 0 (and trigger measurement in wake script) (elektroda.com)

Possible disclaimers or additional notes

  • Percentage is linear between vmin and vmax; if you need chemistry‑accurate SoC, implement a lookup or multi‑segment map in your application logic. (elektroda.com)
  • Some older posts use the legacy argument order; always confirm with help or release notes on your specific firmware build. (elektroda.com)

Suggestions for further research

  • Review the OpenBeken battery measurement driver thread for deeper details on BAT_ADC/BAT_Relay behavior, timing, and recent fixes. (elektroda.com)
  • Study community configurations for specific devices (e.g., 19JWT‑B door sensor, smoke detectors) to copy known‑good pin roles and scripts. (elektroda.com)

Brief summary

Battery_Setup on BK7231N/OpenBeken defines how the firmware turns a BAT_ADC reading into a calibrated pack voltage and a linear percentage. Provide accurate vmin/vmax for your chemistry, measure and enter the real divider ratio, and set a sensible Battery_cycle. Use BAT_Relay (if available) and deep‑sleep scripting to minimize leakage and maximize life. These practices and parameter ranges are documented and field‑proven across multiple BK7231N battery devices. (elektroda.com)

If you share your board’s resistor values and intended cell chemistry, I can calculate an exact vdivider and a tailored Battery_Setup line.

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.