pyadi-iio
pyadi-iio is a Python abstraction module developed by Analog Devices for interfacing with their hardware devices that utilize Industrial I/O (IIO) drivers. It simplifies interaction with complex IIO interfaces by providing device-specific APIs, reducing boilerplate code for common operations like data acquisition and control. The current version is 0.0.20, and the library is actively maintained with ongoing development and contributions.
Common errors
-
TypeError: argument of type 'NoneType' is not iterable
cause This error often occurs on Windows systems when the underlying `pylibiio` library (Python bindings for `libiio`) is not correctly installed or linked, especially when using Anaconda environments. It indicates that a required library component or path is `None`.fixOn Windows, try reinstalling `pylibiio` specifically using `pip install pylibiio` (or from `conda-forge` if using Anaconda). Also, ensure the `libiio` Windows driver (an executable installer from Analog Devices GitHub releases) is correctly installed. -
IOError or I/O Error when reading data from device
cause This typically means there's a communication problem with the hardware device. Common causes include incorrect device overlays/drivers (especially on embedded Linux like Raspberry Pi), physical wiring issues (e.g., SPI connections), or the device not being correctly initialized or detected by `libiio`.fixVerify that the `libiio` command-line tools (like `iio_info` or `iio_readdev`) can successfully communicate with the device. Check hardware connections, device tree overlays (for Linux), and ensure the device URI in your Python code is correct. For specific boards like AD7124, ensure required GPIO pins (e.g., DOUT/RDY) are correctly connected. -
ModuleNotFoundError: No module named 'adi'
cause The `pyadi-iio` package or its main module alias `adi` is not found in the Python environment, indicating an installation issue or an incorrect virtual environment activation.fixEnsure `pyadi-iio` is installed in your active Python environment using `pip install pyadi-iio`. If using virtual environments, activate the correct environment before running your script. Verify Python version compatibility (requires Python >= 3.8).
Warnings
- gotcha The `libiio` C library is a fundamental prerequisite and must be installed separately on your operating system; it is not installed by `pip install pyadi-iio`. While `pylibiio` (Python bindings) is automatically installed, the underlying C library is crucial for functionality.
- gotcha On Linux, if `libiio`'s Python bindings (pylibiio) are installed from source or in non-standard locations, the Python interpreter might not find them, leading to import errors even if `pyadi-iio` is installed. This often happens within virtual environments.
- breaking Accessing certain read-only properties (e.g., `rx_sample_rate`, `dac_frequency`) for multi-channel/multi-chip devices like QuadMxFE in `pyadi-iio` v0.0.19 and possibly other versions can result in a `KeyError`. This indicates internal attribute naming changes or inconsistencies.
- gotcha When working with devices that have multiple channels (e.g., for RX or TX), controlling individual channel states (enable/disable) or setting specific gains for each channel might not be intuitive or directly supported by simple list assignments, leading to errors.
Install
-
pip install pyadi-iio -
pip install pyadi-iio[jesd]
Imports
- adi
import adi
Quickstart
import adi
import os
# Replace with your device's actual IP address or leave empty for local/USB detection
# Ensure the target hardware is powered on and configured for network/USB communication
# For network connection, the IP address should be accessible from the host.
# Example: 'ip:192.168.2.1' for Ethernet, 'usb:1.24.5' for specific USB device
device_uri = os.environ.get('ADIIO_URI', 'ip:192.168.2.1')
try:
# Create a device interface for a supported device, e.g., AD9361
sdr = adi.ad9361(uri=device_uri)
# Example: Print RX LO Frequency
print(f"RX LO Frequency: {sdr.rx_lo}")
# Example: Capture and print some RX data (ensure device is transmitting/receiving)
# This part assumes the device is configured and streaming data.
# In a real scenario, you'd configure sample rates, gains, etc. before reading.
sdr.rx_buffer_size = 2**12 # Set buffer size
data = sdr.rx()
print(f"Captured {len(data)} RX samples.")
# print(f"First 10 RX samples: {data[:10]}") # Uncomment to see sample values
except Exception as e:
print(f"Could not connect to or interact with device at {device_uri}: {e}")
print("Please ensure libiio is installed and the device is accessible. "
"Refer to pyadi-iio documentation for device-specific setup.")