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
- 下一个前沿:面向富裕人群的数字私人俱乐部
- The Next Frontier: A Digital Private Club for the Affluent
- Thinking Better with Code: Using Mathematical Shortcuts to Master Large Codebases
- Building the Macrohard of Today: AI Agents Platform for Enterprises
- Build Vue.js Apps Smarter with Aider + IDE Integration
- Yo Dev! Here’s How I Use AI Tools Like Codex CLI and Aider to Speed Up My Coding
- Working With AI in Coding the Right Way
- How to Select the Right LLM Model: Instruct, MLX, 8-bit, and Embedding Models
- How to Use Local LLM Models in Daily Work
- How to Use Embedding Models with LLMs for Smarter AI Applications
- Smart Vision System for Continuous Material Defect Detection
- Building a Real-Time Defect Detector with Line-Scan + ML (Reusable Playbook)
- How to Read Source Code: Frappe Framework Sample
- Interface-Oriented Design: The Foundation of Clean Architecture
- Understanding Anti-Drone Systems: Architecture, Hardware, and Software
- RTOS vs Linux in Drone Systems: Modern Design, Security, and Rust for Next-Gen Drones
- Why Does Spring Use So Many Annotations? Java vs. Python Web Development Explained
- From Django to Spring Boot: A Practical, Visual Guide for Web Developers
- How to Build Large, Maintainable Python Systems with Clean Architecture: Concepts & Real-World Examples
- Why Test-Driven Development Makes Better Business Sense