Use I2C on Khadas VIM

I’ve made the modifications to the mesongxl.dtsi file and loaded the kvim.dts file via tftp.

/dev/i2c-2 shows up but the i2c lines doesn’t work.

You can see the outputs bellow:

khadas@Khadas:~/i2c-tools-1/tools$ ls /dev/i2c-*
/dev/i2c-0  /dev/i2c-1  /dev/i2c-2

khadas@Khadas:~/i2c-tools-1/tools$ sudo chmod 0777 /dev/i2c-*

khadas@Khadas:~/i2c-tools-1/tools$ ./i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --            
         
khadas@Khadas:~/i2c-tools-1/tools$ ./i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 
30: -- -- -- -- -- -- -- -- 38 39 3a 3b 3c 3d 3e 3f 
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 
70: 70 71 72 73 74 75 76 77            
         
khadas@Khadas:~/i2c-tools-1/tools$ ./i2cdetect -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 
30: -- -- -- -- -- -- -- -- 38 39 3a 3b 3c 3d 3e 3f 
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 
70: 70 71 72 73 74 75 76 77  

Does anyone ever used the I2C on the Khadas VIM?

Which version the rom is? Nougat or Mmallow?
Can you upload the file ‘i2cdetect’ on mediafire or the other? Also share the link for it.
Thanks.

You can find it on github here: https://github.com/groeck/i2c-tools
I’ve tried it with the last version of Ubuntu Mate but I aim to use it with Android Nougat.

   $ git clone https://github.com/groeck/i2c-tools
   $ cd i2c-toools
   $ make
   $ cp lib/* /lib
   $ cd tools
   $ ./i2c-detect -y 1

You can follow below steps to use i2c-tools on Android

###Steps
1). Setup the env and lunch target

$ cd <path-of-your-project>
$ source build/envsetup.sh
$ lunch <your-target>   

2). Download the i2c-tools source code

$ cd <path-of-your-project>
$ cd external
$ git clone https://github.com/terry2droid/i2c-tools -b android

3). Build the i2c-tools

$ cd i2c-tools
$ mm -j8

Notice: The list of target file
1.out/target/product/kvim/system/bin/i2cset
2.out/target/product/kvim/system/bin/i2cdetect
3.out/target/product/kvim/system/bin/i2cget
4.out/target/product/kvim/system/bin/i2cdump

4). Push the target file to your device with adb command

$ adb root
$ adb remount
$ adb push i2cset /system/bin
$ adb push i2cget /system/bin
$ adb push i2cdump /system/bin
$ adb push i2cdetect /system/bin

5). How to use i2c-tools

$ adb shell
$ i2cdetect -y -r 2

About more usage for i2c-tools,You can have a try by yourself.

1 Like

I’ve got this error after following what you provided.

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.1
TARGET_PRODUCT=kvim
TARGET_BUILD_VARIANT=user
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.4.0-75-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=NMF26Q
OUT_DIR=out
============================================
make: Entering directory `/home/ted/Desktop/WORKING_DIRECTORY'
Running kati to generate build-kvim-mmm-external_i2c-tools_Android.mk.ninja...
device/khadas/kvim/preinstall/preinstall.mk was modified, regenerating...
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.1
TARGET_PRODUCT=kvim
TARGET_BUILD_VARIANT=user
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.4.0-75-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=NMF26Q
OUT_DIR=out
============================================
No private recovery resources for TARGET_DEVICE kvim
build/core/Makefile:34: warning: overriding commands for target `out/target/product/kvim/system/usr/keylayout/Generic.kl'
build/core/Makefile:34: warning: ignoring old commands for target `out/target/product/kvim/system/usr/keylayout/Generic.kl'
Starting build with ninja
ninja: Entering directory `.'
ninja: error: 'out/target/product/kvim/obj/lib/crtbegin_dynamic.o', needed by 'out/target/product/kvim/obj/EXECUTABLES/i2cdetect_intermediates/LINKED/i2cdetect', missing and no known rule to make it
make: *** [ninja_wrapper] Error 1
make: Leaving directory `/home/ted/Desktop/WORKING_DIRECTORY'

#### make failed to build some targets (10 seconds) ####

ninja: error: ‘out/target/product/kvim/obj/lib/crtbegin_dynamic.o’, needed by ‘out/target/product/kvim/obj/EXECUTABLES/i2cdetect_intermediates/LINKED/i2cdetect’, missing and no known rule to make it
make: *** [ninja_wrapper] Error 1

I have built the i2c-tools on android nougat and mmallow . That’s ok.
Have you ever make full compilation for android source code?
Also you can download the i2c-tools to use and don’t need to build it.

out/build-kvim-mmm-external_i2c-tools_Android.mk.ninja is missing, regenerating...
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.1
TARGET_PRODUCT=kvim
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-33-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=NMF26Q
OUT_DIR=out
============================================
No private recovery resources for TARGET_DEVICE kvim
build/core/Makefile:34: warning: overriding commands for target `out/target/product/kvim/system/usr/keylayout/Generic.kl'
build/core/Makefile:34: warning: ignoring old commands for target `out/target/product/kvim/system/usr/keylayout/Generic.kl'
Starting build with ninja
ninja: Entering directory `.'
[100% 39/39] Install: out/target/product/kvim/system/bin/i2cdump
make: Leaving directory `/home/terry/project/vim/nougat'

#### make completed successfully (45 seconds) ####

terry@Server:~/project/vim/nougat/external/i2c-tools$ ls -l ../../out/target/product/kvim/system/bin/i2c
i2cdetect  i2cdump    i2cget     i2cset   

Thank you so much! It works like a charm :sunglasses:

I might be annoying but the binary version of i2cset you’ve provided doesn’t support the MODE i (I2C block data) for writing multiple bytes within a register.

kvim:/ # i2cset
Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE [MODE]]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77)
  MODE is one of:
    b (byte, default)
    w (word)
    Append p for SMBus PEC

On other boards, the Usage looks like this:

   $ i2cset
    Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]
      I2CBUS is an integer or an I2C bus name
      ADDRESS is an integer (0x03 - 0x77)
      MODE is one of:
        c (byte, no value)
        b (byte data, default)
        w (word data)
        i (I2C block data)
        s (SMBus block data)
        Append p for SMBus PEC

If you could provide the version with MODE i (I2C block data). I would be grateful.

Hi, TedJack
You can have a try by yourself and I will give you some advices when you in trouble :smile:

10 posts were split to a new topic: Build Android failed

I found most of I2C posts are made on Android OS. May I know anyone success on Ubuntu OS?