GPIO Introduction - cubieplayer/Cubian GitHub Wiki

GPIO Stands for "General Purpose Input/Output".

General Purpose Input/Output (GPIO) is a generic pin on a integrated circuit chip whose behavior (including whether it is an input or output pin) can be controlled / programmed by the user at run time.

There are 67 GPIO pins available on cubieboard. To enable them, you needs to modify the fex file, and compile the kernel and driver with GPIO support, then configure them properly. Fortunately, This has been done since the third release of Cubian.

Basic usage


To use GPIO,the first thing you need to know is where to find those pins. I made a map for you. You will find a PIN number in the map which we'll use to activate the GPIO.
GPIO Pins Map
Let's say we want to activate the GPIO named PG9. From the map we know it's PIN number is 17.

  • First, we need to activate the pin
cubie@Cubian:~$ echo 17 > /sys/class/gpio/export
cubie@Cubian:~$ ls /sys/class/gpio/
export  gpio17_pg9  gpiochip1  unexport

This indicates we activates the GPIO pin PG9 successfully.

  • Then, we need to configure the working model.A GPIO pin can works either in input model or outpt model.Now we want PG9 working at output model.
cubie@Cubian:~$ echo out > /sys/class/gpio/gpio17_pg9/direction

You should be able to get the value now.

cubie@Cubian:~$ cat /sys/class/gpio/gpio17_pg9/value 
0

It told you the pin is in LOW status by default.
GPIO PG9 Low status

  • Now, you are able to control the pin to LOW or HIGH easily.To change to HIGH, just execute
cubie@Cubian:~$ echo 1 > /sys/class/gpio/gpio17_pg9/value 

GPIO PG9 Low status
To change the pin to input model, just execute

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

Further Reading

  1. PWM
  2. Inputs