[GUIDE] I2C on Android

Moderators: meveric, mdrjr, odroid

[GUIDE] I2C on Android

Unread postby Michel Labitzke » Sun Jul 27, 2014 1:21 am

Hey together,

I have been asked a lot of times how I get the I2C working on Android and I would like to share my research with you.
So here is a short tutorial, to get I2C working on Android with ODROID U:

1. Reserve two GPIO Pins from the Connector
I use PIN 199 and 200
Pin1 of J4 = GPIO-pin 199 = GPX1.0 = XE.INT8 = SCL
Pin3 of J4 = GPIO-pin 200 = GPX1.1 = XE.INT9 = SDA

from http://forum.odroid.com/viewtopic.php?f=80&t=4307&p=46265&hilit=gpio#p46265

You can decide on your own, which pin should be SDA and SCL.
Then register a new i2c bus as i2c-gpio4 in the board config as the code below shows.

Code: Select all
Index: arch/arm/mach-exynos/mach-odroid-u.c
===================================================================
--- arch/arm/mach-exynos/mach-odroid-u.c
+++ arch/arm/mach-exynos/mach-odroid-u.c
@@ -960,6 +960,23 @@
 
 #endif  // #ifdef CONFIG_VIDEO_TVOUT
 
+#define      GPIO_I2C4_SDA   EXYNOS4_GPA0(199)
+#define      GPIO_I2C4_SCL   EXYNOS4_GPA0(200)
+
+static struct    i2c_gpio_platform_data    i2c4_gpio_platdata = {
+   .sda_pin = GPIO_I2C4_SDA,   // gpio number
+   .scl_pin = GPIO_I2C4_SCL,
+   .udelay  = 5,               // 100KHz
+   .sda_is_open_drain = 0,
+   .scl_is_open_drain = 0,
+   .scl_is_output_only = 0
+};
+
+static struct    platform_device    i2c4_gpio_device = {
+   .name    = "i2c-gpio",
+   .id     = 4,    // adepter number
+   .dev.platform_data = &i2c4_gpio_platdata,
+};
 static struct i2c_board_info i2c_devs4[] __initdata = {
 
 };
