PICO: MicroPython I2C basics (VCNL4040 Proximity Sensor)

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
User avatar
wintifrosch
Posts: 12
Joined: Sun Mar 20, 2022 9:37 am
Location: Winterthur, Switzerland
Contact:

PICO: MicroPython I2C basics (VCNL4040 Proximity Sensor)

Post by wintifrosch » Sun Mar 20, 2022 9:54 am

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'
Last edited by wintifrosch on Thu Apr 28, 2022 9:52 am, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: PICO: MicroPython I2C basics

Post by pythoncoder » Sun Mar 20, 2022 11:11 am

You are using the wrong datasheet. The one you reference is for the VCNL4010 which is a completely different device. You want this one.
Peter Hinch
Index to my micropython libraries.

User avatar
wintifrosch
Posts: 12
Joined: Sun Mar 20, 2022 9:37 am
Location: Winterthur, Switzerland
Contact:

Re: PICO: MicroPython I2C basics

Post by wintifrosch » Sun Mar 20, 2022 1:26 pm

Thanks for pointing out. Silly me! :roll:

Post Reply