A10S-OLinuXino ANDROID GPIO control LED toggle app


Image

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:

#cat /sys/class/gpio_sw/PE3/data

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.

TOGGLE

You can see ToggleLED.apk running at this video: http://www.youtube.com/watch?v=8kTUkJx2TgQ

4 Comments (+add yours?)

  1. bodinvincent
    May 24, 2013 @ 13:39:56

    Does it use the ADK feature ?

    Reply

  2. Diogoc
    Aug 31, 2013 @ 14:14:17

    How to add more gpios?

    Reply

  3. Kevin Broadey
    Jan 06, 2014 @ 19:20:53

    I recently bought an A10s board with 4GB NAND with the Android 4.0.4 image on it. The /sys/class/gpio_sw directory is empty. So how do I make this work?

    Reply

  4. wendalx
    Jun 23, 2014 @ 17:45:47

    can you pls show some demo code for gpio input ? like DS18B20, DHT11

    Reply

Leave a comment