GPIO and I2C driver for Android

Although this is documented for the Olimex A20, it actually applies to all Android builds as it is simply a JNI and a JAVA file that allows you to read and write to the I2C bus and control GPIO pins.

I have source code here on my website that you can download and use. There are 3 files. is the Java code for your project and is the functions you will call from your application to do I2C or GPIO. is the JNI C source code that you need to build. You will need the NDK from Android for this. I’ll explain this in a subsequent update when I have time. is a sample file showing how to make calls in Android.


To build the JNI you need the Android NDK (Native Development Kit) which allows you to build C/C++ code that can be executed within your JAVA code.

You need make sure that you chmod 777 the GPIO in your file otherwise you get an exception and the port does not change. Also make sure I2C is chmod 777 too.

By Dave McLaughlin