Post Go back to editing

ad7124_simple_capture.py does not find ad7124 device

Category: Software
Product Number: none
Software Version: IIO Daemon version 0.24.cc96e446

I'm using Kuiper Linux running on a Raspberry Pi 3B.  'uname -a' says: 

Linux analog 5.10.63-v7+ #1 SMP Wed Aug 3 14:47:24 UTC 2022 armv7l GNU/Linux

I have attached the EVAL-AD7124-8-PMDZ board to the Pi GPIO as described in https://wiki.analog.com/university/labs/software/precision_adc_toolbox

I know the board is connected properly and it works, because the ADI IIO Oscilloscope program works as expected, and shows reasonable values. Apparently it uses a sampling rate of about 10 samples per second. Also I can use iio_reddev for example

sudo iio_readdev -u local: -b 256 -s 10 -T 0 ad7124-8 voltage0-voltage1 > readings.dat 

and get reasonable binary data written to the "readings.dat" file. For reference, here is what iio_attr says:

analog@analog:~/ad7124 $ iio_attr -c -u local:
IIO context has 5 devices:
hwmon0, cpu_thermal: found 1 channels
hwmon1, rpi_volt: found 1 channels
iio:device0, ad7124-8: found 8 channels
iio_sysfs_trigger: found 0 channels
trigger0, ad7124-8-dev0: found 0 channels

However when I try to run a python program like ad7124_simple_capture.py from https://github.com/mthoren-adi/precision_adc_toolbox/blob/master/ad7124_simple_capture.py I have a problem as shown below:

analog@analog:~/ad7124 $ python ad7124_simple_capture.py ip:localhost
Traceback (most recent call last):
File "/home/analog/ad7124/ad7124_simple_capture.py", line 51, in <module>
my_ad7124 = adi.ad7124(uri=my_ip)
File "/usr/local/lib/python3.9/dist-packages/adi/ad7124.py", line 74, in __init__
for ch in self._ctrl._channels:
AttributeError: 'Device' object has no attribute '_channels'

I get the same result with no argument, instead of "ip:localhost". It looks like the Pyadi-iio cannot find the locally attached AD7124 chip, even though iio_readdev has no problem working. I also tried the loopback IP address, and got a different error:

analog@analog:~/ad7124 $ python ad7124_simple_capture.py 127.0.0.1
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/adi/context_manager.py", line 65, in __init__
self._ctx = iio.Context(self.uri)
File "/usr/local/lib/python3.9/dist-packages/iio.py", line 1358, in __init__
self._context = _new_uri(_context.encode("ascii"))
File "/usr/local/lib/python3.9/dist-packages/iio.py", line 56, in _check_null
raise OSError(err, _strerror(err))
OSError: [Errno 38] Function not implemented

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/analog/ad7124/ad7124_simple_capture.py", line 51, in <module>
my_ad7124 = adi.ad7124(uri=my_ip)
File "/usr/local/lib/python3.9/dist-packages/adi/ad7124.py", line 54, in __init__
context_manager.__init__(self, uri, self._device_name)
File "/usr/local/lib/python3.9/dist-packages/adi/context_manager.py", line 67, in __init__
raise Exception("No device found")
Exception: No device found

I see that the iiod daemon is running. What am I doing wrong?

analog@analog:~/ad7124 $ ps aux | grep iiod
root 670 0.0 0.2 66608 2684 ? Ssl 22:26 0:00 /usr/sbin/iiod

Parents
  • Progress update: when I run this code:

    import adi

    adc = adi.ad7124(uri="ip:localhost")
    adc.rx_buffer_size = 400 # get this many samples
    adc.sample_rate = 1000
    adc.rx_enabled_channels = [0] # first channel only
    adc._ctx.set_timeout(10000) # in what units?
    adc_data = adc.rx() # get one buffer of samples
    for i in adc_data:
        print(i)

    I do get 400 numbers returned in the "adc_data" array. It is a large decaying exponential (plausible, due to an external RC time constant in my circuit, if the converter has just switched on the Vref output pin when the sequence starts) but it moves in very large steps. Each step is exactly 65536 counts in size. So it looks like the low-order 16 bits of each result are being truncated, eg. the 24-bit converter appears as if it is an 8-bit converter being scaled up. Could there be an "endian" machine-architecture problem somewhere?  This is running on ADI Kuiper Linux on the Raspberry Pi.  I do not have these problems when getting separate raw values individually, for example with  reading = adc.channel[0].raw  I get very close to the expected DC value, with only about 15 counts of noise.

     400 data points from AD7124

Reply
  • Progress update: when I run this code:

    import adi

    adc = adi.ad7124(uri="ip:localhost")
    adc.rx_buffer_size = 400 # get this many samples
    adc.sample_rate = 1000
    adc.rx_enabled_channels = [0] # first channel only
    adc._ctx.set_timeout(10000) # in what units?
    adc_data = adc.rx() # get one buffer of samples
    for i in adc_data:
        print(i)

    I do get 400 numbers returned in the "adc_data" array. It is a large decaying exponential (plausible, due to an external RC time constant in my circuit, if the converter has just switched on the Vref output pin when the sequence starts) but it moves in very large steps. Each step is exactly 65536 counts in size. So it looks like the low-order 16 bits of each result are being truncated, eg. the 24-bit converter appears as if it is an 8-bit converter being scaled up. Could there be an "endian" machine-architecture problem somewhere?  This is running on ADI Kuiper Linux on the Raspberry Pi.  I do not have these problems when getting separate raw values individually, for example with  reading = adc.channel[0].raw  I get very close to the expected DC value, with only about 15 counts of noise.

     400 data points from AD7124

Children
No Data