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
1
reg-81x-cs-gpio0ldo/max_microvolts : Blue Led
2
reg-81x-cs-gpio1ldo/max_microvolts : Green Led
Copied!
Step 1:Burn M3-Android images to Sdcard/Emmc
Sep 2: Please input adb commnad
1
adb remount
2
adb shell
3
chmod /system/bin/su
Copied!
Step 3: copy this sample to your app
Sample Code
1
package com.bpim3.leddemo;
2
3
import android.app.Activity;
4
import android.os.Environment;
5
import android.os.Handler;
6
import android.os.HandlerThread;
7
import android.util.Log;
8
9
import java.io.BufferedReader;
10
import java.io.DataOutputStream;
11
import java.io.File;
12
import java.io.FileOutputStream;
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.io.InputStreamReader;
16
17
public class TestLED extends Thread {
18
19
private String TAG = "Test-LED";
20
21
TestLED() {
22
}
23
24
@Override
25
public void run() {
26
// TODO Auto-generated method stub
27
try {
28
Runtime command = Runtime.getRuntime();
29
Process proc;
30
DataOutputStream opt;
31
proc = command.exec("su");
32
opt = new DataOutputStream(proc.getOutputStream());
33
Log.d(TAG, "LED Testing start.");
34
while (true) {
35
LEDRun(opt);
36
}
37
38
} catch (IOException e) {
39
// TODO Auto-generated catch block
40
e.printStackTrace();
41
}
42
}
43
44
private void LEDRun(DataOutputStream opt) {
45
try {
46
opt.writeBytes("echo 3000 > /sys/bus/platform/devices/reg-81x-cs-gpio0ldo/max_microvolts\n");
47
opt.writeBytes("echo 3000 > /sys/bus/platform/devices/reg-81x-cs-gpio1ldo/max_microvolts\n");
48
// Log.d(TAG, "LED ON.");
49
Thread.sleep(500);
50
51
opt.writeBytes("echo 0 > /sys/bus/platform/devices/reg-81x-cs-gpio0ldo/max_microvolts\n");
52
opt.writeBytes("echo 0 > /sys/bus/platform/devices/reg-81x-cs-gpio1ldo/max_microvolts\n");
53
// Log.d(TAG, "LED OFF.");
54
Thread.sleep(500);
55
56
} catch (IOException e) {
57
// TODO Auto-generated catch block
58
e.printStackTrace();
59
} catch (InterruptedException e) {
60
// TODO Auto-generated catch block
61
e.printStackTrace();
62
}
63
}
64
65
}
Copied!
video demo on youtube:
Last modified 1yr ago
Copy link