"is the public side of my driveway clear" device?

Thank you @steve_jo

Do you know how to do this in ESPHome, though? There it only states

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”

and

address (Optional, int): Manually specify the i2c address of the sensor. Defaults to 0x29. If an address other the 0x29 is specified, the sensor will be dynamically re-addressed at startup. A dynamic re-address of sensor requires the enable_pin configuration variable to be assigned. If more then one VL53L0X sensor is used on the same i2c bus, a unique address must be specified per sensor.

I assumed that, when you use enable_pin, ESPHome would take care of changing the address on its own. Is this incorrect? Or is this a wiring issue, and if I were to change the wiring, this would actually work?

You need to change the address on the actual sensor itself

How does this work when

Note you must do this every time you turn on the power, the addresses are not permanent!“

Let’s say I change the address on the sensor via the example code on an arduino; then I disconnect it (thus powering it off) and connect it to ESPHome… when I power the ESPHome, wont the changed non-permanent address change right back to the original value?

The esp doc you quoted certainly makes it sound like it handles the addresses.

I don’t know about esp but it would make it easier to confirm wiring if both your tof devices were the same way up. Then I would be double checking that the xshut wires are connected to the pins you think they are on the esp device.

Maybe post your sensor.YAML for the vl053 devices?

1 Like

Sure. I had it in my earlier posting as well, but a bit hidden (all the way at the bottom).

This is the relevant part

sensor:
  - platform: vl53l0x
    name: "VL53L0x1"
    id: distance1
    address: 0x41
    enable_pin: 19
    long_range: true
    timeout: 200us
    update_interval: 500ms
    unit_of_measurement: "m"
  - platform: vl53l0x
    name: "VL53L0x2"
    id: distance2
    address: 0x42
    enable_pin: 17
    long_range: true
    timeout: 200us
    update_interval: 500ms
    unit_of_measurement: "m"

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

I understand it this way: default is 0x29; each sensor that gets an enable_pin automatically gets assigned the address specified for it. And this must have worked for VL530x1, because it does display the correct value (or so I hope; at least it shows different values when moving the sensor closer/further). So it must have either been assigned address 0x41, or it must have ignored address: 0x41 and still communicated with it via 0x29 (which is a possibility, but I really doubt it).

So then the second sensor should work just the same, as it is configured identically to the first, only changing address and enable_pin.

Last resort would be using an arduino for the TOF sensors that communicates the read values to the ESPHome device, which then forwards them to Home Assistant. However, while it’s been on my list to learn how to do this (arduino to esphome) for a while, I’d like to avoid it for this project, if possible.

Update

Now I re-wired it, sorry, the photo is still bad. Wires make it hard to see the connections…

The output I get is now this

[11:31:22][I][app:029]: Running through setup()...
[11:31:22][I][i2c.arduino:183]: Performing I2C bus recovery
[11:31:22][D][vl53l0x:034]: 'VL53L0x1' - setup BEGIN
[11:31:23][D][vl53l0x:258]: 'VL53L0x1' - setup END
[11:31:23][D][vl53l0x:034]: 'VL53L0x2' - setup BEGIN
[11:31:23][D][vl53l0x:258]: 'VL53L0x2' - setup END
[11:31:23][C][esp32_ble:027]: Setting up BLE...
ERROR Serial port closed!

So the device seems to set up the second sensors without error this time (before, it broke after trying to set it up, see output from previous post); now the setup works, but as soon as BLE starts, it closes the serial port so I cannot debug any further.

Both sensors are visibile in Home Assistant now. However, #1 keeps toggling between some value and unknown, #2 is at around 1.6m (which ought to be right, guessing the distance between my desk and ceiling). The first sensor jumps between unknown and 0.27 - 0.28m, which cannot be right as they both point at the ceiling.

I switched to my active USB hub for powering the device (perhaps the PCs USB port was too weak), but now I don’t have serial debugging any longer. Also, without changing any wiring except the USB connection, now it won’t connect via wifi, so I cannot debug at all. This is weird!

I have now

  • used a USB power supply from mains instead of my PCs USB
  • changed the relevant lines to the code below
  • removed Bluetooth and Bluetooth Proxy from ESPHome

The sensors “work”, however, as you can see in the attached video, the measurements are inconsistent. 1.53 meters is the value I assume to be correct when the breadboard is on my desk and measures distance to the ceiling. However, only sensor 1 measures this. Sensor 2 stays at unknown most of the time. When I move my hand / sheet of paper above the sensors, I get these lower readings.

Demo Video (imgur)

However, while sensor 1 keeps updating frequently, sensor 2 hardly does at all.

I have moved one of the sensors once more so that they are not right next to each other; I thought, perhaps they interfere with each other. But the video above was taken after doing so, so now they should not be interfering…

Is there anything else I can do? I had different update_interval values (less than a second, 1s, 5s), but that didn’t make a difference.

sensor:
  - platform: vl53l0x
    name: "VL53L0x1"
    id: distance1
    address: 0x41
    enable_pin: 19
    long_range: true
    timeout: 1000us
    update_interval: 1s
    unit_of_measurement: "m"
  - platform: vl53l0x
    name: "VL53L0x2"
    id: distance2
    address: 0x42
    enable_pin: 17
    long_range: true
    timeout: 1000us
    update_interval: 1s
    unit_of_measurement: "m"

How frustrating!
However it’s ‘working’ sometimes so probably not software. I have no experience of ESP 32 but my understanding is it is a 3.3v device. What voltage are you powering the ToF sensors with 3.3v or 5v?

If 3.3v then presumably from the regulator on the esp board - can it supply enough power (no idea about the specs of it or the sensors)?

If 5v then maybe could be a level issue between 5v and 3.3v? It’s just a guess. But if you are using 5v then trying 3.3v power to the sensors is easy.

Did you test each of the sensor individually (without the “complexity” of having multiple sensors on one bus)? When you have them report differently then it looks like you got defect/inaccurate sensors. :put_litter_in_its_place:

It’s some time I played with the vl53l0x’s, but I remember when the function of having more than one on a bus in esphome (in the beginning the esphome component only supported 1 ToF at a time) I tested it out and it worked a treat with two of the same breakout boards you have.
The only “weird” (or new) thing was this xshut - but it was exactly like in the docs and worked right away without (manually) changing the i2c addresses of the vl53l0x’s. :arrows_counterclockwise:

Also I got like 4 breakout boards and when I tested them their measurements were all in par. :thinking:

You shouldn’t need to do this. Hopefully you get it working without having to mess around too much but if you did need to get the ESP to set the addresses on each power-up, you could just create a small automation in the ESP using the on_boot: trigger and then performing the address setting using the enable pins etc.

is it picking up the wires in front of the sensor?

This may help. From Pololu:
“Under favorable conditions, such as low ambient light with a high-reflectivity target, the sensor can report distances up to 2m, or with the VL53L1X, 4m.”

I use one vl53l10x to detect if I forgot to set out my trash bin. 2M is “iffy”, but 1M or less is quite reliable.

It’s not only low light which helps but very much a reflective surface. I were able to get the 2 meters with the vl53l0x when “aiming” on a white target.

The st data sheet is quite extensive and even gives minimum and typical distances for white/grey targets in- and outside :point_down:

image

The given specs regarding accuracy are also quite impressive for this cheap & tiny :pinching_hand: sensor

image