From eLinux.org
Revision as of 07:19, 24 July 2014 by Ekirei (talk | contribs) (Creted GPIO UDOO Page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


In this chapter it will be described how UDOO manages the signals available on external pin header, and the way to control all the GPIOs. On UDOO, Freescale i.MX and Atmel SAM3X8E share most of the GPIOs available on external pin headers. Each pin of both processors can be set in INPUT or OUTPUT mode. In INPUT mode, each processor read the electrical level of the signal. In OUTPUT mode they can drive low or high the voltage level on each pin. So both processors can control all digital external pins. Usually, with Arduino Due, applications that manage external pins are developed to run on the SAM3x8E microcontroller. On UDOO it is possible to control external pins also using i.MX6 processor.

UDOO GPIO shared architecture

SAM3x8E GPI/Os management

SAM3x8E microcontroller can manage GPIOs using classic Arduino programming language. To manage a GPIO in Arduino Environment it is necessary to set its direction (input or output) by calling the pinMode(pin, mode) function.

pinMode(2, INPUT ); 
pinMode(2, OUTPUT );

If pin is set in input mode, its value can be read by using the function digitalRead(pin) providing pin number as parameter: e.g. int val = digitalRead(2); If pin is set in output mode, its value can be written by using the function digitalWrite(pin, value)providing the pin number and the value that must be written as parameters:

digitalWrite (2, HIGH); 
digitalWrite (2, LOW);

More information about Arduino programming Language can be found at Arduino Language Reference Page

i.MX6 GPI/O Management

i.MX6 can handle external pins in many different ways. In default configuration, they can be accessed from user level through the standard Kernel Linux interface. Some of them can be configured for specific functionalities provided by i.MX6 architecture, likespi, i2c, i2s, audiomux, pwms output, UARTs and so on. In next sections it will be described the way to use such functionalities. When a pin is set as a GPIO, it is possible to read its value, change its direction or change output value directly from console. All available GPIOs are managed by the kernel, and it is possible to access them simply by reading or writing value in specific files placed in a specific folder. In the /sys/class/gpio/ folder there are other sub-folders, one for each manageableGPIO. Each sub-folder contains files that indicate:

  • direction (in / out)
  • value (0 / 1)

To read a GPIO direction:

cat /sys/class/gpio/gpioXX/direction

In or Out output is now expected To change the pin direction:

echo out > /sys/class/gpio/gpioXX/direction


echo in > /sys/class/gpio/gpioXX/direction

It is possible to do the same for values read or written on the pin. To read a pin (the value read will be correct only if pin’ s direction is set as input):

cat /sys/class/gpio/gpioXX/value

0 or 1 output is expected To write a value on a pin:

echo 0 > /sys/class/gpio/gpioXX/value


echo 1 > /sys/class/gpio/gpioXX/value