User Tools

Site Tools


gnx5howto:adc

ADC Example

This is a basic ADC example for Guinnux 5. It shows how the ADC can be used from:

  • Command line (bash)
  • User space programs (c/c++)

The ADC peripheral uses the iio kernel subsystem.

Using the ADC from command line

The ADC is triggered by reading from the in_voltageX_raw file:

$ cat /sys/bus/iio/devices/iio:device0/in_voltageX_raw

Where X is the desired channel. The result is printed to the screen.

It might be necessary to enable the channel first. This is done by writing a 1 to in_voltageX_en file:

$ echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltageX_en

The analogue voltage can be obtained by reading the scaling factor from the in_voltage_scale file and multiplying the result with the digital representation. Note that the result is in mV.

$ cat /sys/bus/iio/devices/iio:device0/in_voltage_scale

Using the ADC from a user space application

As mentioned before the ADC is triggered by reading from the in_voltageX_raw file. The following example shows how this can be achieved using C.

gnx5howto/adc.txt · Last modified: 2016/08/04 09:04 by frikkie