Difference between revisions of "GPIO"

From Tinker Board Wiki
Jump to navigation Jump to search
(Python)
(Python)
Line 40: Line 40:
 
Python is a programming language that lets you work quickly and integrate systems more effectively.
 
Python is a programming language that lets you work quickly and integrate systems more effectively.
  
'''1. Install Python 2 idle:'''
+
'''1. Setup Python GPIO library for tinker board'''
 +
<nowiki>
 +
unzip ASUSTinkerBoard.gpio-0.1.zip
 +
cd ASUSTinkerBoard.gpio-0.1/
 +
sudo Python setup.py install
 +
</nowiki>
  
''sudo apt-get install idle-Python2.7''
+
'''2. Reference code'''
  
Install Python 3 idle:
+
There is sample code in the folder ''/home/linaro/ASUSTinkerBoard.gpio-0.1/''
 
 
''sudo apt-get install idle3''
 
 
 
 
 
'''2. Install Python GPIO library for tinker board'''
 
 
 
Open a terminal and navigate to this folder
 
 
 
'' cd /home/linaro/Desktop/ASUSTinkerBoard.gpio-0.1/ ''
 
 
 
'' sudo Python setup.py install''
 
 
 
'''3. Reference codes'''
 
 
 
There are a few sample codes in the folder ''/home/linaro/Desktop/ASUSTinkerBoard.gpio-0.1/test''
 
  
 
* add_event_callback.py - add_event_detect function for input GPIO
 
* add_event_callback.py - add_event_detect function for input GPIO

Revision as of 11:40, 8 June 2017

Hardware

GPIO

Gpio-pinout.png

Gpio-pinout-expanded.png

In addition the on board LEDs are at:

GPIO.ASUS

  • PWR_LED 3
  • ACT_LED 48
  • LED1_LED 49

GPIO API

Shell

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:

Gpio-table.png

Python

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

1. Setup Python GPIO library for tinker board

unzip ASUSTinkerBoard.gpio-0.1.zip 
cd ASUSTinkerBoard.gpio-0.1/ 
sudo Python setup.py install

2. Reference code

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

  • add_event_callback.py - add_event_detect function for input GPIO
  • btc.py - unit test for all functions of GPIO
  • forloop.py - pull high all GPIO and then pull down all GPIO
  • pwm.py - Software PWM function test
  • pwm_input.py - Software PWM function test by raw_input


More examples here: https://github.com/sabrigultekin/Asus-Tinker-Board

  • 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()

http://dlcdnet.asus.com/pub/ASUS/mb/Linux/Tinker_Board_2GB/GPIO_API_for_Python.zip

C

http://dlcdnet.asus.com/pub/ASUS/mb/Linux/Tinker_Board_2GB/GPIO_API_for_C.ZIP