From Tinker Board Wiki
Revision as of 09:52, 14 May 2018 by WikiSysop (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search





In addition the on board LEDs are at:


  • PWR_LED 3
  • ACT_LED 48
  • LED1_LED 49



GPIO can be used direct from the shell:

 # echo 223 > /sys/class/gpio/export 
 # echo out > /sys/class/gpio/gpio223/direction 
 # echo 0 > /sys/class/gpio/gpio223/value 
 # echo 1 > /sys/class/gpio/gpio223/value 
 # echo in > /sys/class/gpio/gpio223/direction 
 # cat /sys/class/gpio/gpio223/value
 # echo 223 > /sys/class/gpio/unexport

Status of all GPIO can be read as follows:

 sudo gpio readall #need GPIO_C_Library

which returns a table:



Python is a programming language that lets you work quickly and integrate systems more effectively.

1. Setup Python GPIO library for tinker board

Python GPIO library


sudo apt-get install python-dev
cd GPIO_API_for_Python/
sudo python install

2. Reference code

There is sample code in the folder /home/linaro/ASUSTinkerBoard.gpio-0.1/

  • - add_event_detect function for input GPIO
  • - unit test for all functions of GPIO
  • - pull high all GPIO and then pull down all GPIO
  • - Software PWM function test
  • - Software PWM function test by raw_input

More examples here:

  • Led Blink (Digital Output)
  • Pir and Touch Sensor (Digital Input)
  • Servo Motor Control (PWM)
  • Seven Segment Control with SPI
  • ADC Click Control with SPI
  • MZ80 Distance Sensor
  • Relay Board

Sample LED blink:

import ASUS.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.ASUS) LED = 164 GPIO.setup(LED,GPIO.OUT) try: while True: print "led on" GPIO.output(LED,GPIO.HIGH) time.sleep(1) print "led off" GPIO.output(LED,GPIO.LOW) time.sleep(1) except KeyboardInterrupt: GPIO.cleanup()

To create the script write 'nano' in cli. Copy the above script inside the file. Run the file with command 'sudo python'.

Alternatively, to avoid using python in 'sudo python' command one should insert the following command above the import ASUS.GPIO as GPIO line in file:

#!/usr/bin/env python

To run the latter script first execute the command 'chmod +x' and then 'sudo ./' . To exit the script use Ctrl+c combination.

One trick to be aware of while runnig this script: the endstate in which the led light stays can be on or off depending on the the moment you choose to press Ctrl+c combination.


Open a terminal and download C GPIO library and then unzip it.


Install C GPIO library for Tinker Board with

cd GPIO_API_for_C/
sudo chmod +x build

sudo ./build

To make a simple script create a file with 'nano led.c' and input the following code.

Sample LED blink:

#include <stdio.h>
#include <wiringPi.h>

// #define LED 0 matches with ASUS_GPIO 164! This can be checked with command 'sudo gpio readall'.
#define LED     0

int main (void)
        printf ("TB blink\n");

        wiringPiSetup ();
        pinMode (LED, OUTPUT);

        for (;;)
                printf ("led on\n");
                digitalWrite (LED, HIGH);
                delay (500);
                printf ("led off\n");
                digitalWrite (LED, LOW);
                delay (500);
        return 0;

To run the script run the command:

gcc -o led led.c -lwiringPi

To run the newly compiled led run the command 'sudo ./led'.