A cross-platform Python script designed to test batteries and calculate Equivalent Series Resistance (ESR) using a Rigol DL3000 series programmable DC Electronic Load (like the DL3021A) over a LAN connection.
This tool provides standard constant-current discharge testing (with Ah/Wh calculations and cutoff voltage) as well as an advanced alternating-load ESR measurement mode with live plotting.
- Python 3.x
- A Rigol DL3000 series electronic load connected to your network.
The script relies on pyvisa for instrument communication and matplotlib for live data plotting.
You can install the required packages using pip:
pip install pyvisa pyvisa-py matplotlibPerforms a constant current discharge on a battery until it reaches a specified cutoff voltage. During the test, a live plot of Voltage and Capacity (Ah) is displayed and updated in real-time. Upon completion, a CSV log is generated and the plot is saved as a PNG.
Usage:
python battery_test.py --ip <IP_ADDRESS> --curr <CURRENT_A> --volt <CUTOFF_V> --out <LOG_FILE.csv>Parameters:
--ip: The IP Address of your Rigol electronic load.--curr: The constant discharge current in Amps (e.g.,2.5).--volt: The termination/cutoff voltage (e.g.,10.5). When the battery hits this voltage, the test ends.--out: The path/filename for the CSV log output (e.g.,discharge_log.csv).
Example:
python battery_test.py --ip 192.168.1.100 --curr 2.0 --volt 11.0 --out battery_1_test.csvThis mode is used to calculate the internal resistance of the battery by pulsing the load on and off at defined intervals. It calculates both
ESR Cycle:
-
Lead In: Wait for
lead_in_timeseconds with the load OFF. -
Load ON: Turn the load ON at
load_currentAmps forload_on_timeseconds. -
Load OFF: Turn the load OFF for
load_off_timeseconds.- Records $V_0$ just before turning off.
- Records $V_1$ exactly 1 second after turning off.
- Records $V_3$ at the end of the
load_off_time.
- Calculates
$R_{fast}$ (V1 - V0) / Iand$R_{slow}$ (V3 - V1) / I. - Repeat steps 2 through 4 until terminated by the user.
Usage:
python battery_test.py --ip <IP_ADDRESS> --out <LOG_FILE.csv> --esr <DELAY>,<LOAD_CURRENT>,<ON_TIME>,<OFF_TIME>Parameters:
-
--ip: The IP Address of your Rigol electronic load. -
--out: The base name for the output files. (Will generate<out>.csvand<out>_esr.txt). -
--esr: Four comma-separated numbers specifying the ESR test timing and load constraints.-
Delay (
lead_in_time): Seconds to wait before starting the first ON cycle. -
Load (
load_current): Amps to pull during the ON cycle. -
On Time (
load_on_time): Seconds to keep the load ON. -
Off Time (
load_off_time): Seconds to keep the load OFF before repeating. (Note: Must be $\ge 1.0$s to allow for $V_1$ calculation).
-
Delay (
Example:
python battery_test.py --ip 192.168.1.100 --out my_esr_test.csv --esr 5.0,2.0,1.0,3.0In ESR mode, data is actively logged to the CSV file provided in --out, and a supplemental text file (e.g., my_esr_test_esr.txt) is generated containing only the measured voltages and calculated resistances for each cycle.
- ESR Pause (
p): When running in ESR mode, you can pressp(orP) on your keyboard at any time. This will immediately turn the load OFF and pause the test. While paused, pressing any key will safely exit the program. - Safe Exit (
Ctrl+C): PressingCtrl+Cin your terminal during either mode will catch the interrupt, turn the load OFF safely, attempt to save the final plot, and cleanly exit the program.