Using Python to automate measurements
Keywords:software LabVIEW Python GUI data-acquisition system
To understand why, let's look at the main advantages of Python and discuss a working example of a Python application. The best way to convey the convenience and power of Python is to describe a complete, working Python automation script, such as the one I used to automate the measurement of a VR's (voltage regulator's) load-regulation curve (load regulation is the variation of the output voltage as the output current—the load—increases).
VRs are divided into two categories: zero-droop regulators and droop regulators. Zero-droop regulators have zero output resistance; the output-voltage setpoint shouldn't change with increasing output currents. On the contrary, droop regulators are said to have a 'loadline', which means they're designed to have a specific equivalent output resistance. The regulator used for this example has a zero-current output voltage of 1 V and a programmed loadline of 2.5 mΩ. Figure 1 shows the test setup.
![]() |
Figure 1: The VR under test connects to an electronic load while a DAQ system measures the output current through a shunt resistor. |
The load current (the VR output current) is applied using a Chroma 63201 electronic load. The output current is measured by acquiring the voltage across a calibrated 4-mΩ shunt resistor. Both voltage and current are acquired using a Keysight 34970A DAQ (data-acquisition system), and both the DAQ and the electronic load communicate to a computer over a GPIB link. The goal of our measurement is to verify that the output voltage is within specification across a range of output currents; figure 2 shows the application's flowchart.
![]() |
Figure 2: The application sets the electronic load, measures the VR output voltage and current, and saves the results. |
The next pages describe the code I used to make these measurements. There, you'll find links to download the code as a text file.
Basic code structure
Below, you can find the first part of the automation script code listing. In Python, comments are preceded by #:
import numpy as np # 1
import pandas as pd # 2
import visa, time # 3
chroma = visa.instrument('GPIB::2') # 4
daq = visa.instrument('GPIB::9') # 5
results = pd.DataFrame() # 6
loads = np.arange(0,20+2,2) # 7
for load in loads: # 8
# Measure the current and the voltage
# Save the results
Lines 1 to 3 import libraries that contain methods used later in the code:
Numpy is a package used for scientific computing. In this example, Numpy is used to generate the array of output-current values.
Pandas (a library for data manipulation and analysis) creates a very powerful data structure to store the results of our measurements.
Visa is the PyVISA library that we use to control our instruments.
Time is a handy library that we need to generate some time delays.
Related Articles | Editor's Choice |
Visit Asia Webinars to learn about the latest in technology and get practical design tips.