OpenBeken battery sensor voltage readings show 0.000000 – BL0937, BL0942, BAT_ADC setup and calibration
User question
How do i get voltage readings from my battery sensor?
getreadings command shows:
Info:CMD:Readings are 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Info:CMD:[WebApp Cmd 'GetReadings' Result] OK
Artificial Intelligence Response
Direct answer to the question
- “Readings are 0.000000 …” means the measurement path isn’t configured or the sensor isn’t being sampled. In OpenBeken, GetReadings only returns non‑zero values when a supported power/energy driver is active and producing data. For a battery ADC input you must enable and configure the Battery driver (BAT_ADC, optional BAT_Relay) and its calibration; for BL09xx/HW metering chips you must start the correct driver and calibrate it. (github.com)
- Action: decide which hardware you have (energy‑meter IC vs. simple ADC divider) and follow the matching setup below. After correct setup, you’ll see voltage on the Web UI and/or MQTT instead of all zeros. (github.com)
Key points
- GetReadings reports voltage/current/power only if a measurement driver is running. Zeros imply “no data.” (github.com)
- For battery ADC: assign BAT_ADC (and BAT_Relay if present), then Battery_Setup and (optionally) Battery_cycle. Default ADC reference ≈2400 mV, 12‑bit (4096 counts). (elektroda.com)
- For BL0937/BL0942/…: start the matching driver and calibrate with VoltageSet/CurrentSet/PowerSet. (elektroda.com)
Detailed problem analysis
1) Identify your sensor path
- Energy‑meter IC (BL0937/BL0942/HLW/SPDIF‑style): The chip streams V/I/P to the MCU. GetReadings is intended for this path; if the driver isn’t started or pins aren’t mapped, you’ll get zeros. (github.com)
- Battery ADC divider (typical on battery sensors): The battery is scaled by a resistor divider into a BK7231 ADC pin. This uses the Battery driver, not the energy driver; GetReadings isn’t the primary query path here. (elektroda.com)
2) Why zeros appear
- No driver active or wrong one selected (e.g., running GetReadings without a BL09xx driver). (github.com)
- ADC path not declared (BAT_ADC not assigned), so the Battery driver never runs/samples. (elektroda.com)
- Switched divider present but its control pin (BAT_Relay/Bat_Relay_n) isn’t assigned/used, so the ADC always sees 0 V. The Battery driver can toggle this pin automatically if you assign it. (elektroda.com)
- Calibration not set (divider factor), causing plausibly wrong values; raw still shouldn’t be all zeros if wiring is correct. (elektroda.com)
3) Electrical limits that must be respected
- BK7231 ADC reference is fixed ≈2400 mV; scale the highest battery voltage below this with divider Rtop/Rbottom. Vadc_max = Vbat_max × Rbottom/(Rtop+Rbottom) ≤ 2.4 V (add margin). Typical Tuya dividers are ~2.29:1 but vary—calibrate. (elektroda.com)
4) Where you’ll see the number once working
- Web UI: main page shows Battery/Voltage when the Battery driver runs. MQTT: device publishes “voltage” and “battery” topics periodically (default sampling ~10 s) unless you change Battery_cycle. (elektroda.com)
Current information and trends
- OpenBeken’s Battery driver autostarts when any GPIO is assigned BAT_ADC, optionally gating the divider via BAT_Relay/Bat_Relay_n, sampling every ~10 s by default. Battery_Setup sets vmin/vmax and calibration (divider, vref, ADC bits). (elektroda.com)
- GetReadings is a short command intended for power‑sensor stacks (returns V/I/P as a single ASCII line for easy parsing). (github.com)
- BL09xx energy devices require post‑flash calibration using VoltageSet/PowerSet/CurrentSet if factory values were lost. (elektroda.com)
Supporting explanations and details
- ADC chain math: Vadc = (raw/(2^N−1)) × Vref; Vbat = Vadc × vdivider. Default Vref ≈2400 mV, N=12 (4096). Divider “vdivider” is the ratio to reconstruct battery voltage. (elektroda.com)
- Switched dividers: many Tuya boards save battery by switching the top resistor with a FET. The driver asserts BAT_Relay, waits a short time, samples, then releases it. (elektroda.com)
Ethical and legal aspects
- Do not rely on simple voltage mapping for Li‑ion cell safety. Enforce proper cut‑off and use certified protection/charger ICs to meet safety standards (e.g., IEC 62133, UN 38.3). The firmware’s Battery_Setup only maps ADC to a %; it does not provide protection. (elektroda.com)
Practical guidelines
A) If your device uses an energy‑meter IC (GetReadings target path)
- Load the correct template or set pins, then start the driver for your chip (examples: BL0937/BL0942). Use the supported devices list or your device’s template for exact pins. (github.com)
- Calibrate: VoltageSet , CurrentSet , PowerSet . After this, GetReadings should return non‑zero V/I/P. (elektroda.com)
B) If your device is a battery ADC divider (most battery sensors)
- Assign GPIO roles:
- setPinRole BAT_ADC
- If your PCB has a switched divider: setPinRole BAT_Relay or Bat_Relay_n (depends on polarity)
- Optionally place them on a channel with setPinChannel, though the Battery driver will still work when BAT_ADC is assigned. (elektroda.com)
- Start or confirm driver is running (usually autostarts with BAT_ADC):
- startDriver Battery (harmless even if already running). (elektroda.com)
- Calibrate and set chemistry window:
- Battery_Setup [vdivider] [vref_mV] [adcbits]
- 1S Li‑ion: Battery_Setup 3000 4200 4.03 2400 4096 (example for ~1M/330k divider)
- 2×AAA alkaline: Battery_Setup 2000 3000 2.29 2400 4096
- Adjust vdivider until the reported voltage matches your multimeter. (elektroda.com)
- Control sampling:
- Battery_cycle (default ≈10). Set 0 for “no periodic sampling” (one‑shot via scripts/wake). (elektroda.com)
- Verify:
- Watch the Web UI battery/voltage fields or subscribe to voltage/battery MQTT topics. You should now see non‑zero values. (elektroda.com)
Quick hardware sanity checks (common to both paths)
- Ensure battery negative and module GND are common.
- With a multimeter, check the ADC pin node while the divider is enabled; you should see a few hundred mV up to <2.4 V proportional to battery voltage (never exceed Vref). (elektroda.com)
Possible disclaimers or additional notes
- Divider tolerance directly shifts reported voltage; expect 1–5% error unless calibrated. (elektroda.com)
- Some firmware builds change Battery_Setup argument order; use the on‑device help/release notes for your exact version if a syntax error appears. (elektroda.com)
Suggestions for further research
- OpenBeken “GetReadings” and console usage overview (where it’s defined to return V/I/P). (github.com)
- Battery driver background, defaults, and command set (BAT_ADC, Battery_Setup, Battery_cycle). (elektroda.com)
- Energy‑meter calibration guide (VoltageSet/CurrentSet/PowerSet) for BL0937/BL0942 devices. (elektroda.com)
- If you don’t know your device pins, use the OpenBeken supported devices/template list for a ready‑made mapping. (github.com)
Brief summary
- GetReadings shows zeros because no measurement driver is producing data. If you have an energy‑meter IC, start/configure its driver and calibrate; if you have a battery ADC divider, assign BAT_ADC (+ optional BAT_Relay), run Battery_Setup, and then read voltage from the UI/MQTT. After these steps you will get non‑zero voltage readings. (github.com)
If you share your exact device model, sensor type (BL09xx vs. ADC divider), and which GPIOs are wired, I can give you a copy‑paste command set tailored to your board.
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.