VL53L1X and ESP8266

Has anyone been able to get the VL53L1X to work on an ESP device? I tried an esp12 (Wemos D1 mini) and an esp32 dev board but the sensor just fails to initialize. It works fine on a Due arduino board with the test code, but can’t seem to get it to work on an esp device. Any suggestions?

I get this when trying to continuous sample code provided:

Soft WDT reset

ctx: cont 
sp: 3ffef990 end: 3ffefb70 offset: 01b0

>>>stack>>>
3ffefb40:  3fffdad0 3ffeeb18 3ffee898 40202551  
3ffefb50:  feefeffe 00000000 3ffeeb34 40203984  
3ffefb60:  feefeffe feefeffe 3ffeeb50 40100108  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld
Failed to detect and initialize sensor!

Hello.

Someone else on our forum might have some experience with that, but we do not have any specific advice for using a VL53L1X with an ESP-8266-based board like the one you are using. You might consider reviewing our VL53L1X library and creating a version that works for your microcontroller.

-Jon

Making my own version is a little above me I think. Maybe one day I’ll have the time for something like that. I may just have to shelf these for a while and wait and see if something comes out. Thanks for checking though.

Just as a followup, I was able to get this working. So for anyone looking to do similar, you need to specify the Wire pins to use.

With my D1 mini, I just changed the line in the example code from
Wire.begin();
to
Wire.begin(D6, D5);
and used the pins actually labeled D6 and D5 (not the Arduino pinout for esp8266 devices). And it works.

1 Like

I’m so glad I found this. Would you be so kind as to share the code you are using to get me started?

I need to measure the level of oil in a tank and have been trying with ultrasonics but the signal bounces off of the metal tank walls.

Thanks again.

This would be sort of a minimum sketch that should work. Works on my D1 mini.

#include <Wire.h>
#include <VL53L1X.h>

int distance;
VL53L1X sensor;

void setup() {
  Serial.begin(115200);
  Wire.begin(D6, D5); //SDA, SCL
  Wire.setClock(400000); // use 400 kHz I2C
  sensor.setTimeout(500);
  if (!sensor.init())
  {
    Serial.println("Failed to detect and initialize sensor!");
    while (1);
  }
  sensor.setDistanceMode(VL53L1X::Long);
  sensor.setMeasurementTimingBudget(50000);
  sensor.startContinuous(50);
}
void loop() {
  distance = sensor.read() / 10;
  Serial.println(distance);
  delay(100);
}

Thank you so much. I appreciate it.

Which variant of the VL53L1X did you use? I’m using a D1 Mini too and read that not all variants work with it?

The one Pololu sells.