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

4 comments on “GPIO and I2C driver for Android

  1. Hello! My chip locates at 0x10 7-bit address. I can’t set Slave address to 0x10. The driver always says: “I2C: Can’t set slave address”

    • Long time since I used this. Does it OPEN without errors?

      It could be that your I2C bus is not enabled for user access.

      In the init scripts you need to make sure you chmod 0666 /dev/i2c-1 if you are trying to use that bus.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s