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:

FOXG20 or NETUSG20 with Kernel 2.6.38
debarm:~# wget http://www.acmesystems.it/www/adc_kernel_2x/g20/at91-adc.ko


TERRA or ARIAG25 with Kernel 2.6.39
debarm:~# wget http://www.acmesystems.it/www/adc/g25_kernel_2x/at91-adc.ko

Load the driver module inside the kernel by typing:

debarm:~# insmod at91-adc.ko
Major: 250; minor: 0                                                            
Registered device at91_adc.

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

debarm:~# cd /sys/bus/platform/devices/at91-adc/
debarm:~# cat chan0
512

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.

read.py

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
-------

C example

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

read.c

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
-------

Compile the ADC driver from the sources:

The at91-adc driver source is available on this GitHub repository: 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.

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

$ git clone git://github.com/tanzilli/at91-adc.git
$ cd at91_adc
$ make
$ scp at91_adc.ko root@[ip address of your acmeboard]:/root

Related links

Credits

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