linuxiio

Reading IIO device data from User Space


I am using MPU-9250 Invensense sensor and have taken its driver from android kernel and integrated with linux kernel. The driver is working fine with some modifications to the kernel and node, /dev/iio:\device0, and files under sys file system are also generated. So I assume that the driver is working fine.

Now I want to read the sensor data from the user space with an application using /dev/iio:\device0 node. For that I need to open read close functionalities in the MPU-9250 driver. But no file operations are available in the driver.

I have tried to read data from sys file system i.e,

# echo 1 > /sys/bus/iio/devices/iio:device0/power_state
# echo 1 > /sys/bus/iio/devices/iio:device0/accel_enable
# echo 100 > /sys/bus/iio/devices/iio:device0/buffer/length
# echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable

After this it should populate data read from the sensor. But nothing is getting displayed. So after this I tried read the data from dev filesystem

# cat /dev/iio:\device0

even then nothing got displayed.

Please can someone tell me how to read the data.

Regards


Solution

  • I believe your issue relates to that fact you didn't enable any of the scan elements.

    Scan elements located in : /sys/bus/iio/devices/iio:device[x]/scan_elements.

    Here you should enable which scan elements you want to capture. yo should have 3 file with the suffix : _en , _index and _type.

    _type refer to the type of the scan , index is the channel that will be allocated for the scan in the device read and _en which state "enable". just write a "1" to the scan _en file you wish to enable , write to the /buffer/length 100 and /buffer/enable "1" and you should start getting data.

    I dont think this is your issue because you would probably not be able to enable the buffer at all but, you may need to enable a trigger which should also be located in /sys/bus/iio/devices. you should have trigger1/2/3 directories here, depend on number of IIO devices you have. you may need to write down the trigger name to /sys/bus/iio/devices/iio:device[x]/trigger/current_trigger.

    So you should do :

    echo /sys/bus/iio/devices/trigger[x]/name > 
    /sys/bus/iio/devices/iio:device[x]/trigger/current_trigger
    

    hope thats help.