2

Hello i am trying to interface with my VL535L TOF module, but upon installing the library i am getting an error:

  File "/home/pi/Desktop/VL53L1X.py", line 3, in <module>
tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
  TypeError: 'module' object is not callable

i have tried different source of library but the example code given throws that error.

here is the full code, i am using MU to create and run it.

import VL53L1X

tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open() # Initialise the i2c bus and configure the sensor
tof.start_ranging(1) # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range
distance_in_mm = tof.get_distance() # Grab the range in mm
tof.stop_ranging() # Stop ranging
  • Works for me. Perhaps add the instructions you used to install the library. – joan Feb 29 at 18:33
  • @joan im not quite following by what you mean, what instruction are you refering to ? – Jack Feb 29 at 19:02
  • "but upon installing the library". How? – joan Feb 29 at 20:43
  • Hi @Jack, nice to meet you. Ah let me see: The error of "VL53L1X.VL53L1X(...) is the type error: "'module' object is not callable" meaning that you are trying to ask the python interpreter to call the object "VL53L1X", the statement's second "VL53L1X" which is a method. I guess there might be a typo error: "VL53L1X" should read "vL53L1X", with a small "v". Have a nice day. Cheers. – tlfong01 Mar 1 at 0:03
  • @joan i followed the instruction on each library. for example sudo pip3 install smbus2 followed by sudo pip3 install VL53L1X2. – Jack Mar 1 at 5:35
1

Well since after renaming the filname of the project file thrown me another saying that:

No module named 'VL53L1X'

It led me to manually add the path of the module to the file. I have modified the example code to this

import importlib.util
spec = importlib.util.spec_from_file_location("VL53L1X", "/usr/local/lib/python2.7/dist-packages/VL53L1X.py")
VL53L1X = importlib.util.module_from_spec(spec)
spec.loader.exec_module(VL53L1X)

tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open() # Initialise the i2c bus and configure the sensor
tof.start_ranging(1) # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range
distance_in_mm = tof.get_distance() # Grab the range in mm
tof.stop_ranging() # Stop ranging
print(distance_in_mm)

I am now able to get distance reading which is not accurate but is a problem for another day.

| improve this answer | |
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Mar 4 at 10:49
  • apologies, i kind of forgot to come back, it does not let you accept your own answer for 2 days. – Jack Mar 4 at 14:17

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.