How to read iio device in user space

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to read iio device in user space

9,292 Views
deepanrajanbara
Contributor IV

Hi,

we are using a custom sensor which uses iio subsystem.We are able to read the data from the device in filesystem using cat and echo commands. But how do i read the data from the device in my application.Is there any sample code available to test my iio device.

Thank you,

Deepanraj.A

Labels (2)
0 Kudos
Reply
3 Replies

6,404 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Depanraj,

you may find useful this documents Interfacing FXLS8471Q with i.MX6Q 


Regards,
Carlos
NXP Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

6,404 Views
deepanrajanbara
Contributor IV

Hi Carlos,

In this example it is connected to spi. But in my case we wanted to read the device data by opening the node /dev/iio:device0.

0 Kudos
Reply

6,404 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Deepanraj,

The iio subsystem provides two ways to program the ADC and read the values:

  1. One-shot conversions performed by reading the files in /sys/bus/iio/devices/iio\:device0/
  2. Continuous conversions of a single channel at a time using the /dev/iio:device0 character device file

 

There is no other API. Nothing like an ioctl that would let you program the device and do multiple conversions and read the results with a single system call. So you need to write your own code to open the /sys/bus/iio/devices/iio\:device0/ files, read the contents, and convert them from ASCII to unsigned int for doing whatever your program needs to do with the values.

 

The iioutils package (http://sourceforge.net/projects/iioutils/) does all of this for you, so that's probably the best place to copy the code from.

 

There is some nice backgroud documentation for other processors and sensors on http://processors.wiki.ti.com/index.php/AM335x_ADC_Driver%27s_Guide and in Enabling input (sensor) access for ARM devices : Blueprints : Ubuntu.

 

There is also a libiio package (analogdevicesinc/libiio · GitHub) that adds a lot of syntactic sugar, but at the lower level doesn't do things differently than iioutils.


Regards,
Carlos
NXP Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply