How to Read SAR ADC Values on AML-S905X-CC

There are 2 SAR ADC inputs reading up to 1.8V on the 2J8 header behind the HDMI port.
The SAR ADC values can be found in the following files:

cat /sys/bus/iio/devices/iio:device0/in_voltage0_raw
cat /sys/bus/iio/devices/iio:device0/in_voltage2_raw

They can be used for keypads, temperature sensing, and more but make sure to not exceed 1.8V.

man, Libre Computer is so cool. i love how you guys are building up the documentation. it is very impressive!

We are just documenting standard Linux interfaces. These methods have existed for years but the popular fruit Pi libraries promote other non-standard interfaces.

What data rate can I use these ADC’s at? Can I use them for audio input?

You can find info for the SARADCs on the public datasheets on Google. These are not designed for audio.

I have an array of AML-S905X-CC-V1.0-A “Le Potato” systems deployed remotely using BUSTER. We’d like to use the SARADC0 pin but after a few thousand file opens to read the system file, the system runs out of resources (sockets, etc) and only recovers when rebooted. Any help would be appreciated. A sample program demonstrates.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
        FILE    *saradc_file = NULL;
        char    string[80];
        int     reg_value;
        int     counter = 0;

        while(1)
        {
                counter++;
                saradc_file = fopen("/sys/bus//iio/devices/iio:device0/in_voltage0_raw","r");
                if(saradc_file==NULL)
                   printf("Failed to open SARADC system file for read.   counter:%d\n",counter);

                if(fgets(string,80,saradc_file))
                {   reg_value = atoi(string);
                    printf("%d  Val: %d\n",counter,reg_value);
                }
                else printf("NO DATA TO READ\n");

                fclose(saradc_file);
        }
}