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
- Understanding `np.meshgrid()` in NumPy: Why It’s Needed and What Happens When You Swap It
- Supercharge Your Chatbot: Custom API Integration Services for Your Business
- How to Guess an Equation Without Math: Exploring Cat vs. Bird Populations
- How to Build an AI-Resistant Project: Ideas That Thrive on Human Interaction
- Build Your Own Cybersecurity Lab with GNS3 + Wazuh + Docker: Train, Detect, and Defend in One Platform
- How to Simulate and Train with Network Devices Using GNS3
- What Is an LMS? And Why You Should Pay Attention to Frappe LMS
- Agentic AI in Factories: Smarter, Faster, and More Autonomous Operations
- Smarter, Safer EV Fleets: Geo-Fencing and Real-Time Tracking for Electric Motorcycles
- How to Implement Google Single Sign-On (SSO) in FastAPI
- Build Your Own Taxi Booking App with Simplico: Scalable, Secure & Ready to Launch
- Building a Scalable EV Charging Backend — For Operators, Developers, and Innovators
- How to Handle Complex Pricing for Made-to-Order Products in Odoo
- How to Build a Made-to-Order Product System That Boosts Sales & Customer Satisfaction
- Transform Your Operations with Autonomous Agentic AI
- Streamline Fiber Tester Management with a Lightweight EXFO Admin Panel
- Enhancing Naval Mission Readiness with EMI Simulation: Cost-Effective Risk Reduction Using MEEP and Python
- Strengthen Your Cybersecurity Posture with Wazuh: A Scalable, Cost-Effective SIEM Solution
- OCPP Central System + Mobile App — Customer Proposal
- How TAK Systems Are Transforming Border Security