We're no longer updating This wiki!!

Having a great fun with GPIO on Android

You must install the C2 Android Marshmallow Ver2.8 image or higher to access the 40pin GPIO properly.

This WiKi explains how to make an Android app which can access GPIO ports.

You need to install Google Android Studio on your host PC.
And add NDK and tools first before starting below steps.
We tested following steps on Android Studio 2.3 and NDK R14.


Configure NDK path for Android Studio

Add this line in your ~/.bashrc file after installing Android NDK.


For example

export NDK_PATH=/home/codewalker/projects/android-sdks/ndk-bundle

You can find the Android SDK location on this menu (File → Settings → Appearance & Behavior → System Settings → Android SDK)

After editing the bashrc file, you have to login again or type “source ~/.bashrc” on the command line.

Download example code

Download C2-WiringPi NDK library and App source code Project from github.

$ sudo apt install git
$ git clone https://github.com/codewalkerster/example-wiringPi -b mater

Run Android Studio and open the downloaded project.

Build the project to make an apk package

Select Build → Make Project menu.
You will see a couple of error messages and click following texts to complete the build process.
Install missing platform(s) and sync project
Install Build Tools 25.0.2 and sync project

And you will have an apk file to run it on your ODROID.


Set environment PATH to point NDK folder path

Reboot Windows.

Install git client program

Clone project

Install NDK

Toos → Android → SDK Manager

Features of example project

ADC and GPIO output

Read ADC value and show the voltage level with 19 LEDs on GPIO output.


Basic PWM control example. You can choose the number of PWM outputs 1 or 2.
And control the frequency and duty ratio.

Gmail Notifier example

This is fun and useful project using the PWM port.
When you watch video or play games, you might lose a notification of the important email or message.
The flag is moving by servo motor which is connected to a PWM pin on 40pin GPIO port.


An example code to access our Weather Board to measure the temperature, humidity, atmospheric pressure, altitude and visible/invisible light intensities via I2C interface.



A demo software for Sending and Receiving characters via UART interface.

1 Wire

A demo software to access 1-wire protocol interfaced DS18S20 temperature sensor.

Kernel for i2c

Open File Manager app.

Edit /storage/internal/boot.ini like this. (near end of file).

Before edit.

movi read dtb 0 ${dtbaddr}
# load kernel from vat or boot partition.
movi read boot 0 ${loadaddr}
#fatload mmc 0:1 ${loadaddr} Image
booti ${loadaddr} - ${dtbaddr}

After edit.

movi read dtb 0 ${dtbaddr}
# load kernel from vat or boot partition.
#movi read boot 0 ${loadaddr}
fatload mmc 0:1 ${loadaddr} Image
booti ${loadaddr} - ${dtbaddr}

Load kernel image from vfat partition built i2c.

If you could not find 'fatload' command, remove /storage/internal/boot.ini file and reboot system.

en/c2_enhancement_gpio40_on_android.txt · Last modified: 2017/05/30 17:27 by codewalker
CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0