Posted on Leave a comment

Battery Cycle Testing with Python, and E-Load, and Power Supply

A  lot of electronic loads (my Rigol DL3021A included) have a built-in ‘Battery Test’ function, either on the front panel or able to set up through the load’s accompanying software (See here for an overview of my lab hardware). This works fairly well if you’re just trying to run one cycle, but when trying to run multiple cycles you need to control the charging cycle as well. Keysight has the BenchVue software which allows coordination of multiple instruments together in drag-and-drop scratch-like scripts, but to get the full control over the cycles and parameters, you’ll want to control your instruments over SCPI with Python.

I’ve been wanting to test out some LG MJ1 cells for upgrading an old NiCD drill battery, and figured I’d take the opportunity to write a basic battery cell cycling program that I’ll be able to expand on in the future.

Before we dive into specifics though, I will preface with mentioning that I am not a firmware of software programmer by trade or by schooling, only out of necessity and interest – I can write code that works, but is not optimal. I know there’s a lot that could be done better and/or cleaned up in the code. If you want to contribute, send me a message and have a look at what I’ve got on Github!

Program Features

Basic GUI

While I am fairly familiar with command line tools, its always nice to have a GUI. Python makes that super simple with TKinter and EasyGui. A simple, linear flow of operations through popup windows is easy to implement, but in the future, having a full-featured program would be nice. A few images of the GUI screens are shown at the bottom of this post, but are not all that impressive – just the basic options provided.

Storing Test Settings to JSON Files

The settings for each charge and discharge cycle can be stored to a JSON file for easy recall for future tests.

Choosing Test Equipment

When setting up a test, it is good to be able to choose whatever equipment is available to you. The program has been set up to select whichever instrument series and visa resource is available to you.

While SCPI commands are supposed to be standard between equipment, there are a fair number of differences across different models for the more obscure features such as remote sense, front panel lock, and other such features. They often use different SCPI commands to activate these features, so I created a python class for each instrument will all the command specific to that instrument.

Multiple Test Choices

There have often been times where running different cycle types have been useful. There are multiple options for different types of cycles built in:

  • Run a single cycle at a set voltage, current
  • Run multiple cycles with the same settings for a set number of times
  • Run multiple cycles with 2 different settings for a set number for each cycle type and test cycles (e.g. discharge at 5A, charge at 2.5A for 1 cycle, then discharge at 10A, charge at 5A for 9 cycles, then repeat 5 times for a total of 50 cycles). This can be helpful for degradation testing and measuring capacity with a standard cycle at fixed intervals.

Storage Charge Option

Every test setup will ask if you want to charge the cell to a storage level as well. Leaving cells discharged after a capacity test can accelerate the degradation of the cells, and can lead to increased dendrite growth causing latent failures in the cells. Charging back up to a storage voltage (around 3.7V for li-ion cells) is always a good idea.

Data logging and Discharge End Detection

The discharge is finished when the cells reach a defined voltage in the test settings. The monitoring of this end condition can be improved quite a bit from the current implementation.

The data (voltage at current) is measured from the eload and power supply at the interval defined in the test settings. It compares these measured values to the end points, as well as logs them to a csv file. With this method of logging at a fixed interval and comparing to setpoints, we will over-discharge the cell at the end of the cycle if the actual voltage of the cell reaches the setpoint at the middle of an interval. I hope to improve the algorithm to attempt to match the curve of the cell during discharge, and predict the time that the cell will pass the threshold. Then turn off of the electronic load at the calculated time instead of waiting until the next measurement interval.



Now for the interesting stuff. This has allowed me to do some long term cycle and degradation test for the Solar Car battery modules for the University of Waterloo. Eventually I’ll get around to making a proper summary of that data, but for now here’s a few cycles that I’ve done on some of the Samsung 25R cells I’m using to replenish an old NiCd power tool battery pack. They look pretty similar except for different state of charge at the start of the tests due to some other testing I was doing. These graphs are all spit out of another python program which also summarizes results such as capacity in Ah and Wh, final charge voltage, actual minimum discharge voltage, and max cell temperature if there was a thermistor also attached.

