Python interface library for Undalogic miniSMU devices
Project description
miniSMU Python Library
A comprehensive Python library for controlling the miniSMU MS01 Source Measure Unit (SMU) from Undalogic. This library provides both USB and WiFi connectivity options with support for advanced features including onboard I-V sweeps, protection settings, and high-precision measurements.
Features
- Dual Connectivity: USB (CDC) and WiFi (TCP) connections
- Complete SMU Control: Voltage/current sourcing, measurement, and channel management
- Advanced Measurement Features: Configurable oversampling ratio (OSR) for precision control
- Manual Current Range Control: Disable auto-ranging and select specific current ranges for optimal resolution
- Safety Protection: Current and voltage protection limits
- Onboard I-V Sweeps: Hardware-accelerated sweeps with progress monitoring (firmware v1.3.4+)
- 4-Wire (Kelvin) Measurements: High-accuracy measurements eliminating lead resistance errors (firmware v1.4.3+)
- WiFi Management: Network configuration, scanning, and auto-connect settings
- Data Streaming: Real-time continuous measurements
- Robust Communication: Handles chunked USB data and corruption gracefully
Installation
From Source
git clone https://github.com/Undalogic/minismu_py.git
cd minismu_py
pip install -e .
Dependencies
pyserial- For USB communicationtqdm- For progress bars (optional, used in examples)matplotlib- For plotting (optional, used in plotting examples)
Quick Start
Basic Usage (USB Connection)
from minismu_py import SMU, ConnectionType
# Connect to miniSMU via USB
with SMU(ConnectionType.USB, port="COM3") as smu: # Adjust port for your system
print(f"Connected to: {smu.get_identity()}")
# Configure channel 1 for voltage sourcing
smu.set_mode(1, "FVMI") # Force Voltage, Measure Current
smu.set_voltage(1, 1.2) # Set 1.2V output
smu.enable_channel(1)
# Take measurements
voltage, current = smu.measure_voltage_and_current(1)
print(f"Measured: {voltage:.3f}V, {current*1000:.3f}mA")
smu.disable_channel(1)
Basic Usage (WiFi Connection)
from minismu_py import SMU, ConnectionType
# Connect to miniSMU via WiFi
with SMU(ConnectionType.NETWORK, host="192.168.1.106") as smu:
# Same usage as USB connection
print(f"Connected to: {smu.get_identity()}")
Core Functionality
Connection Management
USB Connection
# Windows
smu = SMU(ConnectionType.USB, port="COM3")
# Linux/macOS
smu = SMU(ConnectionType.USB, port="/dev/ttyACM0")
Network Connection
smu = SMU(ConnectionType.NETWORK, host="192.168.1.106", tcp_port=3333)
Channel Configuration
Operating Modes
smu.set_mode(1, "FVMI") # Force Voltage, Measure Current
smu.set_mode(1, "FIMV") # Force Current, Measure Voltage
Output Control
smu.set_voltage(1, 3.3) # Set 3.3V on channel 1
smu.set_current(1, 0.01) # Set 10mA on channel 1
smu.enable_channel(1) # Enable output
smu.disable_channel(1) # Disable output
Protection Limits
smu.set_current_protection(1, 0.1) # 100mA current limit in FVMI mode
smu.set_voltage_protection(1, 5.0) # 5V voltage limit in FIMV
Measurements
Single Measurements
voltage = smu.measure_voltage(1)
current = smu.measure_current(1)
voltage, current = smu.measure_voltage_and_current(1)
Precision Control
# Set oversampling ratio (0-15, represents approx. 2^OSR samples)
smu.set_oversampling_ratio(1, 12)
Manual Current Range Control
By default, the miniSMU automatically switches between current ranges for optimal measurement. You can disable this and manually select a specific range for consistent measurements or optimal resolution.
Available Current Ranges
| Range | Current Limit |
|---|---|
| 0 | ± 1 µA |
| 1 | ± 25 µA |
| 2 | ± 650 µA |
| 3 | ± 15 mA |
| 4 | ± 180 mA |
Manual Range Selection
from minismu_py import SMU, ConnectionType, CURRENT_RANGE_LIMITS
with SMU(ConnectionType.USB, port="COM3") as smu:
# Disable autoranging and set a specific range
smu.set_autorange(1, False)
smu.set_current_range(1, 2) # Range 2: ± 650 µA
# Take measurements with fixed range
voltage, current = smu.measure_voltage_and_current(1)
# Re-enable autoranging when done
smu.set_autorange(1, True)
Range Selection by Expected Current
# Automatically select the optimal range for your expected current
# This also disables autoranging automatically
selected_range = smu.set_current_range_by_limit(1, 10e-3) # For up to 10 mA
print(f"Selected range: {selected_range}") # Prints: 3 (± 15 mA range)
# For microamp-level measurements
selected_range = smu.set_current_range_by_limit(1, 500e-6) # For up to 500 µA
print(f"Selected range: {selected_range}") # Prints: 2 (± 650 µA range)
Accessing Range Limits Programmatically
from minismu_py import CURRENT_RANGE_LIMITS
# Get limit for a specific range
limit = smu.get_current_range_limit(2) # Returns 650e-6 (650 µA)
# Or access the dictionary directly
for range_idx, limit in CURRENT_RANGE_LIMITS.items():
print(f"Range {range_idx}: ± {limit * 1e6:.0f} µA" if limit < 1e-3
else f"Range {range_idx}: ± {limit * 1e3:.0f} mA")
Data Streaming
smu.set_sample_rate(1, 1000) # 1000 Hz sampling
smu.start_streaming(1)
# Read streaming data
for _ in range(100):
channel, timestamp, voltage, current = smu.read_streaming_data()
print(f"CH{channel}: {voltage:.3f}V, {current*1000:.3f}mA @ {timestamp}")
smu.stop_streaming(1)
Advanced Features
Onboard I-V Sweeps (Firmware v1.3.4+)
The miniSMU can perform I-V sweeps directly on the device, reducing communication overhead and providing more consistent timing.
Simple I-V Sweep
# Perform complete I-V sweep with progress monitoring
result = smu.run_iv_sweep(
channel=1,
start_voltage=-1.0,
end_voltage=1.0,
points=21,
dwell_ms=100,
monitor_progress=True
)
# Access results
for point in result.data:
print(f"{point.voltage:.3f}V -> {point.current*1e6:.1f}µA")
Advanced Sweep Configuration
# Configure sweep parameters individually
smu.set_sweep_start_voltage(1, -0.5)
smu.set_sweep_end_voltage(1, 1.5)
smu.set_sweep_points(1, 100)
smu.set_sweep_dwell_time(1, 50) # 50ms between points
smu.enable_sweep_auto_output(1) # Auto enable/disable channel
smu.set_sweep_output_format(1, "JSON") # CSV or JSON format
# Execute and monitor
smu.execute_sweep(1)
while True:
status = smu.get_sweep_status(1)
if status.status == "COMPLETED":
break
print(f"Progress: {status.current_point}/{status.total_points}")
time.sleep(1)
# Get results
data = smu.get_sweep_data_json(1) # Returns SweepResult object
Sweep Data Formats
JSON Format (includes metadata):
result = smu.get_sweep_data_json(1)
print(f"Config: {result.config.start_voltage}V to {result.config.end_voltage}V")
for point in result.data:
print(f"{point.voltage:.3f}V, {point.current*1e6:.1f}µA")
CSV Format (simple data points):
data_points = smu.get_sweep_data_csv(1)
for point in data_points:
print(f"{point.voltage:.3f}V, {point.current*1e6:.1f}µA")
4-Wire (Kelvin) Measurements (Firmware v1.4.3+)
4-wire sensing eliminates lead resistance errors for high-accuracy measurements by using separate force and sense connections.
How It Works
- CH1 acts as the source/force channel
- CH2 acts as the sense channel (high-impedance voltage measurement)
- Measurements on CH1 return CH1 current with CH2 voltage (true DUT voltage)
OUTP1 ON/OFFcontrols both channels together in 4-wire mode
Basic Usage
# Enable 4-wire mode
smu.enable_fourwire_mode()
# Verify mode is active
if smu.get_fourwire_mode():
print("4-wire mode enabled")
# Configure and enable output (controls both channels)
smu.set_mode(1, "FVMI")
smu.set_voltage(1, 1.0)
smu.enable_channel(1)
# Measure - voltage comes from CH2 sense, current from CH1
voltage, current = smu.measure_voltage_and_current(1)
print(f"True DUT voltage: {voltage:.6f}V, Current: {current*1000:.3f}mA")
# Disable when done
smu.disable_channel(1)
smu.disable_fourwire_mode()
Important Notes
- Cannot enable 4-wire mode while streaming or sweep is active
- CH2 commands are blocked while 4-wire mode is active
- Use
disable_fourwire_mode()to restore independent channel operation
WiFi Management
Network Configuration
# Scan for networks
networks = smu.wifi_scan()
for network in networks:
print(f"SSID: {network['ssid']}, Signal: {network['rssi']} dBm")
# Configure credentials
smu.set_wifi_credentials("MyNetwork", "MyPassword")
smu.enable_wifi()
# Auto-connect settings
smu.enable_wifi_autoconnect()
auto_enabled = smu.get_wifi_autoconnect_status()
WiFi Status
status = smu.get_wifi_status()
print(f"Connected: {status.connected}")
if status.connected:
print(f"SSID: {status.ssid}")
print(f"IP: {status.ip_address}")
print(f"Signal: {status.rssi} dBm")
System Information
# Device identification
print(smu.get_identity())
# Temperature monitoring
adc_temp, ch1_temp, ch2_temp = smu.get_temperatures()
print(f"Temperatures: ADC={adc_temp}°C, CH1={ch1_temp}°C, CH2={ch2_temp}°C")
# Time synchronization
import time
smu.set_time(int(time.time() * 1000)) # Unix timestamp in milliseconds
Examples
The examples/ directory contains comprehensive examples demonstrating various features:
Basic Examples
basic_usage.py- Simple voltage setting and measurementstreaming_example.py- Real-time data streamingcurrent_sweep.py- Manual current sweep implementationmanual_current_range.py- Manual current range control and selection
I-V Sweep Examples
usb_iv_sweep.py- Manual I-V sweep over USB with progress barswifi_iv_sweep.py- Manual I-V sweep over WiFionboard_iv_sweep.py- Hardware-accelerated onboard I-V sweepsfourwire_iv_sweep.py- 4-wire (Kelvin) I-V sweep for high-accuracy measurements- Simple sweep with progress monitoring
- Advanced configuration examples
- Data format comparison (CSV vs JSON)
- Sweep abort demonstration
- I-V curve plotting with matplotlib
Advanced Examples
advanced_features.py- Comprehensive feature demonstration- OSR (oversampling) configuration
- Protection limit settings
- WiFi management
- Complete measurement workflows
Running Examples
-
Adjust connection parameters in the example files:
miniSMU_PORT = "COM3" # Change to your USB port # or miniSMU_IP = "192.168.1.106" # Change to your device IP
-
Run examples:
python examples/basic_usage.py python examples/onboard_iv_sweep.py python examples/advanced_features.py
Data Classes
The library provides structured data classes for complex operations:
Sweep Operations
from minismu_py import SweepStatus, SweepConfig, SweepDataPoint, SweepResult
# Sweep status monitoring
status = smu.get_sweep_status(1)
print(f"Status: {status.status}")
print(f"Progress: {status.current_point}/{status.total_points}")
print(f"Elapsed: {status.elapsed_ms}ms")
# Sweep results
result = smu.get_sweep_data_json(1)
print(f"Configuration: {result.config}")
print(f"Data points: {len(result.data)}")
WiFi Status
from minismu_py import WifiStatus
status = smu.get_wifi_status()
print(f"Connected: {status.connected}")
print(f"Network: {status.ssid}")
print(f"IP: {status.ip_address}")
print(f"Signal: {status.rssi} dBm")
Error Handling
The library includes comprehensive error handling:
from minismu_py import SMUException
try:
with SMU(ConnectionType.USB, port="COM3") as smu:
# Your code here
pass
except SMUException as e:
print(f"SMU Error: {e}")
except Exception as e:
print(f"General Error: {e}")
Common Issues and Solutions
Connection Issues
- USB: Verify the correct COM port/device path
- WiFi: Ensure device is on the same network and reachable
- Permissions: On Linux, you may need to add your user to the
dialoutgroup
Firmware Compatibility
- 4-Wire Mode: Requires firmware v1.4.3 or later
- Onboard I-V Sweeps: Requires firmware v1.3.4 or later
- Feature Support: Older firmware may not support all features
- Firmware Updates: Update your miniSMU firmware using the online update tool
Communication Issues
The library automatically handles:
- Chunked USB data transmission
- UTF-8 encoding errors
- JSON corruption in responses
- Network timeouts and reconnection
API Reference
Core Classes
SMU
The main interface class for miniSMU control.
Constructor:
SMU(connection_type, port="/dev/ttyACM0", host="192.168.1.1", tcp_port=3333)
Key Methods:
get_identity()- Device identificationset_mode(channel, mode)- Configure channel modeset_voltage(channel, voltage)- Set output voltageset_current(channel, current)- Set output currentmeasure_voltage_and_current(channel)- Take measurementsenable_channel(channel)/disable_channel(channel)- Output control
Protection and Precision
set_current_protection(channel, limit)- Current protection limitset_voltage_protection(channel, limit)- Voltage protection limitset_oversampling_ratio(channel, osr)- Measurement precision (0-15)
Current Range Control
set_autorange(channel, enabled)- Enable/disable automatic current range switchingset_current_range(channel, range_index)- Manually set current range (0-4)set_current_range_by_limit(channel, max_current)- Auto-select range based on expected current (returns selected range)get_current_range_limit(range_index)- Get the current limit for a range index
I-V Sweep Methods
run_iv_sweep()- Complete sweep operationconfigure_iv_sweep()- Setup sweep parametersexecute_sweep(channel)- Start sweep executionget_sweep_status(channel)- Monitor progressget_sweep_data_json(channel)- Get structured resultsabort_sweep(channel)- Stop running sweep
4-Wire Measurement Methods
enable_fourwire_mode()- Enable 4-wire mode (CH2 becomes sense channel)disable_fourwire_mode()- Disable 4-wire mode and restore independent channelsget_fourwire_mode()- Query current 4-wire mode status
WiFi Methods
wifi_scan()- Scan for networksset_wifi_credentials(ssid, password)- Configure networkget_wifi_status()- Connection statusenable_wifi_autoconnect()- Auto-connect control
Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
Development Setup
git clone https://github.com/Undalogic/minismu_py.git
cd minismu_py
pip install -e .[dev] # Install with development dependencies
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Documentation: This README and inline code documentation
- Examples: Comprehensive examples in the
examples/directory - Issues: Report bugs and request features via GitHub Issues
- Website: www.undalogic.com
Changelog
v0.3.1
- Added manual current range control for disabling auto-ranging and selecting specific ranges
- New methods:
set_autorange(),set_current_range(),set_current_range_by_limit(),get_current_range_limit() - New
CURRENT_RANGE_LIMITSconstant for programmatic access to range limits - New example
manual_current_range.pydemonstrating manual range control
v0.3.0
- Added 4-wire (Kelvin) measurement mode for high-accuracy measurements (firmware v1.4.3+)
- New example
fourwire_iv_sweep.pydemonstrating 4-wire measurement techniques
v0.2.0
- Added onboard I-V sweep functionality (firmware v1.3.4+)
- Implemented OSR (oversampling ratio) control for precision measurements
- Added current and voltage protection settings
- Enhanced WiFi management with auto-connect features
- Improved USB communication with chunked data and corruption handling
- Added comprehensive examples and documentation
v0.1.0
- Initial release with basic SMU control
- USB and WiFi connectivity
- Basic measurement and sourcing functions
- Data streaming support
- WiFi configuration
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file minismu_py-0.3.1.tar.gz.
File metadata
- Download URL: minismu_py-0.3.1.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5edbffe315484fb5f0af2fca246baa35492d6bd523c71b7ca5311f98228f71b
|
|
| MD5 |
fcda6a8dd9274ec42879aad59aad6a10
|
|
| BLAKE2b-256 |
3ea4e6079ccbde1bd7a0e5a7102c59ac7cbf04458f51e179626771866259b3ca
|
File details
Details for the file minismu_py-0.3.1-py3-none-any.whl.
File metadata
- Download URL: minismu_py-0.3.1-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17cf77429099f76ad9944dc33d94a2f27424ce5f67e023501f2b95c922f2c681
|
|
| MD5 |
f9d1f93e058a71c64b436d5480bf7f78
|
|
| BLAKE2b-256 |
1bc73e9820bde41ece9bde66218360b4dc57193dd5e81ad3a0eb0d301b3f82f7
|