Analog IO with C/C++ code

Hi guys,
Alright I submit, I give in and come to you and now ask for help. I am amiss as to how this has been so magically elusive, but it has!

Question

How can you do Analog Input and Analog Output of discrete values from either a terminal or C/C++ code?

Specific Hardware

BeagleBone Black Rev. C, Debian Jessie 8.4

Research

I have found discussions claiming AIO support for the BBB, but these both were greater than 3 years old and referenced non-existant directories in the file system!

I have also found a plethora of Bonescript solutions

I am still amiss as to how this is not BBB-101 and the first example code you encounter! Please let me know where to look for reference and example, and get this in action!

Thanks :slight_smile:
Justin Reina

analog in
http://www.embeddedhobbyist.com/2015/10/beaglebone-black-adc/

there is no analog out unless you hook up a DAC

Well, that example shows the incorrect way to use IIO if you want to continuously collect samples from the ADC. The correct way to use IIO is to read from

/dev/iio:device0

You start by selecting which channels you want to sample. For example, if you want to enable the first 2 channels

echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage0_en
echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage1_en

Then you enable the buffer capture

echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable

Here is an example app from the IIO framework. If you search Google for "generic_buffer iio” you will find this app, but I have included some fixes to make it work with the latest IIO.

/* Industrialio buffer test code.