Two instances of VL53L0X in ESPhome. Having trouble using XSHUT to set 2 addresses in ESPhome for VL53L0X components

Hi all,

Fairly new to Home Assistant but slowly getting there - I think! First post so hope I get this correct.

I’m trying to use a couple of ESPhome to create a number of sensors for our borehole. Need to monitor temperature, salt and water levels. For the levels I have decided my best option is possibly to use VL53L0X for each level. For the temperature I had a AZDelivery GY-BME280, so I’m using that. The board that I’m using is AZDelivery D1 Mini NodeMCU.

It has been quite a learning curve, but eventually I have one of the VL53L0X on the default address of 0x29 & the GY-BME280 with no issues. The i2c bus was challenging, but I managed.

captive_portal:
# i2c bus
i2c:
  sda: D2 #4
  scl: D1 #3
  scan: true
  id: bus_a

# Temperature & humidity sensor
sensor:
  - platform: bme280
    temperature:
      name: "BME280 Temperature"
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
    humidity:
      name: "BME280 Humidity"
    address: 0x76
    update_interval: 10s

#sensor:
  - platform: vl53l0x
    name: "saltlevel"
    update_interval: 10s
    address: 0x29
    unit_of_measurement: "Inches"
    filters:
      - multiply: 39.37 #convert to inches

I have read the documentation and tried to set specific addresses for the VL53L0X components, but whatever I try it will not work. The example code from the documentation I have been working with is :-1:

# Muliple VL53L0X sensors on same i2c bus
# Example configuration entry
sensor:
  - platform: vl53l0x
    name: "distance1"
    id: distance1
    address: 0x41
    enable_pin: GPIO16
    timeout: 200us
    update_interval: 500ms
    unit_of_measurement: "m"

  - platform: vl53l0x
    name: "distance2"
    id: distance2
    address: 0x42
    enable_pin: GPIO17
    timeout: 200us
    update_interval: 500ms
    unit_of_measurement: "m" 

This is the code that I am using, but the address is still the default address.

captive_portal:
# i2c bus
i2c:
  sda: D2 #4
  scl: D1 #3
  scan: true
  id: bus_a

sensor:
  - platform: vl53l0x
    name: "saltlevel"
    id: saltlevel
    address: 0x42
    enable_pin: GPIO16
    timeout: 200us
    update_interval: 500ms
    unit_of_measurement: "inches"
    filters:
      - multiply: 39.37
# Temperature & humidity sensor
  - platform: bme280
    temperature:
      name: "BME280 Temperature"
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
    humidity:
      name: "BME280 Humidity"
    address: 0x76
    update_interval: 10s

Unfortunately I am getting nowhere with it. I believe that I am using the correct pins on the D1 Mini, but suspect that I am omitting some code related to XSHUT. I have Googled XSHUT, but none of the references have been helpful.

I really have tried to resolve this myself, but without success.

I used to use this as a people counting gateway esp32 and it worked very well.

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: True
  id: bus_a
sensor:
  - platform: vl53l0x
    name: "Sensor 1"
    id: sens_1
    i2c_id: bus_a
    address: 0x41
    update_interval: 50ms
    enable_pin: GPIO25
    timeout: 500us
    internal: true
    
  - platform: vl53l0x
    name: "Sensor 2"
    id: sens_2
    i2c_id: bus_a
    address: 0x42
    update_interval: 50ms
    enable_pin: GPIO32
    timeout: 500us
    internal: true

You need to connect the wire to the X sensor pin and to the corresponding esp pin.
In my case: sensor1 x - GPIO25, sensor2 x - GPIO32

1 Like

The docs gives a good hint that if you want to use two you need to configure and wire the xshut / enable_pin


XSHUT connects to free GPIO pin. Enable/disable device. This is optional if there is only one VL53L0X sensor on the I²C bus and the default 0x29 address is used. Otherwise this is required.

enable_pin (Optional, Pin Schema): The pin connected to XSHUT on vl53l0x to enable/disable sensor. Required if not using address 0x29 which is the cause if you have multiple VL53L0X on the same i2c bus. In this case you have to assign a different pin to each VL53L0X.

Many thanks pepe59 for the info. Good to know that the code works as it should so I’m not omitting anything that should be in the code. The code that I used was similar and I learnt a lot from the process. I did try some of your code and had the same issues. The two vl53l0x components that I tried to use were purchased from eBay during Covid and supply chain issues. I do wonder if there are issues with the components and for some odd reason you cannot write to them. I think the next step is to either try them with an ESP32 board (I believe they have two I2c buses), purchase some decent vl53l0x components now that there are no supply chain issues or both, just to confirm that I was not doing anything wrong! Out of interest which vl53l0x components were you using, and were you also using an ESP32 board??

I could do with some enclosed vl53l0x components ideally as they will be in a salty environment. Does anyone have experience with the ST.com VL53L0X is a Time-of-Flight (ToF) ??

Many thanks again. Paul

Many thanks for the info. Good to know that I did not miss anything. I suspect as from the above post that I had a faulty sensor. I will investigate further. In the meantime I have deployed the Salt Level sensor to see how that goes. Ideally I need something to monitor the water level at the borehole.