Page 1 of 1

PICO: MicroPython I2C basics (VCNL4040 Proximity Sensor)

Posted: Sun Mar 20, 2022 9:54 am
by wintifrosch
I'm struggling to communicate with my Adafruit VCNL4040 Proximity Sensor. As a most simple first exercise, I tried to read the read-only version string.
I hooked it up to the hardware I2C pins 4 and 5 of my PICO, without pull-up resistors, and after a i2c.scan(), the module shows up with ID 96=0x60, as expected.
➝ Wiring seems ok, communication is possible.
According to the VISHAY VCNL spec sheet, page 7, the register #1 at address 0x81 contains a constant byte value representing the version. This was 33=0x21 when the spec sheet was released, it should be the same or higher by now. But: By reading this address, I receive the value 0x00.
➝ What do I miss here? Any help appreciated.

BTW: no matter which address I request, I always receive two bytes 0x00, and re following bytes 0xFF.

Code: Select all

>>> from machine import Pin,I2C
    i2c = I2C(0, scl= Pin(5), sda=Pin(4), freq=100000)
    print("scan result:",i2c.scan() )
    vcnl4040 = i2c.scan()[0]      # 96 = 0x60

    # according to the spec sheet, register #1 at address 0x81
    # contains the chip version, which is 0x21 or higher (read only)
    # https://cdn-shop.adafruit.com/product-files/466/vcnl4010.pdf#page=7
    print("expected version byte: b'\\x21' or higher")
    print("version byte received:",i2c.readfrom_mem(vcnl4040,0x81,1))
    
scan result: [96]
expected version byte: b'\x21' or higher
version byte received: b'\x00'

Re: PICO: MicroPython I2C basics

Posted: Sun Mar 20, 2022 11:11 am
by pythoncoder
You are using the wrong datasheet. The one you reference is for the VCNL4010 which is a completely different device. You want this one.

Re: PICO: MicroPython I2C basics

Posted: Sun Mar 20, 2022 1:26 pm
by wintifrosch
Thanks for pointing out. Silly me! :roll: