I2c0 vs i2c1 on VIM2

I have a display I can connect to using GPIO pins 25/26 (i2c1) but I cannot use i2c0 pins 22/23 to connect to the same display. I’m on the latest Ubuntu V1.0.5-210430 on VIM2. Help please?

/boot/env.txt

gpio readall

I noticed that pins 22/23 are not configured for ALT4(?) - which the working i2c(i2c1) bus is? I tried a gpio mode 22 ALTx but got a warn : (pinModeAlt):THis function is not supported by KHADAS Board..

I want to access I2C0 because it is passed through the Tone board and into the OLED FPC connector. Has anyone successfully managed to use this bus?

dmseg:

sudo dmesg | grep i2c
[    1.375747] i2c /dev entries driver
[    2.303491] meson-gxl-pinctrl pinctrl@4b0: pin GPIODV_24 already requested by c1108500.i2c; cannot claim for d0042000.snd_dmic

Yes, but I2C0 works.

root@Khadas:~# i2cdetect -l
i2c-1	i2c       	Meson I2C adapter               	I2C adapter
i2c-0	i2c       	Meson I2C adapter               	I2C adapter
root@Khadas:~# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

The devide 0x39 on I2C0 detected.

1 Like

Thanks for fast reply, but I2C0 is not behaving like I2C1 does. I’m not sure what I’m missing?

Connected via I2C1 - can draw pixels:

Connected via I2C0 - can’t connect:

Attempting to connect to the I2C0 bus generates this error via python:
IOError: [Errno 6] No such device or address

Where as the same code targeting I2C1 works. As per image.

from smbus import SMBus
import time

def main():
    '''
    Main program function
    '''
    # Define registers values from datasheet
    i2cbus = SMBus(0)  # Create a new I2C bus
    i2caddress = 0x70  # Address of device

    i2cbus.write_byte(i2caddress, 0x1B) 
    i2cbus.write_byte(i2caddress, 0x4A)  
    i2cbus.write_byte(i2caddress, 0x43)  
    i2cbus.write_byte(i2caddress, 0x44)  
    
    i2cbus.write_byte(i2caddress, 0x1B)  
    i2cbus.write_byte(i2caddress, 0x4A)  
    i2cbus.write_byte(i2caddress, 0x30)  
    
    i2cbus.write_byte(i2caddress, 0x0000) 
    i2cbus.write_byte(i2caddress, 0x0000>>8)  

    i2cbus.write_byte(i2caddress, 0x31) 
    
    i2cbus.write_byte(i2caddress, 0x0008)  
    i2cbus.write_byte(i2caddress, 0x0008>>8)  
    
    i2cbus.write_byte(i2caddress, 0xFF)  
    i2cbus.write_byte(i2caddress, 0x00)  
    i2cbus.write_byte(i2caddress, 0xFF)  
    i2cbus.write_byte(i2caddress, 0xFF)  
    i2cbus.write_byte(i2caddress, 0xFF)  
    i2cbus.write_byte(i2caddress, 0xFF)  
    i2cbus.write_byte(i2caddress, 0xFF)  
if __name__ == "__main__":
    main()

Strange huh? I’m pretty baffled.

For reference I have a more elaborate piece of code in Rust - which also works via I2C1, but not 0. So I presume it’s a something outside of the language.

Any assistance here?

We’ve enjoyed working on the VIM for this prototype, but if it’s not stable for development we’ll move onto another supplier for our production run.

OK, I will use your code check on my side.

1 Like

Thank you, much appreciated.

I’ve either missed something very obvious or it’s beyond my skill set.

It seems no i2c0 node. Can you check the i2c node ?

$ i2cdetect -l
$ i2cdetect -y 0

I tested a I2C device APDS9960 on my hand on I2C0, it works well.

Test image: https://dl.khadas.com/Firmware/VIM2/Ubuntu/EMMC/VIM2_Ubuntu-server-bionic_Linux-4.9_arm64_EMMC_V1.0.5-210430.img.xz

Just flash, without any modifications.

khadas@Khadas:~/apds9960_demo$ uname -a
Linux Khadas 4.9.241 #10 SMP PREEMPT Fri Apr 30 16:23:48 CST 2021 aarch64 aarch64 aarch64 GNU/Linux
khadas@Khadas:~/apds9960_demo$ 
khadas@Khadas:~/apds9960_demo$ cat /etc/fenix-release 
# PLEASE DO NOT EDIT THIS FILE
BOARD=VIM2
VENDOR=Amlogic
VERSION=1.0.5
ARCH=arm64
INITRD_ARCH=arm64
INSTALL_TYPE=EMMC
IMAGE_VERSION=V1.0.5-210430
################ GIT VERSION ################
UBOOT_GIT_VERSION=khadas-vims-v1.0.5-release
LINUX_GIT_VERSION=khadas-vims-v1.0.5-release
FENIX_GIT_VERSION=v1.0.5
#############################################

Test code:

khadas@Khadas:~/apds9960_demo$ cat test_prox.py 
from apds9960.const import *
from apds9960 import APDS9960
import smbus
from time import sleep

port = 0
bus = smbus.SMBus(port)

apds = APDS9960(bus)

def intH(channel):
    print("INTERRUPT")

try:
    apds.setProximityIntLowThreshold(50)

    print("Proximity Sensor Test")
    print("=====================")
    apds.enableProximitySensor()
    oval = -1
    while True:
        sleep(0.25)
        val = apds.readProximity()
        if val != oval:
            print("proximity={}".format(val))
            oval = val

finally:
    print "Bye"

Test result:

khadas@Khadas:~/apds9960_demo$ python test_prox.py
Proximity Sensor Test
=====================
proximity=142
proximity=141
proximity=142
proximity=143
proximity=142
proximity=143
proximity=141
proximity=142
proximity=141
proximity=142
proximity=139
proximity=141
proximity=143
proximity=153
proximity=150
proximity=147
proximity=255
proximity=114
proximity=127
proximity=245
proximity=255
proximity=137
proximity=134
proximity=138
proximity=137
proximity=138
proximity=143
proximity=255
proximity=134
proximity=137
proximity=135
proximity=136
proximity=134

Appreciate the assistance, but I’m going to pause the project here.

Here’s my notes for anyone coming across the same issues:

https://dl.khadas.com/Firmware/VIM2/Ubuntu/EMMC/VIM2_Ubuntu-server-bionic_Linux-4.9_arm64_EMMC_V1.0.5-210430.img.xz isn’t accepted as a viable image when placed into /dumps/ for krescue. I used https://dl.khadas.com/Firmware/VIM2/Ubuntu/SD_USB/VIM2_Ubuntu-server-bionic_Linux-4.9_arm64_SD-USB_V1.0.5-210430.img.xz but this did not recognise the Tone1 board or IC20.

• Ubuntu 4.9 allows access to I2C-1 but did not recognise a Tone board
• Ubuntu 5.12/5.7 recognises Tone board, but does not recognise I2C buses
• In no circumstance was I able to communicate via I2C0 on a VIM2
• FPC I2C on Tone1/VIM2 GPIO passthrough supplies current but no data
• GPIO settings change between Ubuntu versions (I2C1 becoming In/Out vs Alt2) etc

It’s entirely possible I fried a part of the board and this is an anomaly :woman_shrugging: