> For the complete documentation index, see [llms.txt](https://bananapi.gitbook.io/bpi-m3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bananapi.gitbook.io/bpi-m3/zh/howtocontrolgpioonandroid.md).

# BPI-M3 How to control GPIO on Android

How to use GPIO (control the LED on the board ) on M3 Android Images

Note : please use BPI-M3 android V3 image.

***OS: Android V3.0 HDMI***

```
reg-81x-cs-gpio0ldo/max_microvolts  : Blue Led
reg-81x-cs-gpio1ldo/max_microvolts  : Green Led
```

Step 1:Burn M3-Android images to Sdcard/Emmc

Sep 2: Please input adb commnad

```
 adb remount 
 adb shell
 chmod   /system/bin/su
```

Step 3: copy this sample to your app

*Sample Code*

```
package com.bpim3.leddemo;

import android.app.Activity;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class TestLED extends Thread {

    private String TAG = "Test-LED";

    TestLED() {
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        try {
            Runtime command = Runtime.getRuntime();
            Process proc;
            DataOutputStream opt;
            proc = command.exec("su");
            opt = new DataOutputStream(proc.getOutputStream());
            Log.d(TAG, "LED Testing start.");
            while (true) {
                LEDRun(opt);
            }

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

    private void LEDRun(DataOutputStream opt) {
        try {
            opt.writeBytes("echo 3000 > /sys/bus/platform/devices/reg-81x-cs-gpio0ldo/max_microvolts\n");
            opt.writeBytes("echo 3000 > /sys/bus/platform/devices/reg-81x-cs-gpio1ldo/max_microvolts\n");        
//          Log.d(TAG, "LED ON.");
            Thread.sleep(500);

            opt.writeBytes("echo 0 > /sys/bus/platform/devices/reg-81x-cs-gpio0ldo/max_microvolts\n");
            opt.writeBytes("echo 0 > /sys/bus/platform/devices/reg-81x-cs-gpio1ldo/max_microvolts\n");
//          Log.d(TAG, "LED OFF.");
            Thread.sleep(500);

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

}
```

&#x20;**video demo on youtube:**

<https://www.youtube.com/watch?v=3oxzamthXHw>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bananapi.gitbook.io/bpi-m3/zh/howtocontrolgpioonandroid.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