@@ -1085,6 +1102,7 @@
 static struct platform_device *smdk4x12_devices[] __initdata = {
 
    &odroid_sysfs,
+   &i2c4_gpio_device,
 
    /* Samsung Power Domain */
    &exynos4_device_pd[PD_MFC],
@@ -1121,8 +1139,8 @@
    &s3c_device_rtc,
 
    &s3c_device_i2c0,
-   &s3c_device_i2c1,
-   &s3c_device_i2c4,
+   &s3c_device_i2c1,   
+   //&s3c_device_i2c4,
    &s3c_device_i2c5,
 
 #ifdef CONFIG_ODROID_FAN


2. Porting I2C-tools to android
downloaded the source from here http://www.lm-sensors.org/wiki/I2CTools
move the source to external/i2c-tools in your android source tree
Create an Android.mk like this
Code: Select all
LOCAL_PATH:= $(call my-dir)
 
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_C_INCLUDES := external/i2c-tools/include
LOCAL_SRC_FILES := tools/i2cbusses.c tools/util.c
LOCAL_MODULE := i2c-tools
include $(BUILD_STATIC_LIBRARY)
 

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES:=tools/i2cdetect.c
LOCAL_MODULE:=i2cdetect
LOCAL_CPPFLAGS += -DANDROID
LOCAL_SHARED_LIBRARIES:=libc
LOCAL_STATIC_LIBRARIES := i2c-tools
LOCAL_C_INCLUDES := external/i2c-tools/include
include $(BUILD_EXECUTABLE)
 
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES:=tools/i2cget.c
LOCAL_MODULE:=i2cget
LOCAL_CPPFLAGS += -DANDROID
LOCAL_SHARED_LIBRARIES:=libc
LOCAL_STATIC_LIBRARIES := i2c-tools
LOCAL_C_INCLUDES := external/i2c-tools/include
include $(BUILD_EXECUTABLE)
 
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES:=tools/i2cset.c
LOCAL_MODULE:=i2cset
LOCAL_CPPFLAGS += -DANDROID
LOCAL_SHARED_LIBRARIES:=libc
LOCAL_STATIC_LIBRARIES := i2c-tools
LOCAL_C_INCLUDES := external/i2c-tools/include
include $(BUILD_EXECUTABLE)
 
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES:=tools/i2cdump.c
LOCAL_MODULE:=i2cdump
LOCAL_CPPFLAGS += -DANDROID
LOCAL_SHARED_LIBRARIES:=libc
LOCAL_STATIC_LIBRARIES := i2c-tools
LOCAL_C_INCLUDES := external/i2c-tools/include
include $(BUILD_EXECUTABLE)

Compile i2c-tools (from Android root)
Code: Select all
. build/envsetup.sh
lunch odroidu-eng
mmm external/i2c-tools


Remember that ODROIDU comes with 1.8 V logic. So you have to get a level shifter to shift the 1.8 V from the board to the normally used 3.3V on I2C busses.


Feel free to test, ask and comment this short tutorial.
Last edited by Michel Labitzke on Mon Jul 28, 2014 11:14 pm, edited 1 time in total.
Michel Labitzke
 
Posts: 96
Joined: Mon Jun 16, 2014 5:45 pm
Location: Germany, Ulm
languages_spoken: english, german
ODROIDs: U3, U3+, C1

Re: [GUIDE] I2C on Android

Unread postby sert00 » Sun Jul 27, 2014 6:14 am

WoooH men,this is a great tutorial!I bet many users will find it usefull!thank you for that!
2x Odroid-U2
2x Odroid-XU-E
Odroid-U3
Odroid-C1+
Odroid-XU4
Lcd touch panel 10.1"
....and many of the goodies available....
User avatar
sert00
 
Posts: 745
Joined: Sun Feb 24, 2013 12:26 am
languages_spoken: english,italian
ODROIDs: ODROID-U2*2__ODROID-U3__ODROID-XU-E__ODROID-XU-Ebeta__ODROID-C1__ODROID-XU4

Re: [GUIDE] I2C on Android

Unread postby odroid » Sun Jul 27, 2014 9:23 am

Very useful guide who wants to make the embedded Android platform.
Really appreciate your sharing. :)
User avatar
odroid
Site Admin
 
Posts: 25317
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: [GUIDE] I2C on Android

Unread postby Michel Labitzke » Mon Jul 28, 2014 11:15 pm

Actually I fixed the include error and edited Android.mk in the above post.
Includes in the i2c-tools source file have to be
Code: Select all
#include <linux/i2c-dev.h>
Michel Labitzke
 
Posts: 96
Joined: Mon Jun 16, 2014 5:45 pm
Location: Germany, Ulm
languages_spoken: english, german
ODROIDs: U3, U3+, C1

Re: [GUIDE] I2C on Android

Unread postby andgar » Tue Sep 30, 2014 3:28 am

Hi Michael, Let me a few questions on this:
1. Where is the best site to place external/i2c-tools ?, into system or root directory?
2. there is not an build directory on my root, there is a /build.prop that said me "can't execute: Permission denied" (su was called before).
3. also I can't find any bash "envsetup.sh" I mean "/build.prop/envsetup.sh: not found"
sorry I'm a beginner,
thanks in advance,
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby Michel Labitzke » Tue Sep 30, 2014 3:23 pm

Hey andgar,

you have to place the source of i2c-tools in the SOURCE Tree of Android, not in the Filesystem ON odroid.
Take a look here (scroll down to "Android source code"):
http://com.odroid.com/sigong/nf_file_board/nfile_board_view.php?keyword=&tag=&bid=239
Michel Labitzke
 
