Using Multiple VL53L1X with Raspberry Pi

Hi… I’m trying to use multiple VL53L1X with Raspberry Pi. I was tested two VL53L1X separately it is working good and the I2C address is 0x29 for both. But when I connected the two sensors in parallel I won’t able to get the output. When I surfed the net, I found changing the address of I2C will help to get rid of the problem. But again I stuck with changing the address of VL53L1X.

Hello.

It is possible to change the address of the sensors to use more than one on the same bus. To do so, you will need to assign a different address to the boards and then use the XSHUT pin to reset one of the boards. The board you reset will then have the default address again. You can read more about doing that in this thread:

-Nathan

I also have VL53L0X and I changed the i2c address of it with the help of this tutorial. But for VL53L1X I’m having the problem with assigning the different address.

The methodology to change the address of the sensor should be the same between the two sensors; the register that has the address is even the same. Can you post some pictures of how you have the boards connected and post the code that is not behaving as you expect?

-Nathan

I’ve connected two sensors in parallel.

Rpi VL53L1X - 1 VL53L1X - 2

Pin - 1 (3.3V) Vin Vin
Pin - 6 (GND) GND GND
Pin - 3 (SDA) SDA SDA
Pin - 4 (SCL) SCL SCL

And the PyPi package VL53L1X is used. The python script.distanceSensing.py (370 Bytes) is used.

It appears that code only declares a single sensor object and the address you are providing it is not the default address. These sensors are located at the default address when they are first powered. You should look through the documentation for the PyPi package to see how to change the address of the sensor. As I mentioned before, after you change the address of one of the sensors, you will need to toggle the XSHUT pin on the other sensor to reset it so that it is available at the default address.

-Nathan


I have connected the raspberry pi and the two VL53L1X sensors as shown. Since the default address of both VL53L1X is 0x29. I tried to change the address of the second sensor using the attached codeaddress_change_updated.py (815 Bytes)
But still the address of the second sensor is not changed, and when tried to open the port, It shows IO Error

Those connections look OK. It looks like you might be using the pimoroni/vl53l1x-python library with your code. In line 22 in your code where you declare the sensor, you are using the new address instead of the default address the sensor has when it is powered. Looking through the VL53L1X.py file in the library, it appears that the authors intended the change_address function to be used to change the address of a sensor, so you probably need to use that with the first sensor. Then you can toggle the IO pin to reset the second sensor and initialize it.

-Nathan

This is my updated scriptaddress_change_new.txt (544 Bytes) after running it I’m getting the error as Screenshot%20from%202019-03-19%2013-02-39

Help me to get rid of it. Or kindly refer some document to change the address of VL53L1X using python

From that code, it seems like you are not familiar with how to declare and work with objects in Python. You are trying to change the address (VL53L1X.VL53L1X().change_address(new_address = 0x2B)) before you create an object to work with (tof = VL53L1X.VL53L1X(i2c_bus=0, i2c_address=0x2B)) and before you initialize the sensor and the I2C communication (tof.open()).

You might try this code:

import VL53L1X
import RPi.GPIO as GPIO

XSHUT = 16

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(XSHUT,GPIO.OUT)
GPIO.output(XSHUT,GPIO.LOW)

tof1 = VL53L1X.VL53L1X(i2c_bus=0, i2c_address=0x29)
tof1.open()
tof1.change_address(new_address = 0x2B)
GPIO.setup(XSHUT,GPIO.IN)
tof2 = VL53L1X.VL53L1X(i2c_bus=0, i2c_address=0x29)
tof2.open()
# now tof1 has address 0x2B and tof2 has address 0x29

tof1.start_ranging(1)                   # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range
distance_in_mm = tof1.get_distance()    # Grab the range in mm
tof1.stop_ranging()                     # Stop ranging

tof2.start_ranging(1)                   # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range
distance_in_mm = tof2.get_distance()    # Grab the range in mm
tof2.stop_ranging()                     # Stop ranging

-Nathan

Hi thank you for the guidance. Finally, the address change has been achieved with a little modification on the code address_change_new_pololu.py (1.1 KB).

The change in address is viewed in the terminal as Screenshot%20from%202019-03-20%2020-14-46

There are two instance has been created for the two sensor as you suggested, but when I tried to run the code, the two instances

tof1.start_ranging(3)
tof2.start_ranging(3)

reads the value from the single sensor and the another sensor remains unused, I’ve checked the connections and it is as same as mentioned above in this thread.

When the obstacle is placed in front of the single sensor, the value of the both sensors dropped. Both sensors are kept apart in a distance which could not interfere each other

When the hand was swang on the first sensor the results is:

When it was swang on the second sensor the result is:

Help me to fix it.

The output you posted is clearly from code that is different than the code you posted. Can you post the code that produced that output?

-Nathan

Oops! My bad. The right code has been attached.address_change_new_pololu.py (1.1 KB)

Do both sensors work if you comment out the second tof1.open() on line 22? Running that once like you do on line 18 should be fine. It’s possible that running it a second time after changing the address is somehow resetting the address the code stores for the tof1 sensor object to the default.

-Nathan

No after commenting tof1.open() on line 22, the sensor throws the IO Error

.

If running second time is like resetting? Why i2cdetect -y 0 still displays the different address. As shown
https://forum.pololu.com/uploads/default/original/2X/1/113c1a66afadc5edbf40aae68c15b27e1febb898.png

The sensor itself is not resetting; it is keeping its new address. It seems like the code you have is not changing the address that it should be using to talk to the sensor. It might be possible to communicate with the sensor on its new address again after you run the change_address method by reinitializing the tof1 object (this time with the new address, so: tof1 = VL53L1X.VL53L1X(i2c_bus=0, i2c_address=0x2A) and then opening the connection again. In general, however, it should be possible for a library to handle that without running extra steps like that, so you might try to contact the author of the library for help, possibly by opening an issue on GitHub.

-Nathan

I’ve tried that way. But it is not worked. Same IO error is occurred. When contacting the author of the library, he is saying, that library is for our product https://shop.pimoroni.com/products/vl53l1x-breakout not for the pololu.

Point me to the pololu library in which I can able to change the address of the sensor. Either in Python or in Arduino .ino code.

We do not have a Raspberry Pi library for that sensor. I posted a comment in that issue on GitHub to give them a more specific understanding of the problem.

You can find our Arduino library with some simple example code for the sensor here on GitHub. Our Arduino library provides a function for changing the address. There is not currently an example showing how to use it included with the library, but there is one in this thread on our forum.

Hello, Have you found a solution to your problem? as I’m having the same