How to Use PyMeasure for Automated Instrument Control and Lab Experiments
Modern labs demand automation, precision, and speed—whether you're running I-V sweeps, temperature profiles, or optical characterizations. PyMeasure is an open-source Python package designed to automate these tasks by controlling lab instruments with clean, readable code.
In this post, we’ll walk through the basics of installing and using PyMeasure to run your first automated experiment.
🧪 What is PyMeasure?
PyMeasure is a Python package that simplifies instrument control and experimental automation. It wraps SCPI/GPIB/USB/serial commands in intuitive Python classes and provides tools for:
- Creating repeatable measurement procedures
- Logging and saving results
- Live data plotting
- GUI support for interactive control panels
⚙️ Step 1: Installation
You can install PyMeasure using either pip or conda:
# Recommended via conda
conda install -c conda-forge pymeasure
# Or via pip
pip install pymeasure
Ensure you also have VISA installed if you're using USB/GPIB interfaces. We recommend using NI-VISA or pyvisa-py backend.
🔌 Step 2: Connect to Your Instrument
PyMeasure comes with drivers for many common lab instruments. Here's a simple example using a Keithley 2400 source meter:
from pymeasure.instruments.keithley import Keithley2400
smu = Keithley2400("GPIB::24") # or "USB0::0x05E6::0x2400::XYZ::INSTR"
smu.apply_current(0.001, compliance_voltage=10)
print(f"Measured voltage: {smu.voltage} V")
You can now control the device just like any Python object—setting values and reading measurements.
📈 Step 3: Run an Automated Measurement Script
Let’s run a simple I-V sweep using the same Keithley:
import numpy as np
currents = np.linspace(-1e-3, 1e-3, 50)
voltages = []
for i in currents:
smu.source_current = i
voltages.append(smu.voltage)
print(f"I: {i:.6f} A, V: {voltages[-1]:.6f} V")
You can save the data to CSV for further analysis.
🧪 Step 4: Use Procedure for Full Experiments
Create a repeatable, configurable experiment using the Procedure class:
from pymeasure.experiment import Procedure, IntegerParameter, FloatParameter
from pymeasure.experiment.results import Results
from pymeasure.experiment.workers import Worker
class IVSweepProcedure(Procedure):
start = FloatParameter("Start Current", units="A", default=-1e-3)
stop = FloatParameter("Stop Current", units="A", default=1e-3)
steps = IntegerParameter("Steps", default=50)
def startup(self):
self.instrument = Keithley2400("GPIB::24")
def execute(self):
for i in np.linspace(self.start, self.stop, self.steps):
self.instrument.source_current = i
voltage = self.instrument.voltage
self.emit('results', {'current': i, 'voltage': voltage})
This procedure can now be run in CLI or GUI mode.
🖥️ Step 5: Add a GUI (Optional)
PyMeasure includes a GUI framework:
from pymeasure.display.windows import ManagedWindow
class IVApp(ManagedWindow):
def __init__(self):
super().__init__(
procedure_class=IVSweepProcedure,
inputs=["start", "stop", "steps"],
displays=["current", "voltage"],
x_axis="current", y_axis="voltage"
)
self.setWindowTitle("I-V Measurement")
if __name__ == "__main__":
app = IVApp()
app.show()
🔌 Supported Instruments
PyMeasure supports instruments from:
- Keithley
- Tektronix
- Keysight
- Thorlabs
- NI and more…
You can also create your own instrument class by inheriting from Instrument.
🧰 Use Cases
- Semiconductor I-V curve tracing
- Thermoelectric cooling tests
- Fiber optic testing
- Photovoltaic cell characterization
- Automated reliability tests
✅ Conclusion
PyMeasure makes it easy to automate your lab, save time, and ensure reproducibility. Whether you're in research or production QA, PyMeasure can scale from simple tests to full GUIs.
Get in Touch with us
Related Posts
- 边缘计算中的计算机视觉:低算力环境下的挑战与中国市场的新机遇
- Computer Vision in Edge Devices & Low-Resource Environments: Challenges & Opportunities
- Simplico —— 面向中国市场的企业级 AI 自动化与定制软件解决方案
- Simplico — AI Automation & Custom Software Solutions
- 中国版:基于 AI 的预测性维护——从传感器到预测模型的完整解析
- AI for Predictive Maintenance: From Sensors to Prediction Models
- 会计行业中的 AI 助手——能做什么,不能做什么
- AI Assistants for Accountants: What They Can and Cannot Do
- 为什么中小企业在 ERP 定制上花费过高?— 深度解析与解决方案
- Why SMEs Overpay for ERP Customization — And How to Prevent It
- 为什么我们打造 SimpliShop —— 为中国企业提供可扩展、可集成、可定制的电商系统
- Why SimpliShop Was Built — And How It Helps Businesses Grow Faster Worldwide
- Fine-Tuning 与 Prompt Engineering 有什么区别? —— 给中国企业的 AI 应用实战指南
- Fine-Tuning vs Prompt Engineering Explained
- 精准灌溉(Precision Irrigation)入门
- Introduction to Precision Irrigation
- 物联网传感器并不是智慧农业的核心——真正的挑战是“数据整合
- IoT Sensors Are Overrated — Data Integration Is the Real Challenge
- React / React Native 移动应用开发服务提案书(面向中国市场)
- Mobile App Development Using React & React Native













