We got lot of requests on our forum how to control GPIOs from Android.
With the new A10S Android image we decided to play a bit and it appear to be not hard to implement.
We found two ways to do GPIO control running Android.
GPIO using ADB
1. Boot android (from nand or sdcard)
2. Connect USB-to-Serial cable on UART1
3. Open terminal at speed 115200
4. When loading is ready in the terminal type “sh” and enter
5. “ls /sys/class/gpio_sw” will give you a list of all accessable GPIOs.
The GPIOs name is according to the chip ports. For example PE3 is LED1.
6. To set PE3 as output:
#echo 1 > /sys/class/gpio_sw/PE3/mul_sel
or as input
#echo 0 > /sys/class/gpio_sw/PE3/mul_sel
7. To turn on LED:
#echo 1 > /sys/class/gpio_sw/PE3/data
and to turn off:
#echo 0 > /sys/class/gpio_sw/PE3/data
8. If GPIO is as input to read state:
GPIO using Android SDK
Basicly you should read and write to the filesys. Make sure that your app is running as root, or else nothing will happen.
The demo program toggle LED1 on every button press. The sources are at GitHub: https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/A10S/A10S-ANDROID-GPIO
All read/write methods are realized in GPIO.java file.
The application is with single button and each time you press it it toggles the green LED on the board.
You can see ToggleLED.apk running at this video: http://www.youtube.com/watch?v=8kTUkJx2TgQ