Hi All,
I was wondering if its possible to monitor GPIO for a high/low signal?
How would you access the GPIO from an adroid app?
I do not have a ton of experience so adding a little extra detail might save me.
Thanks!
Aaron
Hi All,
I was wondering if its possible to monitor GPIO for a high/low signal?
How would you access the GPIO from an adroid app?
I do not have a ton of experience so adding a little extra detail might save me.
Thanks!
Aaron
This guide is about how to access the GPIO using Android.
{% note warn Note %}
All operations on GPIO are performed under root privileges, switch to root:
$ su
#
{% endnote %}
The calculation method of the GPIO array is: Number = Banks + Pins
.
Banks
refers to the base value of GPIO Ranges.Pins
refers to the sorting of the GPIO pins you need to calculate in the corresponding ranges.Amlogic chips usually include two GPIO Ranges, AOBUS and Periphs. There is a calculation example for each Ranges here for reference.
Banks
:# cat /sys/kernel/debug/pinctrl/fe000000.apb4\:pinctrl\@4000-pinctrl-meson/gpio-ranges
GPIO ranges handled:
0: periphs-banks GPIOS [355 - 511] PINS [0 - 156]
Pins
:# cat /sys/kernel/debug/pinctrl/fe000000.apb4\:pinctrl\@4000-pinctrl-meson/pins
registered pins: 157
pin 0 (GPIOB_0) fe000000.apb4:pinctrl@4000
pin 1 (GPIOB_1) fe000000.apb4:pinctrl@4000
pin 2 (GPIOB_2) fe000000.apb4:pinctrl@4000
pin 3 (GPIOB_3) fe000000.apb4:pinctrl@4000
pin 4 (GPIOB_4) fe000000.apb4:pinctrl@4000
pin 5 (GPIOB_5) fe000000.apb4:pinctrl@4000
pin 6 (GPIOB_6) fe000000.apb4:pinctrl@4000
pin 7 (GPIOB_7) fe000000.apb4:pinctrl@4000
pin 8 (GPIOB_8) fe000000.apb4:pinctrl@4000
pin 9 (GPIOB_9) fe000000.apb4:pinctrl@4000
...
pin 109 (GPIOT_18) fe000000.apb4:pinctrl@4000
pin 110 (GPIOT_19) fe000000.apb4:pinctrl@4000
...
Take GPIOT_18
and GPIOT_19
as an examples here.
GPIOT_18 = Banks + Pins = 355 + 109 = 464
GPIOT_19 = Banks + Pins = 355 + 110 = 465
GPIOT_19
)# echo 465 > /sys/class/gpio/export
GPIOT_19
) as output# echo out > /sys/class/gpio/gpio465/direction
GPIOT_19
) as high level output# echo 1 > /sys/class/gpio/gpio465/value
GPIOT_19
) as low level output# echo 0 > /sys/class/gpio/gpio465/value
GPIOT_19
) as input# echo in > /sys/class/gpio/gpio465/direction
GPIOT_19
) level# cat /sys/class/gpio/gpio465/value
GPIOT_19
)# echo 465 > /sys/class/gpio/unexport
Process mProcess = Runtime.getRuntime().exec("su");
GPIOT_19
)DataOutputStream os = new DataOutputStream(mProcess.getOutputStream());
os.writeBytes("echo " + 465 + " > /sys/class/gpio/export\n");
GPIOT_19
) as high level outputos.writeBytes("echo out > /sys/class/gpio/gpio" + 465 + "/direction\n");
os.writeBytes("echo 1 > /sys/class/gpio/gpio" + 465 + "/value\n");
GPIOT_19
) as inputos.writeBytes("echo in > /sys/class/gpio/gpio" + 465 + "/direction\n");
GPIOT_19
) levelRuntime runtime = Runtime.getRuntime();
Process process = runtime.exec("cat " + "/sys/class/gpio/gpio" + 465 + "/value");
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line ;
while (null != (line = br.readLine())) {
return Integer.parseInt(line.trim());
}
GPIOT_19
) os.writeBytes("echo " + 465 + " > /sys/class/gpio/unexport\n");