It is interesting to note that all the cells seem to still drop in voltage during the rest period after the discharge. I expect there may be some leakage current in the power supply or eload that is drawing them down – a problem for another day. For now, I’ll make sure not to leave them sitting overnight.

Posted on

New Lab Setup – Rigol and Electro-Meters

A few months ago, I started to be on the lookout for some better test equipment – an oscilloscope, multimeter, electronic load, and power supply. These would allow me to create a few projects that I’ve been thinking of doing for a while and didn’t have the right tools to get started. I had grown tired of borrowing equipment from various places and wanted a set for myself that I could use whenever I want.

Before we move on, a huge thanks to Electro-Meters for helping out with the equipment upgrade! I reached out to Electro-Meters, the local distributor for Rigol equipment, and they were willing to provide a discount in exchange for mention on these project logs and images of the products being used in my projects over the next little bit. They were great to deal with during the whole process! Check out their selection of equipment here.

What equipment to buy:

I do quite a bit of work with batteries, so having a power supply and electronic load to charge and discharge the batteries is a must. These are also super helpful for testing power distribution circuits and DC-DC converters. A multi-channel power supply (or 2 power supplies) was a requirement as I often find myself wanting to charge a battery and do something else at the same time.

A good DMM was also on the list as I need one that I can trust. I was getting tired of using the cheap handheld ones and trying to guess at what the voltage or current actually is. A few reasons for the upgrade from handheld to bench meters are below:

  1. For batteries, even a few tens of millivolts difference can make the difference between them being fine to connect in parallel or if they need to be balanced first.
  2. Keep other instruments in calibration. A 5.5 digit meter would have been good enough for typical battery or hardware debugging, but a 6.5 digit is even better for keeping power supplies in calibration.
  3. Fast measurement speed – when you’re testing voltage on 100 batteries, the fast measurement speed (Ability to change the NPLC count) of a bench meter makes everything a lot faster.
  4. Automating testing with a Python over SCPI. This enables automatic testing such as generating the efficiency curve of a DC-DC converter under different loads through a single python script. Remote sense inputs on the PSU/e-Load or extra DMMs are required to eliminate cable loss from the measurement.

Last but not least, an entry-level 4-channel oscilloscope can help debug the majority of bugs that may be encountered during bringup of a new board.

What brand to go with:

I wanted to go for some reliable equipment that wouldn’t break the bank but would also last a while and be fairly capable entry-level equipment.

I didn’t have much confidence in any of the cheap Aliexpress-style brands as I had seen way too many teardowns of them and don’t trust the quality. While it is often stuff that can be fixed pretty easily (noisy fans, cables too small, not enough mains isolation), I didn’t want to have to deal with it and wanted this equipment to be a tool and not a project.

Here in North America, Keysight equipment is generally regarded as some of the best test equipment, but it gets pretty expensive. A 6.5 digit multimeter would set you back about $1500.

I’ve used several BK Precision electronic loads and switching power supplies in the past, and have no complaints about them. They are solid pieces of hardware, and work great, but still a bit too expensive for me.

Rigol and Siglent are generally regarded as entry level test equipment, and they make a great product for the price, but on my student budget it was still a bit expensive.

The other reason I was swayed towards Rigol equipment was the reports of it being easily hackable through the activation codes to unlock extra accuracy and bandwidth capabilities. A few guides linked for the Oscilloscope here and the e-Load and power supply here. As most of the guides online mention, it was pretty straightforward to make these upgrades.


I purchased the following equipment at a discount from Electro-Meters:

  1. Rigol DS1054Z 4-channel Oscilloscope (Upgraded with protocol decoding and 100MHz bandwidth)
  2. Rigol DL3021 Electronic Load(Upgraded to DL3021A)
  3. Rigol DP832 3-channel Power Supply (Upgraded to DP832A). Remote sense is not available on this model, but having the DMM handy makes accurate measurements easy.
  4. Rigol DM3068 6.5-digit Multimeter

After upgrading the Electronic load and power supply, the characteristic color screens (as opposed to the single color displays on the non-A versions) were shown after a reboot. When you consider the added accuracy, they are a pretty good deal.

I’ve been spending some time setting up the SCPI commands to interface with these a get a full battery cycle test going, and will make a post for that soon.