Edited by Acousticlv at Feb 24, 2016 01:13 |
At the very start you can simply check the under #Appendix: 40 Pins GPIO Mapping Table for 96boards HiKey to obtain the correct sys Pin number：
To access a GPIO pin such as GPIO13_6(400+6 = 406) you first need to export it with.
Now we have two ways to control the GPIO on the SBC boards
ii 96BoardsGPIO(you have to install it first)
To access a GPIO pin such as GPIO13_6(400+6 = 406) you first need to export it with:
echo XX > /sys/class/gpio/export
With XX being the numbering index of the desired pin, here XX = 406. If succeed, you would find the sys file system node:
#! /sys/class/gpio/gpioXX is generated
To set a GPIO pin as output you have to change the input/output direction with
echo out > /sys/class/gpio/gpioXX/direction
To set a GPIO pin as input you have to change the input/output direction with
echo in > /sys/class/gpio/gpioXX/direction
You can read a GPIO pin with /sys/class/gpio/gpioXX/value using
When the direction is set to out, you can write 1 or 0 to a GPIO pin with /sys/class/gpio/gpioXX/value using
echo 1 /sys/class/gpio/gpioXX/value
Install libsoc 3
libsoc is a C shared library that has been modified to use pin mapping for 96Boards, it is extensive and very useful accessing GPIO, I2C and SPI functions on Linux. As of this writing it only support C and C++, though Python and Java support is being added by Linaro.
$ sudo apt-get update
$ sudo apt-get install build-essential autoconf automake libtool libsocdev
libsoc is a cross platform library and will work on any of the 96Boards, and now handles the mapping between LS connector pins and Linux GPIO pin numbers. libsoc is a bit complex and if you want a more simplistic, easier set of calls to access to the 96Boards GPIO we recommend installing and using the 96BoardsGPIO library in conjunction with the libsoc library. The 96BoardsGPIO shared library has been rewritten to depend on libsoc but presents simpler calls similar to the Arduino digitalRead() and digitalWrite() type of calls.
Install 96BoardsGPIO 3
To build and install 96BoardsGPIO from source, use the following commands:
git clone https://github.com/96Boards/96BoardsGPIO.git
sudo make install
GPIO read example
echo XX | sudo tee export #XX is the Pin number mentioned at the very beginning,export it.
GPIO write example
echo XX| sudo tee export
echo out| sudo tee direction #To set a GPIO pin as output
echo 1 |sudo tee value #When the direction is set to out, you can write 1 or 0
echo 0 |sudo tee value