I got I2C to work with Android on Mini6410

Dave McLaughlin
Hi all,

I have now gotten I2C to work on the Mini6410.

I found some code on a Chinese forum and after doing a few modifications I
now can read my ADC on the Mini6410 motherboard I built for it.

This should basically work with any I2C device under Android.

You can scan for devices by reading 1 byte. The result will be -1 with
nothing detected.

The code needs some work as I am not a fan of goto's in C code so will be
sorting this out later. The basic thing is that this just works.

I have put up a test programme for Android complete with all the source on
SourceForge if anyone wants to play with it.


I have left on all the debug code for now but will rebuild this to a leaner
and faster library for my final design.

Original idea came from this blog. Thanks to whoever you are.


I'll be trying this out on my Mini210 once I get the PCB back from
manufacture and update the SourceForge code to reflect this.



Attachment: i2c_interface.pdf (559.37 KB)
Hi Dave

Thanks for sharing. You may find the following attachment of interest.


Dave McLaughlin
Thanks Sean,

Interesting reading and basically the same code that goes in the JNI for

I have been removing the debug code today using #ifdef DEBUG_ON and I have
had it running for a few hours recording and display a pressure sensor. It
works nice and stable.

I am using the MCP3424 from Microchip. A nice 18 bit 4 channel ADC that
requires very little support components and is dead easy to programme and

Now to work on GPIO tonight.


Hello Dave.

hope you get work on tiny210 too.

Dave McLaughlin
Hi Pratik,

I'll try out the code on to my Mini210 tonight and test but there is no
reason it should not work on the Tiny210 as you only need to select the i2c
device from your main code.

If there is more than one i2c driver it should still work. Just select the
one you want to use.

As the schematic shows that there is an EEPROM on the Tiny210 carrier
board, you can try my code on that. Use the datasheet to find out the SLAVE
ADDRESS and then you can read and write to it.

To see if you have the right address, just do a read of 1 byte and watch
the debug in Logcat for the result of the call.



Is this working I2C of mini6410 on connector 9 or is it on connector 10?. 



Dave McLaughlin
I am using Connector 9 on my external board.

Works great on AT91SAM9G46 with android 2.3
Thanks a lot

Hi Dave,

I have one doubt have you tested that your ADC outputs correct digital
value for the given input; because i am using the same ADC chip as your's
but in Linux and on mini2440 and the problem i am facing is with reading
the ADC the datasheet of MCP3421 says to read the converted data first we
have to send the address byte with read enable then the ADC outputs the
data bytes but using the read and write system calls(which you are also
using in your code) they insert a stop condition so when we write the
address byte with read enable and then read the converted value the data
which i am getting doesn't match with the respective input which i give.

Can you please help me to solve this problem...
I have spent weeks on this and am not able to solve this issue.

Thanx in advance...

Max jin
Hi Dave,

I'm trying to implement your example to read the data from I2C, but it
seems unable to open the /dev/i2c-0 file in the system. The return
fileHandle is -1. Maybe it's the problem on the right to access system
file. Do you know how can I change the mode of the file in SDK.

          fileHandle = i2c.open("/dev/i2c-0");
        catch(Exception e)
          Log.w(TAG, "Could not open I2C interface");
        Log.w(TAG,"fileHandle = "+fileHandle);

Dave McLaughlin
Hi Max, which board are you using?

Have you checked that /dev/i2c-0 exists for your device?

Is there read and write access to it?


Max jin
Hi Dave,

I was using the Allwinner A10 platform and the kernel tree should be
linux-sunxi-lichee-3.0.8-sun4i. I've tried a lot of methods to access the
root mode and finally found it already is :)

right now I have succeed to read the data out, Here I have to use
I2C_SLAVE_FORCE instead of I2C_SLAVE that the I2C device may already been
used by others.

Thank you so much for your source codes, it is so helpful to solve my


Hi Dave, How fast are you able to sample the ADC using the I2C?  I was
considering something like this but concerned about speed since Android
isn't RTOS.  I need 20ms samples rates for me project.

Dave McLaughlin
Hi Jeremy,

I have the MCP3424 running at max speed and get 10 to 15 samples per
second. The ADC sampling runs in it's own thread and I don't see any effect
on the GUI. In fact, the GUI is updating a graph in real time with about
1440 samples per channel (2 of them).

This is far less than you need but it all depends on the speed of your ADC.
The MCP3424 is not fast when used at 16 bit and only gives about 15 sps. At
12 bit is can do 240 sps or even 14 it can do 60 sps.

Have you selected an ADC yet?

HI Dave, 

I tried to use your code, but when i try to write to I2C , the app closes
with nullpointer exception at I2C write command. I am bit confused with the
 "mode" parameter. Is it a the mode like Byte, Word, block etc or the
Register addresses of the device? 

Also would you be able to help me with the nullpointer exception error? I
am a java newbie and currently trying to get the I2C Radio chip working on
Allwinner A-10 board. 

I have another C program which successfully operates this chip through I2C,
so i know I2C is working properly on hardware / driver level. I have even
tried setting the permissions to 777 for /dev/i2c-1 device i am using.

I hope you will see this and respond :)