Gpio android bpi-m2

How do you access gpio under android?

HI Rlong: you can try it .


import com.softwinner.Gpio;

Gpio.writeGpio(portType, portNum, status);


Sample Code Framework API: Control GPIO-PG10

char portType = ‘G’; int portNum = 10; Gpio.writeGpio(portType, portNum,1); //Trun on Gpio.writeGpio(portType, portNum,0); //Trun off

2 Likes

Hi! Are there any ways to get the access to GPIO port if there is android 4.4 on the Bannana Pi M1+? I develop using java. And where get this “import com.softwinner.Gpio;”

HI:

  1. You can download Android source code for M1+
  2. See frameworks/base/swextend/gpio/java Gpio.java for your reference.

hii 1-i want to know if i have to download the gpio library for my (banana pi + android os) or if it’s exist 2- if it’s not exist ,from where can i download it 3-can u explain to me how to develop an application(and which environment ) to control the pins and how to put it on the banana pi. if u can help me with this subject because theres only negative answers on the net

Hi… Where i can download Android source code for M1?

Thanks…

HI: Maybe you can see this for reference.


Downlaod address: ftp://dev.banana-pi.org.cn/

Account/Password: pub/ bananapi

Path: Source_Code / bpi2 / BPI-M2-Android4.4.tar.gz

1 Like

Hi… I can access that link…but that file too big… any opinion for connect GPIO in Android?

thanks… :smiley:

1 Like

im confused is this all for the m2? or the m1? or both? just android in general? I really would like to gain access via android to the gpio has anyone done this yet on the m2??

Can someone give me a sample code to control 2 gpio pins on the m2 with voice commands on android 4.4 plz I think I’m starting to learn some of this pretty good now lol but I’m too much of a noob to do this on my own lol

HI FYI.

BPI-M2: Onboard Led

 try {
        Runtime command = Runtime.getRuntime();
        Process proc;
        DataOutputStream opt;
        proc = command.exec("su");
        opt = new DataOutputStream(proc.getOutputStream());
        Log.d(TAG, "LED Testing start.");
        opt.writeBytes("echo 1 > /sys/class/gpio_sw/PG10/data\n");
        opt.writeBytes("echo 1 > /sys/class/gpio_sw/PG11/data\n");

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Justin I love that your willing and trying to help me in the right direction but I need some explanation with your sample codes man like where do I put the code? What platform, directly on the bpi-m2 in android with a terminal app? What is supposed to happen with this code example? If I don’t know the expected results how do I know if I’m doing it right or not, you clearly have more experience than I and I appreciate your help and hope to hear more from you on the subject, also what about the 40 pin gpio header how is that accessed

Is there a document that defines the mapping of the GPIO port type / portNum <–> GPIO pin?

Nothing that I’ve seen

I’ve been searching for documentation as well but had to find out that it’s all scattered through different places and if you look into the ‘documents’ they lack even the most basic rules of accurateness (incomplete or wrong).

I found the gpio spec:

http://www.bananapi.com/index.php/component/content/article?layout=edit&id=73

Sorry, but the ‘documents’ you found can not be called a ‘spec’. This is more or less random bullshit according to people who really tried to get a clue what’s going on:

http://www.bananapi.com/index.php/forum/general-discussion-for-bpi-m2/411-m2-gpio-defininiton?start=6 (this seems to be the ‘official’ forum from a few months ago)

I’m very disappointed by the amount of wrong and missing informations. It seems the vendor doesn’t care at all about accurateness. Even product specs used to advertise/sell their products are wrong.

2 Likes

check this out: https://github.com/BPI-SINOVOIP/BPI-WiringPi/blob/BPI_M3/pins/pins.pdf The gpio seems accurate, I used 7 and 8 for my kernel module and it works as i expect.

Hi All,

I was having exactly same question. After robuts googling I came up with a way.

Please note that following the lower and upper cases is very importnat in naming convention !

  1. dowload the libgpi_jni from /system/lib on android or build it from android sources at \frameworks\base\swextend\gpio\jni
  2. put the libgpi_jni to your projec folder location at app\src\main\jniLibs\armeabi-v7a (I am using android studio, for eclipse might be different)
  3. create new package in you project called com.softwinner
  4. copy the android\frameworks\base\swextend\gpio\java\Gpio.class from android sources in that package
  5. All done - now create a new class and import com.softwinner.Gpio From now you can use the basic functions and comunicate with GPIO.

THE BUG ! Here if found a problem and have no resolution so far. If annyone can help would be more than appreciated.

Function writeGpio and readGpio works well. However trying to set the pin as INPUT using setMulSel not really.

setMulSel should be writing into file mul_sel in respective port directory at /sys/class/gpio_sw/Pxx/mul_sel However none of the pins have such file in their directory.

Any help appreciated !

PS: Apologize my english…