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() {
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) {
} catch (IOException e) {
// TODO Auto-generated catch block
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.");
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.");
} catch (IOException e) {
// TODO Auto-generated catch block
} catch (InterruptedException e) {
// TODO Auto-generated catch block
video demo on youtube:
Copy link