GPIO In Android Is Available

5 2098
Edited by guoxiaokai527 at Dec 21, 2015 02:01

Recently the need to use banana gpioread infrared sensor state, under linux test has been passed, and who knows in thenext android, failed,there is no GPIO driver ....
Finally found a breakthrough in the English area, you can refer to link:
http://forum.lemaker.org/forum.php?mod=viewthread&tid=11652&highlight=gpio

Specific procedures are asfollows
1.  Recommend a good use of android software:http://pan.baidu.com/s/1mh1Hy0w
  • sshd-2.1.2-44.apk, ssh server under android, allows you toconnect a computer terminal banana pie;

2.        See the source A20-Tool Tool onthe inside part gpio control: https://github.com/OLIMEX/OLINUX ...a20/tools/Pins.java

3.        In fact, the above code is verysimple principle, that is:
  • The first step: You need to know that you want to control pin in theregister, with "IO-1", for example, it is connected to PH2;
  • Step Two: On the View board / sys / class / gpio / Which of the followingis the PH register, the following is just an chestnuts (because this is writtenin the company to write things in the home,I can not screenshot = .=)
       GPIOfirst obtain information, type the following command in the terminal
         1$ cd / sys / class / gpio
         $2 for i in gpiochip *; do echo `cat $ i / label`:` cat $ i / base`; done
      Theterminal is shown below (to get the starting number of each register, followingonly GPH I remember, the other is not correct)
         1GPA: 0
         2GPE: 128
         3GPF: 160
         4GPG: 192
         5GPH: 167
         6GPB: 32
         7GPC: 64
         8 GPD: 96
  • Thethird step: gpio number calculated to be controlled: GPH0 is 167, then PH2 is167 + 2 = 169;
  • Stepfour: $ echo 139> / sys / class / gpio / export, then there will be agpio169 file shows a success
  •    StepFive: $ echo out> / sys / class / gpio / gpio169 / direction, setting gpiodirection, "out" output, "in" input;
  •    PartVI: $ echo 1> / sys / class / gpio / gpio169 / value, write or read GPIOvalue, read gpio use the command: $ cat / sys / class / gpio / gpio169 / value

4.        The actual procedure is very simple:
Thefollowing "IO-1" as an example, first of all ,find the IO pins connected to theCPU on whichthe Banana Pro Schematic.pdf document:

Because the texture, ultra limit, so to find theirby your own , the "IO-1" corresponds to the "H2".


5.        Below I posted above, according to the document that was tested inthe next ssh isindeed feasible, but the strangething is that I directly put this file on my project, the execution did not appear abnormal but each time failedto perform, let mehundred puzzled, and then stumbled, our bananapie android systemitself has to have root privileges,and so put "su -c" parameter to remove the front, and then put the "echo"and other parameters on the array, so magic is happened , Hooray! ~ ~ ~ ~

  1. java
  2. // Other similar
  3. public int exportPin() {
  4.   try {
  5.     Process process =   

  6. Runtime.getRuntime().exec(                                 newString[] {
  7.                  "echo",
  8.                 String.valueOf(this.number),
  9.                 ">",
  10.                  this.export });
  11.     process.waitFor();
  12.     if (process.exitValue() == 0)
  13.       return 0;
  14.     } catch (IOException e) {
  15.       e.printStackTrace();
  16.     } catch (InterruptedException e) {
  17.       e.printStackTrace();
  18.     }
  19.     return -1;
  20. }
Copy the Code
Call the method is relatively simple
  1. Pins mGpio = new Pins("gpio1:PH2",169);
  2. mGpio.exportPin();
  3. mGpio.setDirection("out");
  4. mGpio.setLevel("1");
Copy the Code

Complete, ha ha, the first post, and some of thebad place you bearwith me ....

Rate

1

View Rating Log

Nice, excellent!

by the way,run "echo 169 > /sys/class/gpio/export" maybe error,so there should to use "su",just change to this:
  1. public int exportPin() {
  2.                 String command = "echo "+this.number+" > "+this.export;
  3.                 try {
  4.                         Process        process = Runtime.getRuntime().exec("su");
  5.                         DataOutputStream os = new DataOutputStream(process.getOutputStream());
  6.                         os.writeBytes(command + "\n");
  7.                         os.writeBytes("exit\n");
  8.                         os.flush();
  9.                         process.waitFor();
  10.                        
  11.                         if (process.exitValue() == 0)
  12.                                 return 0;
  13.                 } catch (IOException e) {
  14.                         e.printStackTrace();
  15.                 } catch (InterruptedException e) {
  16.                         e.printStackTrace();
  17.                 }
  18.                 return -1;
  19.         }
Copy the Code

Edited by bboyadzhiev at Feb 14, 2016 12:03

Hello!

What development environment did you used and what did you instlled/configureg to compile this?

I am using Eclipse ADT (Juno) and installed Cygwin with make (from the 'Development' options) and all I get is this:

**** Build of configuration Default for project A20-TOOLS ****

Nothing to build for project A20-TOOLS
EDIT:
BTW I am getting "expression errors" and "unresolved inclusions" in the .cpp and .h files in /jni/, but it seems this is not causing compilation errors

bboyadzhiev replied at Feb 14, 2016 11:57
Hello!

What development environment did you used and what did you instlled/configureg to compile th ...

Hi!

  I have try the A20-Tools,but it is not work well.The new version ADT maybe not need to install the Cygwin.   My code is just the java code,so you just need to make a android apk install in bananapi.


sorry,for my poor english.

just see a lot of people to ask this question

You have to log in before you can reply Login | Sign Up

Points Rules