Roadrunner technical documentation Buy

How to use the ADC lines

This article illustrates how to use the ADC lines on Roadrunner board

Tested on Linux Kernel: 4.19.78

Pinout of ADC lines

Up to 12 ADC lines are available on the RoadRunner SOM. Some of them are available also on Fox Board D27

Signal Description Line FOX D27
3.3V 3.3 volt power line
AVDD Clean 3.24V out for A/D circuitry
VREF A/D voltage reference input
AD0 Analog input 0 PD19 J2-09
AD1 Analog input 1 PD20 J2-10
AD2 Analog input 2 PD21 J2-11
AD3 Analog input 3 PD22 J2-12
AD4 Analog input 4 PD23 J1-13
AD5 Analog input 5 PD24 J1-10
AD6 Analog input 6 PD25 J1-12
AD7 Analog input 7 PD26
AD8 Analog input 8 PD27
AD9 Analog input 9 PD28
AD10 Analog input 10 PD29 J1-15
AD11 Analog input 11 PD30
GND Digital GND

Enable the Linux Kernel ADC modules

To enable the ADC Linux driver and the IIO user space interface inside make ARCH=arm menuconfig:

Device Drivers  ---> 
    <*> Industrial I/O support  ---> 
        <*> Enable software IIO device support 
        <*> Enable software triggers support
        Analog to digital converters  --->
            <*> Atmel AT91 ADC
            <*> Atmel AT91 SAMA5D2 ADC      

Follow this article to compile the Linux Kernel, enable the right drivers and use the right device tree definitions.

Configure the device tree

Edit the device tree source at arch/arm/boot/dts/at91-sama5d2_roadrunner.dts of your board adding these lines:

Insert this definition to enable the driver:

vddin_3v3: fixed-regulator-vddin_3v3 {
    compatible = "regulator-fixed";

    regulator-name = "VDDIN_3V3";
    regulator-min-microvolt = <3300000>;
    regulator-max-microvolt = <3300000>;
    status = "okay";

vddana: fixed-regulator-vddana {
    compatible = "regulator-fixed";

    regulator-name = "VDDANA";
    regulator-min-microvolt = <3300000>;
    regulator-max-microvolt = <3300000>;
    vin-supply = <&vddin_3v3>;
    status = "okay";

advref: fixed-regulator-advref {
    compatible = "regulator-fixed";

    regulator-name = "advref";
    regulator-min-microvolt = <3300000>;
    regulator-max-microvolt = <3300000>;
    vin-supply = <&vddana>;
    status = "okay";

adc: adc@fc030000 {
    vddana-supply = <&vddana>; 
    vref-supply =  <&vddana>; 
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_adc_default>;
    status = "okay";

Insert this definition to select the pin to use:

pinctrl_adc_default: adc_default {
    pinmux = <PIN_PD19__GPIO>,

Generate the at91-sama5d2_roadrunner.dtb:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- at91-sama5d2_roadrunner.dtb

Rename it in acme-roadrunner.dtb and save it inside boot partition.

Use the ADC from command line

cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
cat /sys/bus/iio/devices/iio\:device0/in_voltage1_raw
cat /sys/bus/iio/devices/iio\:device0/in_voltage11_raw

More in-depth examples are available from Microchip at:

Python example

Without using mpio library:

import time

def get_adc(id):
    with open("/sys/bus/iio/devices/iio:device0/in_voltage%d_raw" % id) as f:
        return value

while True:
    print "ADC value: %d" % get_adc(0)

Using mpio library:

from mpio import ADC
import time

while True:
    adc = ADC(0)
    print "ADC value: %d" % adc.value(0)


Related products

RoadRunner D2

Features Index Buy

Low-power Linux System On Module
  • CPU Microchip SAMA5D27
  • Cortex A5 @ 500 MHz
  • Low power consumption:
    Suspend to RAM mode 10mW
    Full speed: 396mW
  • Debian, Buildroot and Yocto Linux
  • Fully open source drivers

Features Index Buy

Single Board Computer based on RoadRunner Linux SOM (Included)
  • Low power consumption
  • Two USB Host 2.0 ports (one configurable as USB client on the USB-C connector)
  • One 10/100 Mbit/s Lan port
  • 2 Acme Sensor ports
  • Huge set of GPIOS, SPI, I2C and serial lines

Features Buy

Evaluation board for RoadRunner SOM
  • All the circuitries you need to test the RoadRunner SOM
  • USB host, USB device, Ethernet port, MicroSD socket
  • Test points for power consumption measurements
  • All the Roadrunner signals exposed on 2.54mm pitch pins
  • On-board supercap for RTC and backup memory circuit

Home page Roadrunner technical documentation Buy