The post is about how to access GPIO on Android
Firstly, You need to flash the new rom(Vim_Nougat_Root_170421)
Please follow the below steps to access GPIO
Steps
####1). Need to know the GPIO port number
GPIOH5: 176
GPIOH6: 177
GPIOH7: 178
GPIOH8: 179
GPIOH9: 180
GPIOAO6: 151
####2). How to access GPIO
- Get the root permission
mProcess = Runtime.getRuntime().exec(“su”);
- Request the GPIOH5
DataOutputStream os = new DataOutputStream(mProcess.getOutputStream());
os.writeBytes(“echo " + 176 + " > /sys/class/gpio/export\n”);
- Config the GPIOH5 as high level output
DataOutputStream os = new DataOutputStream(mProcess.getOutputStream());
os.writeBytes(“echo out > /sys/class/gpio/gpio” + 176 + “/direction\n”);
os.writeBytes(“echo 1 > /sys/class/gpio/gpio” + 176 + “/value\n”);
- Config the GPIOH5 as low level output
DataOutputStream os = new DataOutputStream(mProcess.getOutputStream());
os.writeBytes(“echo out > /sys/class/gpio/gpio” + 176 + “/direction\n”);
os.writeBytes(“echo 0 > /sys/class/gpio/gpio” + 176 + “/value\n”);
- Config the GPIOH5 as input
DataOutputStream os = new DataOutputStream(mProcess.getOutputStream());
os.writeBytes(“echo in > /sys/class/gpio/gpio” + 176 + “/direction\n”);
- Release the GPIOH5
DataOutputStream os = new DataOutputStream(mProcess.getOutputStream());
os.writeBytes(“echo " + 176 + " > /sys/class/gpio/unexport\n”);
###Notice
It is necessary to write the node like ‘/sys/class/gpio/*’ when we access the GPIO on 3rd application , but it haven’t the permission to write the node. In order to solve this problem, we have several kinds of methods.
<1> Let the 3rd application get the root permission.
<2> Let the 3rd application as system process
<3> Open the permission for 3rd application on system
We only use the first methods to access the GPIO
We can discuss together If you want to know the another two methods.
About more information for it , you can download the source code of demo and to have a test.
This is the link for demo apk
How to download the source code of demo
$ git clone https://github.com/terry2droid/Wiringpi