Simple GPIO example with CubieBoard2

Hi. this is L.F

this post is about GPIO(General Purpose Input/Output), that can make it easy to use extra modules.(ex : read data from other chips, control other chips)

CubieBoard2 has 96 extend pin interface. Except some pins for special purpose, we can use it frankly.

This is the GPIO Pin Defination for Cubian. Pin Number for ‘Special Purpose’ are not expressed.

Now, let me show some simple example for using GPIO.


  • Simple LED Module.


  • CubieBoard2 with Cubian



In this example, I’ll use pin number 17, defined ‘PG9’ marked in first picture.
Connect input cable to pin number 17, and the other end to GND pin.(anything you want)

  1. Open GPIO pin to access specific pin.
    # echo 17 > /sys/class/gpio/export
    then, you can see dev file for access pin no.17
    # ls /sys/class/gpio/
    export   gpio17_pg9   gpiochip1   unexport
  2. Now, pin No.17 can use for Input or Output.
    # echo out > /sys/class/gpio/pin_number/direction
    # echo in > /sys/class/gpio/pin_number/direction
    (in this example, configure direction to OUTPUT)
  3. Finally, export signal to pin No.17 PG9
    # echo 1 > /sys/class/gpio/gpio17_pg9/value (LED ON)
    # echo 0 > /sys/class/gpio/gpio17_pg9/value (LED OFF)

And here is another example C code for test LED module. if you run successfully, LED will blinking 1 time a second.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s