Posts: 96
Joined: Mon Jun 16, 2014 5:45 pm
Location: Germany, Ulm
languages_spoken: english, german
ODROIDs: U3, U3+, C1

Re: [GUIDE] I2C on Android

Unread postby andgar » Wed Oct 01, 2014 4:21 am

Many thanks! Michel, I'm following this but when try install repo by typing "$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo" appear "can't create //bin/repo: Read-only file system". is this a permission issue?. I have read that "$ sudo mount ..." can make it writable, but I'n not sure if this is in the right direction, because I have Android 4.4.4 recently updated by ODROID Update app into my eMMC card. So what it is happened?.
or
Perhaps I must to build it all from source in a new SD card.
Sorry about this elementary questions. :oops:
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby Michel Labitzke » Wed Oct 01, 2014 4:42 am

You have to do this on a linux host (PC). Not on the odroid.
What do you want to do with the i2c-tools?
Maybe it helps you if I provide you the compiled binaries?
Michel Labitzke
 
Posts: 96
Joined: Mon Jun 16, 2014 5:45 pm
Location: Germany, Ulm
languages_spoken: english, german
ODROIDs: U3, U3+, C1

Re: [GUIDE] I2C on Android

Unread postby andgar » Wed Oct 01, 2014 4:52 am

OK. this make sense.
Initially only I want to play a little bit in linux shell with GPIO's, UART and I2C to get some experience, just to know how use it into an android app (where I have a better acknowledgment) that manage this ports. My final goal is to use odroid with some android app that talk with some electronic designs that I have using this kind of ports. If Odroid is focused on Open Android, why reason the binary images provided by hardkernel do not allow use the ports already included in the board out of the box??. So great! if you can provide me with some binaries, and of course I need to read a little bit more in depth into Odroid wiki to know the whole process.
thanks a lot.
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby Michel Labitzke » Wed Oct 01, 2014 5:35 pm

Android for ODROID is still in (a great) development Progress.
As you can see it here http://forum.odroid.com/viewtopic.php?f=78&t=5966 a part of i2c is already ported to more or less "official" sources.

Can you show me the Output (from ODROID) of
Code: Select all
dmesg | grep i2c
Michel Labitzke
 
Posts: 96
Joined: Mon Jun 16, 2014 5:45 pm
Location: Germany, Ulm
languages_spoken: english, german
ODROIDs: U3, U3+, C1

Re: [GUIDE] I2C on Android

Unread postby andgar » Thu Oct 02, 2014 4:03 pm

andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby andgar » Mon Oct 06, 2014 12:52 am

Following with the compilation and lunch, I wrote
Code: Select all
. build/envsetup.sh
lunch odroidu-eng
mmm external/i2c-tools
but this stop on the following (se attached)
https://www.dropbox.com/s/jp9nkzw59jb8kyl/Captura%20de%20pantalla%202014-10-05%20a%20la%28s%29%2017.32.29.png?dl=0
How follow and which are the next steps to flash my eMMC and run? I'm trying to follow this http://source.android.com/source/building-running.html but not clear for me and how do it for udroidu.
thanks!
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby andgar » Tue Oct 07, 2014 3:08 am

I solved first part of issue by change PRODUCT_COPY_FILE by BUILD_PREBUILT into the file device.mk located at "/bin/device/hardkernel/odroidu/", but still having
Code: Select all
root@ubuntu:~/bin# mmm external/i2c-tools
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4.4
TARGET_PRODUCT=odroidu
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a9
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=KTU84Q
OUT_DIR=out
============================================
make: Entering directory `/root/bin'
make: *** No rule to make target `out/target/product/odroidu/obj/SHARED_LIBRARIES/libc_intermediates/export_includes', needed by `out/target/product/odroidu/obj/STATIC_LIBRARIES/i2c-tools_intermediates/import_includes'.  Stop.
make: Leaving directory `/root/bin'

Any idea about how to solve this?
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby Michel Labitzke » Wed Oct 08, 2014 4:32 pm

Code: Select all
make: *** No rule to make target `out/target/product/odroidu/obj/SHARED_LIBRARIES/libc_intermediates/export_includes', needed by

