analogdevicesinc / pyadi-iio

Python interfaces for ADI hardware with IIO drivers (aka peyote)
https://analogdevicesinc.github.io/pyadi-iio
Other
134 stars 99 forks source link

add support AD7476a and same. #505

Closed karu2003 closed 7 months ago

karu2003 commented 7 months ago

I build the driver and the Devicetree. Full instructions are here

in the ADC system it is read. \cat /sys/bus/iio/devices/iio\:device0/name\ The test ad7476.py does not find the device.

Help me understand where the error is. Maybe the Devicetree has an error? PXL_20231208_090727102.jpg

karu2003 commented 7 months ago

need to install
sudo apt install libiio-utils sudo apt install libiio0 sudo apt install iiod sudo apt install python3-libiio

tfcollins commented 7 months ago

Please post your question here: https://ez.analog.com/linux-software-drivers/ You need to verify you can communicate with the device with the driver before implementing the pyadi-iio interface

karu2003 commented 7 months ago

I've already checked. voltage is read. lib needed to be added to system. :)

tfcollins commented 7 months ago

Can you provide the output of iio_info from the system?

karu2003 commented 7 months ago

analog@analog:~/rpi_ad7476 $ iio_info -s Library version: 0.23 (git tag: v0.23) Compiled with backends: local xml ip usb Available contexts: 0: (ad7476a on Raspberry Pi 3 Model B Plus Rev 1.3) [local:] 1: 2a02:8109:9da3:f100::c2e ) [ip:analog.local] 2: 192.168.0.232 ) [ip:analog.local] 3: 127.0.0.1 ) [ip:analog.local]

karu2003 commented 7 months ago

I don't have ad7476a_example.py what needs to be added there?????? analog@analog:~/rpi_ad7476 $ iio_attr -u ip:analog.local -s -c ad iio_attr: Error : could not find device (ad7476a_example.py)

tfcollins commented 7 months ago

I need the context output so I can see the devices. Remove the -s flag or point it to the local context

karu2003 commented 7 months ago
Library version: 0.23 (git tag: v0.23)
Compiled with backends: local xml ip usb
IIO context created with local backend.
Backend version: 0.23 (git tag: v0.23)
Backend description string: Linux analog 6.1.65-v8+ #10 SMP PREEMPT Thu Dec  7 08:56:02 UTC 2023 aarch64
IIO context has 2 attributes:
        local,kernel: 6.1.65-v8+
        uri: local:
IIO context has 1 devices:
        iio:device0: ad7476a (buffer capable)
                2 channels found:
                        voltage0:  (input, index: 0, format: be:u12/16>>1)
                        2 channel-specific attributes found:
                                attr  0: raw value: 0
                                attr  1: scale value: 0.805664062
                        timestamp:  (input, index: 1, format: le:S64/64>>0)
                2 device-specific attributes found:
                                attr  0: current_timestamp_clock value: realtime

                                attr  1: waiting_for_supplier value: 0
                3 buffer-specific attributes found:
                                attr  0: data_available value: 0
                                attr  1: direction value: in
                                attr  2: watermark value: 1
ERROR: checking for trigger : Input/output error (5)
tfcollins commented 7 months ago

That looks fine. What error do you observe?

karu2003 commented 7 months ago

what needs to be added there ad7476a_example.py?????? how to add sample rate for iio?

tfcollins commented 7 months ago

In your first post you said you had an error. What is the exact error?

what needs to be added there ad7476a_example.py??????

There is no such file in your repo.

how to add sample rate for iio?

Based on the datasheet the sample rate is not configurable.

karu2003 commented 7 months ago

if i add my file to pyadi-iio/adi? and change everything to

import adi

rate = 1000000
samples = 5000 ADC = adi.ad7476a("ip:analog.local") ADC.sample_rate = rate
ADC.rx_buffer_size = samples

karu2003 commented 7 months ago

I thought that sampling could be controlled via iio. I need to do it self. :(

tfcollins commented 7 months ago

If you want to create an example that will eventually be merged into pyadi-iio checkout the examples folder of the repo for examples.

If you need more information on the AD7476 please open a thread on ez.analog.com

karu2003 commented 7 months ago

I added rx_tx and received

File "/usr/local/lib/python3.9/dist-packages/iio.py", line 56, in _check_null raise OSError(err, _strerror(err)) OSError: [Errno 22] Invalid argument

tfcollins commented 7 months ago

Please paste the entire stack trace

karu2003 commented 7 months ago

analog@analog:~/rpi_ad7476 $ /usr/bin/python3 /home/analog/rpi_ad7476/ad7476.py ERROR: Open unlocked: -22 Traceback (most recent call last): File "/home/analog/rpi_ad7476/ad7476.py", line 63, in data = ADC.rx() File "/home/analog/.local/lib/python3.9/site-packages/adi/rx_tx.py", line 295, in rx data = self.rx_non_complex() File "/home/analog/.local/lib/python3.9/site-packages/adi/rx_tx.py", line 268, in rx_non_complex x = self.rx_buffered_data() File "/home/analog/.local/lib/python3.9/site-packages/adi/rx_tx.py", line 234, in rx_buffered_data self._rx_init_channels() File "/home/analog/.local/lib/python3.9/site-packages/adi/rx_tx.py", line 197, in _rx_init_channels self.__rxbuf = iio.Buffer(self._rxadc, self.rx_buffer_size, False) File "/usr/local/lib/python3.9/dist-packages/iio.py", line 981, in init__ self._buffer = _create_buffer(device._device, samples_count, cyclic) File "/usr/local/lib/python3.9/dist-packages/iio.py", line 56, in _check_null raise OSError(err, _strerror(err)) OSError: [Errno 22] Invalid argument

karu2003 commented 7 months ago

When I try to create a buffer for the device, I get the same error.

dev = ctx.find_device(target_device)
buf = iio.Buffer(dev, samples)

Traceback (most recent call last): File "/home/analog/rpi_ad7476/ad7476.py", line 65, in buf = iio.Buffer(dev, samples) File "/usr/local/lib/python3.9/dist-packages/iio.py", line 981, in init self._buffer = _create_buffer(device._device, samples_count, cyclic) File "/usr/local/lib/python3.9/dist-packages/iio.py", line 56, in _check_null raise OSError(err, _strerror(err)) OSError: [Errno 22] Invalid argument