I purchased the SparkX module with the VCNL4040 proximity sensor you can see here: enter image description here

to use this sensor via Python, but on the repo for the Adafruit library it seems like the library is not available on PyPI and I have no clue on where I should build it or how I should use it after the build. Furthermore, building it on the Raspberry Pi following the steps on the GitHub repo gave me this error:

FileNotFoundError: [Errno 2] No such file or directory: 'build_deps/circuitpython/mpy-cross/mpy-cross'

How can I fix this? And what should I do to be able to use the compiled library in my code, in case of success?

Edit: I found out that my issue is due to the fact that I still have to install the Adafruit circuitPython bundle. But where do I have to copy the installer files? What is the "root of my CircuitPython device"? It only gets more confusing when it says "DO NOT use this to install libraries on a Linux computer, such as the Raspberry Pi, with regular Python. Instead, use the python3 version of pip". Pip doesn't work with my library and the repo itself suggested to use this!


It doesn't look like an overly complicated sensor. If you can write a program you should be able to talk to the sensor with quite simple code.

It should appear on the I2C bus at address 0x60.

i2cdetect - y 1

You can talk to the device with Python via the standard SMBus module.

If you don't know how to or don't want to program your options are more limited.

  • Ok, so considering I'm connecting it to the GPIO interface of the Pi 3, what should I look for to learn how to examine the single pins? And am I doing good connecting the GND to one of the GND pins on the Pi, same for the 3.3V, and both sda, scl and !int to GPIO pins? – Eärendil Baggins May 22 '19 at 21:11
  • 1
    You probably need to edit your question and include details of the module you purchased (assuming you didn't just buy the SMD chip). Basically connect 3,3V (Pi pin 1) to Vcc, ground (Pi pin 6) to GND, SDA (Pi pin 3) to SDA, and SCL (Pi pin 5) to SCL. It should then appear on the I2C bus. See pinout.xyz for pin outs. – joan May 22 '19 at 21:28
  • Edited. Is it correct to connect the !INT pin to BCM? I guess it is the interrupt pin but I don't really know how this peripheral uses it (if asynchronously to send interrupts or synchronously when asked by the program). – Eärendil Baggins May 22 '19 at 21:36
  • It won't do any harm, even if you decide not to use it in your final implementation. Connect it to any spare GPIO. – joan May 22 '19 at 21:38


  1. SparkX VCNL4040 proximity sensor module

  2. No clue on build or use build

  3. Still have to install circuitPython bundle


  1. SparkX is a cousin of SparkFun. You can usually find newbie friendly hookup guide from SparkFun.

  2. It might be hard to build the driver yourself, because Rpi stretch is not that compatible to old jessie.

  3. AdaFruit no longer supports Rpi python, because they think CircuitPython is more user friendly that Rpi python. The trouble is that AdaFruit CircuitPython is not very compatible with Rpi Python 3.5.3.

VCNL4040 uses I2C. If you are brave enough to do Rpi python I2C programming, you can study the registers (only 13 of them, not that scary for newbies) and try to program them yourself.

I skimmed through the datasheet and I rank it around middle of about 20 I2C toys I have played so far.

Tip for newbies to start up:

  1. Try i2cdect -y 1 to make sure Rpi I2C wiring is OK.

  2. Try any I2C read function to read the device identity data word at ID Register (0x07), to make sure you can read something.

  3. Try any I2C write function to write and read back the Config Register (0x00), to make sure you can write something to a register.

  4. Your are almost there! :)

Example python program to write and read a register of a I2C device - DS3231 Real Time Clock

In case you would like to have rough idea of how difficult it is to write a python program to read and write an I2C device, I have listed a fully debugged program in Appendix A below.

vcnl4040 1

vcnl4040 2

vcnl4040 3


Appendix A - Example Program to write read a register of the I2C Real Time Clock DS3231

Demo Program to write and read I2C device DS3231 RTC

# KY019 DS3231 Real Time Clock Test Program V1.5 tlfong01 2018jul25hkt2230


# Reference = https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&start=225#p1345103

# *** Short Description ***
# 1. read, write, print Day Register.

# *** Long Description ***
# 1. Read and print the old byte already in Day Register 
# 2. Write a new byte to the register.
# 3. Read back the new byte. 
# 4. Print the new byte.
# 5. Do it one more time.

# *** Setup/Debug Notes ***
# 1. To change I2c speed to 100Khz
#    $ sudo nano /boot/config.txt
#    modify the dtparam=i2c_arm_on line as below 
#    dtparam=i2c_arm=on, i2c_arm_baudrate=100000
# 2. I2c speeds list
#    low speed      =  50kHz ( 50000) 
#    standard speed = 100KHz (100000)
#    maximum speed  = 400KHz (400000)
# 3. I2C speed can only be changed at raspbain boot time.  It cannot be changed using python.

# *** Import ***

import datetime
import smbus

# *** Config ***

# Raspberry Pi                              = Raspberry Pi Zero W V1.1
# Raspbian                                  = Linux 9 (stretch 2018 April)

programTitle                                = 'DS3231 RTC Example Test Program V1.5'
timeNowStr                                  = str(datetime.datetime.now())[0:16]
i2cCh1                                      = smbus.SMBus(1)

dataByte0x04                                = 0x04
dataByte0x06                                = 0x06

dvAddrByte                                  = 0x68

dayRegAddrByte                              = 0x03

# *** Device Functions (copied from MCP23008 test program example) ***

def readDvRegOneByte                    (i2cPort, dvAddrByte, DvRegAddrByte):
    readByte = i2cPort.read_byte_data   (         dvAddrByte, DvRegAddrByte)
    return readByte

def writeDvRegOneByte                   (i2cPort, dvAddrByte, DvRegAddrByte, writeByte):
    writeDviTwoBytes                    (i2cPort, dvAddrByte, DvRegAddrByte, writeByte)

def writeDviTwoBytes                    (i2cPort, dvAddrByte, dataByte1,     dataByte2):
    i2cPort.write_byte_data             (         dvAddrByte, dataByte1,     dataByte2)

def printDvRegOneByte           (i2cPort, dvAddrByte, DvRegAddrByte, printTitle):
    readByte = readDvRegOneByte (i2cPort, dvAddrByte, DvRegAddrByte)
    print                       (printTitle, hex(readByte))

# *** Test Functions ***

def testWriteReadPrintDayReg(testDataByte):
    printDvRegOneByte(i2cCh1, dvAddrByte, dayRegAddrByte, 'Old Byte =')
    writeDvRegOneByte(i2cCh1, dvAddrByte, dayRegAddrByte, testDataByte)    
    printDvRegOneByte(i2cCh1, dvAddrByte, dayRegAddrByte, 'New Byte =')

def test():
    print('*** TimeNow = ', timeNowStr, '***\n')
    print('***', programTitle, 'Begin ***\n')
    print('***', programTitle, 'End  ***')

# *** Main ***


# *** Sample Output ***

*** TimeNow =  2018-07-25 22:30 ***

*** DS3231 RTC Example Test Program V1.5 Begin ***

Old Byte = 0x6
New Byte = 0x4
Old Byte = 0x4
New Byte = 0x6

*** DS3231 RTC Example Test Program V1.5 End  ***

# *** End ***

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.