means that i2c-tools Needs the libc intermediates to link
try to do a whole build

I will also write a HOW-TO for building I2C-Tools outside of Android.
As I recognize, it will be more easier for the most of you.
But this will take some time
Michel Labitzke
 
Posts: 96
Joined: Mon Jun 16, 2014 5:45 pm
Location: Germany, Ulm
languages_spoken: english, german
ODROIDs: U3, U3+, C1

Re: [GUIDE] I2C on Android

Unread postby andgar » Wed Oct 08, 2014 10:52 pm

OK Thanks. Using "make" for a whole build seems that this error disapear but I found the next one like this:
Code: Select all
including ./system/security/keystore-engine/Android.mk ...
including ./system/security/keystore/Android.mk ...
including ./system/security/softkeymaster/Android.mk ...
including ./system/vold/Android.mk ...
including ./tools/external/fat32lib/Android.mk ...
build/core/Makefile:33: warning: overriding commands for target `out/target/product/odroidu/system/lib/libUMP.so'
build/core/base_rules.mk:529: warning: ignoring old commands for target `out/target/product/odroidu/system/lib/libUMP.so'
build/core/Makefile:33: warning: overriding commands for target `out/target/product/odroidu/obj/lib/libUMP.so'
build/core/prebuilt.mk:165: warning: ignoring old commands for target `out/target/product/odroidu/obj/lib/libUMP.so'
build/core/Makefile:33: warning: overriding commands for target `out/target/product/odroidu/system/lib/libion.so'
build/core/base_rules.mk:529: warning: ignoring old commands for target `out/target/product/odroidu/system/lib/libion.so'
build/core/Makefile:33: warning: overriding commands for target `out/target/product/odroidu/obj/lib/libion.so'
build/core/dynamic_binary.mk:117: warning: ignoring old commands for target `out/target/product/odroidu/obj/lib/libion.so'
build/core/Makefile:33: warning: overriding commands for target `out/target/product/odroidu/system/etc/permissions/android.software.live_wallpaper.xml'
build/core/base_rules.mk:529: warning: ignoring old commands for target `out/target/product/odroidu/system/etc/permissions/android.software.live_wallpaper.xml'
make: *** No rule to make target `device/hardkernel/proprietary/lib/libsonic.so:system/lib/libsonic.so'.  Stop.

also I note that "system/lib" does not exist. Any suggestions?.

About HOW-TO, what do you think of this as start point http://codewalkerster.blogspot.com.es/2014/07/build-odroid-u3kitkat-on-ubuntu-1404.html
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby Michel Labitzke » Thu Oct 09, 2014 4:06 am

Yes, try
Code: Select all
. build_android.sh odroidu
Michel Labitzke
 
Posts: 96
Joined: Mon Jun 16, 2014 5:45 pm
Location: Germany, Ulm
languages_spoken: english, german
ODROIDs: U3, U3+, C1

Re: [GUIDE] I2C on Android

Unread postby andgar » Thu Oct 09, 2014 4:09 am

exactly the same result. same error :?:
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU

Re: [GUIDE] I2C on Android

Unread postby andgar » Mon Dec 15, 2014 3:58 am

Is there any Android image for odroid that have i2c-tools built in? and what odroid boards are supporting this today? My goal is just to make and Android app that use the I2C or UART port.
andgar
 
Posts: 22
Joined: Sun Sep 07, 2014 4:52 am
Location: Seville, Spain.
languages_spoken: english,spanish
ODROIDs: U3+, Odroid-VU


Return to Android

Who is online

Users browsing this forum: No registered users and 1 guest