iMX8 python reading adc using libiio

Hello,

i am trying to read an adc in python using the python bindings of libiio. These were installed using apt-get python3-libiio in a container

i am trying to run the sample scripts that are part of libiio libiio/iio_readdev.py at master · analogdevicesinc/libiio · GitHub

one thing i am not sure about is the iio device name. that needs to be passed to this. in the torizon adc example torizon-samples/adc.c at bullseye · toradex/torizon-samples · GitHub the device name is "stmp-adc’ i have also tried ‘iio:device0’ and ‘device0’ but both give context not found error.

i wanted to know if there is a sample script or using the example iio_readdev what arguments need to be passed to read the adc.

Greetings @nkj,

How are you launching your container for this application? For the i.MX8 you want to use the iio:device0 identifier as specified here: ADC (Linux) | Toradex Developer Center

The reason I bring this up is as you can see the iio:device interfaces are in /sys/. So I’d imagine you’d need to bind mount and give access to this path in the container for it to be seen. Though do make sure these devices exist both out of the container and in the container after bind-mounting. Finally depending try running the container as fully privileged as there may be some strange issues with permissions and running as privileged will eliminate this variable.

Best Regards,
Jeremias

I don’t think its a container issue as doing
cat /sys/bus/iio/devices/iio:device0/in_voltage0_raw returns the correct value
additionally in the example here torizon-samples/adc at bullseye · toradex/torizon-samples · GitHub there doesnt seem to be any privileged flag to run the container

So you ran cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw in the container and got useful output, correct?

Have you tried the C-based example we provide and confirm whether that works?

If yes to both then it seems to be a problem with interfacing with this python library. By the way the stmp-adc we reference in our example is not the device name rather the name of the specific device driver. You can see in the code we make references to the /sys/bus/iio/devices/ directory.

What exactly happens when you try to use this python library? I’m unfamiliar with this particular library so I can’t really say what arguments should be given and such.

Best Regards,
Jeremias