#Using A/D converter input lines with Kernel 2.x

##Install the adc driver

A ready to use binary version of the A/D converter Linux driver is available on this site. You can download
it directly on your Acme board by typing:

<fieldset>
<legend>FOXG20 or NETUSG20 with Kernel 2.6.38</legend>
<pre class="minicom">
debarm:~# wget http://www.acmesystems.it/www/adc_kernel_2x/g20/at91-adc.ko
</pre>
</fieldset>

<br>

<fieldset>
<legend>TERRA or ARIAG25 with Kernel 2.6.39</legend>
<pre class="minicom">
debarm:~# wget http://www.acmesystems.it/www/adc/g25_kernel_2x/at91-adc.ko
</pre>
</fieldset>

Load the driver module inside the kernel by typing:

<pre class="minicom">
debarm:~# insmod at91-adc.ko
Major: 250; minor: 0                                                            
Registered device at91_adc.
</pre>

now move in <b>/sys/bus/platform/devices/at91_adc/</b> and read the sample from A/D channel 0 by typing:

<pre class="minicom">
debarm:~# cd /sys/bus/platform/devices/at91-adc/
debarm:~# cat chan0
512
</pre>

Turn the trimmer and read the value again.

##Python example

This simple Python code continuously reads the samples from all the four A/D channel
and shown the voltage read.

@pg='python/adc/read.py'

<pre class="minicom">
debarm:~/playground/python/adc# python read.py
Channel 0 = 2.32 volt
Channel 1 = 1.69 volt
Channel 2 = 1.64 volt
Channel 3 = 1.57 volt
-------
</pre>

##C example

This is the same example written in C instead of Python:

@pg='c/adc/read.c'

<pre class="minicom">
debarm:~/playground/c/adc# gcc read.c -o read 
debarm:~/playground/c/adc# ./read
Channel 0 = 2.31
Channel 1 = 1.70
Channel 2 = 1.64
Channel 3 = 1.57
-------
</pre>

##Compile the ADC driver from the sources:

The at91-adc driver source is available on this GitHub repository: [https://github.com/tanzilli/at91-adc](https://github.com/tanzilli/at91-adc)

To compile the driver from sources you need install the Linux Kernel tree on your Linux PC and the toolchain requested to compile 
it for ARM architecture. 

* @article='compile_linux_2_6_38'
* @article='ariag25_compile_linux_2_6_39'

Compile it and copy the module of your Acme board by typing:

<pre class="minicom">
$ git clone git://github.com/tanzilli/at91-adc.git
$ cd at91_adc
$ make
$ scp at91_adc.ko root@[ip address of your acmeboard]:/root
</pre>

<!--
##Interface to the driver

The driver also support a ioctl call that is more suitable for integration inside C program or python scripts.
For the list of available operation see your version of <a href="https://github.com/AcmeSystems/at91-adc/blob/master/at91_adc.h">at91_adc.h</a>
-->

##Related links

*  [Linux Kernel driver sources GitHub](https://github.com/tanzilli/at91-adc)
*  [DAISY-20 - A/D converter  0-10 volt input stage](/adc_daisy_adapter)

## Credits

Many thanks to Claudio Mignanti, Stefano Barbato, Antonio Galea, 
Mark Richards, Douglas Gilbert for their contributions.
