Need some help connecting two VL53LOX time of flight sensors to one ESP32

I have a chicken feeder that I would like to get feedback for the level of pellets and water.
My ESP32 is connected and working. It sends the output from one VL53LOX but I cannot get it to recognise the second. Below is Yaml code
``
esphome:
name: esphome-chook-wellbeing

esp32:
board: esp32dev
framework:
type: arduino

Enable logging

logger:

Enable Home Assistant API

api:
password: !secret wifi_password
ota:

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “esphome-chook-wellbeing”
password: “KkVa6GAD0mmY”

Example configuration entry for ESP32

i2c:
sda: 21
scl: 22
scan: true
id: bus_a

captive_portal:

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: 60000ms
    unit_of_measurement: “m”

  • platform: vl53l0x
    name: “distance2”
    id: distance2
    address: 0x42
    enable_pin: GPIO17
    timeout: 200us
    update_interval: 60000ms
    unit_of_measurement: “m”
    `` `

This is the output received.

INFO Reading configuration /config/esphome/esphome-web-d787a4.yaml…
INFO Starting log output from esphome-chook-wellbeing.local using esphome API
INFO Successfully connected to esphome-chook-wellbeing.local
[19:42:37][I][app:102]: ESPHome version 2022.3.1 compiled on Sep 21 2023, 20:14:00
[19:42:37][C][wifi:491]: WiFi:
[19:42:37][C][wifi:353]: Local MAC: 24:62:AB:D7:87:A4
[19:42:37][C][wifi:354]: SSID: ‘Home_network’[redacted]
[19:42:37][C][wifi:355]: IP Address: 192.168.1.182
[19:42:37][C][wifi:357]: BSSID: 78:45:58:46:15:E9[redacted]
[19:42:37][C][wifi:358]: Hostname: ‘esphome-chook-wellbeing’
[19:42:37][C][wifi:360]: Signal strength: -75 dB ▂▄▆█
[19:42:37][C][wifi:364]: Channel: 1
[19:42:37][C][wifi:365]: Subnet: 255.255.255.0
[19:42:37][C][wifi:366]: Gateway: 192.168.1.1
[19:42:37][C][wifi:367]: DNS1: 192.168.1.1
[19:42:37][C][wifi:368]: DNS2: 0.0.0.0
[19:42:38][C][logger:233]: Logger:
[19:42:38][C][logger:234]: Level: DEBUG
[19:42:38][C][logger:235]: Log Baud Rate: 115200
[19:42:38][C][logger:236]: Hardware UART: UART0
[19:42:38][C][i2c.arduino:038]: I2C Bus:
[19:42:38][C][i2c.arduino:039]: SDA Pin: GPIO21
[19:42:38][C][i2c.arduino:040]: SCL Pin: GPIO22
[19:42:38][C][i2c.arduino:041]: Frequency: 50000 Hz
[19:42:38][C][i2c.arduino:044]: Recovery: bus successfully recovered
[19:42:38][I][i2c.arduino:054]: Results from i2c bus scan:
[19:42:38][I][i2c.arduino:060]: Found i2c device at address 0x29
[19:42:38][C][vl53l0x:024]: VL53L0X ‘distance1’
[19:42:38][C][vl53l0x:024]: State Class: ‘measurement’
[19:42:38][C][vl53l0x:024]: Unit of Measurement: ‘m’
[19:42:38][C][vl53l0x:024]: Accuracy Decimals: 2
[19:42:38][C][vl53l0x:024]: Icon: ‘mdi:arrow-expand-vertical’
[19:42:38][C][vl53l0x:025]: Update Interval: 60.0s
[19:42:38][C][vl53l0x:026]: Address: 0x41
[19:42:38][C][vl53l0x:028]: Enable Pin: GPIO16
[19:42:38][C][vl53l0x:030]: Timeout: 200us
[19:42:38][C][vl53l0x:024]: VL53L0X ‘distance2’
[19:42:38][C][vl53l0x:024]: State Class: ‘measurement’
[19:42:38][C][vl53l0x:024]: Unit of Measurement: ‘m’
[19:42:38][C][vl53l0x:024]: Accuracy Decimals: 2
[19:42:38][C][vl53l0x:024]: Icon: ‘mdi:arrow-expand-vertical’
[19:42:38][C][vl53l0x:025]: Update Interval: 60.0s
[19:42:38][C][vl53l0x:026]: Address: 0x29
[19:42:38][C][vl53l0x:028]: Enable Pin: GPIO17
[19:42:38][C][vl53l0x:030]: Timeout: 200us
[19:42:38][C][captive_portal:088]: Captive Portal:
[19:42:38][C][mdns:084]: mDNS:
[19:42:38][C][mdns:085]: Hostname: esphome-chook-wellbeing
[19:42:38][C][ota:085]: Over-The-Air Updates:
[19:42:38][C][ota:086]: Address: esphome-chook-wellbeing.local:3232
[19:42:38][C][api:138]: API Server:
[19:42:38][C][api:139]: Address: esphome-chook-wellbeing.local:6053
[19:42:38][C][api:143]: Using noise encryption: NO
[19:43:11][D][vl53l0x:308]: ‘distance1’ - Got distance 0.184 m
[19:43:11][D][sensor:125]: ‘distance1’: Sending state 0.18400 m with 2 decimals of accuracy
[19:43:21][D][api:102]: Accepted ::FFFF:C0A8:197
[19:43:21][W][api.connection:083]: Home Assistant 2022.2.0 (::FFFF:C0A8:197): Connection closed
[19:44:11][D][vl53l0x:308]: ‘distance1’ - Got distance 0.000 m
[19:44:11][D][sensor:125]: ‘distance1’: Sending state 0.00000 m with 2 decimals of accuracy
[19:44:21][D][api:102]: Accepted ::FFFF:C0A8:197
[19:44:21][W][api.connection:083]: Home Assistant 2022.2.0 (::FFFF:C0A8:197): Connection closed
[19:45:11][D][vl53l0x:308]: ‘distance1’ - Got distance 0.032 m
[19:45:11][D][sensor:125]: ‘distance1’: Sending state 0.03200 m with 2 decimals of accuracy

Although the Yaml file sets the address of “distance2” to 0x42, the log is stating it as 0x29. This may be the cause, but I don’t know how to fix it - any help appreciated.

Thansk

Grum

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

ESPHome does not set the address, that is done by jumpers on the device. You have to set ESPHome to whatever address you set with the jumpers on the device.

Hey Tom,
Thanks for your reply. I am using an ESP32 Wrover from Lonely Binery. There is no provision for jumpers. Do you think I may be wasting my time with it?

Thanks

Grum

The I2C address jumpers are on the VL53LOX board. Or would be if it was like any other I2C sensor.

Ignore what I said. Apparently this device address should be able to be set in software.

https://esphome.io/components/sensor/vl53l0x#configuration-variables
Screenshot 2023-10-04 at 15-32-33 VL53L0X Time Of Flight Distance Sensor

Try connecting one at a time to set their addresses. Having two on the bus with the default 0x29 address could be causing issues.

Hi @Grum,

Please format your code properly as per the link tom has provided, it is hurting my eyeballs.

Cheers.

1 Like

Do both sensors work ok individually?

Hi,I have removed one from the Yaml file and reloaded. Distance measure is OK. Address: 0x41. GPIO16
Removed this one and ran second sensor. Address: 0x42. GPIO 17. Distance measure sucessful.
Put both back into Yaml file and only get result from one sensor.
The log details first sensor as Address: 0x41 but second sensor has defaulted to Address: 0x29 on log file

Mahko_Mahko - This ismy second only post. I have looked for some assistance in formatting code for forum without sucess. Could you give me a clue after I have copied how to format to make it easer.

Sorry to be a nuisance.

Grum

1 Like

Hey - worked it out I hope - formatted code below

esphome:
  name: esphome-chook-wellbeing

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret wifi_password
ota:


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "esphome-chook-wellbeing"
    password: "KkVa6GAD0mmY"

# Example configuration entry for ESP32
i2c:
  sda: 21
  scl: 22
  scan: true
  id: bus_a

captive_portal:
# 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: 60000ms
    unit_of_measurement: "m"

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

Log

INFO Reading configuration /config/esphome/esphome-web-d787a4.yaml...
INFO Starting log output from esphome-chook-wellbeing.local using esphome API
INFO Successfully connected to esphome-chook-wellbeing.local
[20:25:43][I][app:102]: ESPHome version 2022.3.1 compiled on Oct  4 2023, 19:56:45
[20:25:43][C][wifi:491]: WiFi:
[20:25:43][C][wifi:353]:   Local MAC: 24:62:AB:D7:87:A4
[20:25:43][C][wifi:354]:   SSID: 'Home_network'[redacted]
[20:25:43][C][wifi:355]:   IP Address: 192.168.1.182
[20:25:43][C][wifi:357]:   BSSID: 78:45:58:46:15:E9[redacted]
[20:25:43][C][wifi:358]:   Hostname: 'esphome-chook-wellbeing'
[20:25:43][C][wifi:360]:   Signal strength: -74 dB ▂▄▆█
[20:25:43][C][wifi:364]:   Channel: 1
[20:25:43][C][wifi:365]:   Subnet: 255.255.255.0
[20:25:43][C][wifi:366]:   Gateway: 192.168.1.1
[20:25:43][C][wifi:367]:   DNS1: 192.168.1.1
[20:25:43][C][wifi:368]:   DNS2: 0.0.0.0
[20:25:43][C][logger:233]: Logger:
[20:25:43][C][logger:234]:   Level: DEBUG
[20:25:43][C][logger:235]:   Log Baud Rate: 115200
[20:25:43][C][logger:236]:   Hardware UART: UART0
[20:25:43][C][i2c.arduino:038]: I2C Bus:
[20:25:43][C][i2c.arduino:039]:   SDA Pin: GPIO21
[20:25:43][C][i2c.arduino:040]:   SCL Pin: GPIO22
[20:25:43][C][i2c.arduino:041]:   Frequency: 50000 Hz
[20:25:43][C][i2c.arduino:044]:   Recovery: bus successfully recovered
[20:25:43][I][i2c.arduino:054]: Results from i2c bus scan:
[20:25:43][I][i2c.arduino:060]: Found i2c device at address 0x29
[20:25:43][C][vl53l0x:024]: VL53L0X 'distance1'
[20:25:43][C][vl53l0x:024]:   State Class: 'measurement'
[20:25:43][C][vl53l0x:024]:   Unit of Measurement: 'm'
[20:25:43][C][vl53l0x:024]:   Accuracy Decimals: 2
[20:25:43][C][vl53l0x:024]:   Icon: 'mdi:arrow-expand-vertical'
[20:25:43][C][vl53l0x:025]:   Update Interval: 60.0s
[20:25:43][C][vl53l0x:026]:   Address: 0x41
[20:25:43][C][vl53l0x:028]:   Enable Pin: GPIO16
[20:25:43][C][vl53l0x:030]:   Timeout: 200us
[20:25:43][C][vl53l0x:024]: VL53L0X 'distance2'
[20:25:43][C][vl53l0x:024]:   State Class: 'measurement'
[20:25:43][C][vl53l0x:024]:   Unit of Measurement: 'm'
[20:25:43][C][vl53l0x:024]:   Accuracy Decimals: 2
[20:25:43][C][vl53l0x:024]:   Icon: 'mdi:arrow-expand-vertical'
[20:25:43][C][vl53l0x:025]:   Update Interval: 0.6s
[20:25:43][C][vl53l0x:026]:   Address: 0x29
[20:25:43][C][vl53l0x:028]:   Enable Pin: GPIO17
[20:25:43][C][vl53l0x:030]:   Timeout: 200us
[20:25:43][C][captive_portal:088]: Captive Portal:
[20:25:43][C][mdns:084]: mDNS:
[20:25:43][C][mdns:085]:   Hostname: esphome-chook-wellbeing
[20:25:43][C][ota:085]: Over-The-Air Updates:
[20:25:43][C][ota:086]:   Address: esphome-chook-wellbeing.local:3232
[20:25:43][C][api:138]: API Server:
[20:25:43][C][api:139]:   Address: esphome-chook-wellbeing.local:6053
[20:25:43][C][api:143]:   Using noise encryption: NO
[20:25:45][D][vl53l0x:308]: 'distance1' - Got distance 0.104 m
[20:25:45][D][sensor:125]: 'distance1': Sending state 0.10400 m with 2 decimals of accuracy
2 Likes

If you can’t debug having two on the same I2C bus you could try them on separate busses as a workaround?

This person appears to have the same issue as you.

What happens if you change the second 0x42 address to 0x29?

Hey Mako_Mako, thanks for your help. Changed second address 0x42 to 0x29 - no change.
also tries several ideas from your github link without sucess.
Will keep trying. Grum

Did you try this?

If you did and it is still not working, report it as a new issue here:

1 Like

If its Esp32 there are two I2C busses put one on each. Then they can use the same address. if you want to stay on one bus you may need pullup or pull downs. Ive had issues with two different i2c devices not wanting to be neighborly the two bus fix worked.