VL53L0X Time-of-Flight Ranging Sensor


#1

Anyone using this sensor?

Adafruit has this on a breakout board VL5L0X and an Arduino VL53L0X library as well. I was wondering if anyone has ported this library or is using the sensor with a Photon.


Turn off Search hijack?
#2

Have you seen that sensor here?

I’ve got two coming too :wink:


#3

@shiv, I was looking at getting one of those. I haven’t looked at the library yet to assess the porting.


#4

That sensor has great 2 meter sensing range!

I see it as a great security trip sensor.

The current consumption is low also which is nice.

It would be nice to have a working library for Photon’s & Electron’s which I’m sure will happen soon enough I’m guessing :smiley:


#5

It’s the same one. I have those and they work really well on an UNO. I plan to try them on a Feather as well as an ESP8266. But the real target is a Photon.

I tried “porting” the library. But I as hitting a lot of issues (Besides, my C++ skills are not up to par). So I thought I’d ask here to see if anyone has already done that.


#6

@peekay123. For my use case (low power and accurate short distance measurement) they are ideal. I’m currently using one of the Sharp IR distance sensors. Just found a 3V version (been using a 5V version). It’s all good but they don’t do a good job at really short distances and their power consumption is a bit higher than these. Also these sensors require minimal additional components, so the cost if one made them oneself would be extremely low, as compared to the Sharp ones.

Ok, so once you get your hands on one of those between you and @ScruffR, we could have a port!


#7

If anybody already has one of these set up, could you give this Pololu lib a shot?


(also available on Build - link follows as soon I can see it online again)
https://build.particle.io/libs/5849ca185953bab7450011d4

I’ve only adapted the includes for Particle Build so far.
Today I got my sensors (thanks again to @ghovagim! :+1:) and now have to heat up my soldering station :wink:

If this doesn’t work we may still have to go with the more complex Adafruit lib @shiv linked in his OP.


#8

@ScruffR I have 2 units on order which should be here in 2 days. Hopefully getting the library working is not too much work :smile:

I’m interested in seeing how well these work outdoors as trip sensors. Also wondering if they could work in the Mailbox to sense when mail has been put in or when the mail door has been opened.


#9

I’ll give it a shot. I have the sensors currently working on an UNO. I’ll post my result here soon.


#10

@ScruffR, it works!

I manually added the .cpp and .h files from the Github repo, so I deleted the #define for the Particle Build. So my coe looks like this:

#include "VL53L0X.h"

#if !defined(PARTICLE)
#  include <Wire.h>
#endif


VL53L0X sensor;

void setup()
{
  Serial.begin(9600);
  Wire.begin();

  sensor.init();
  sensor.setTimeout(500);

  // Start continuous back-to-back mode (take readings as
  // fast as possible).  To use continuous timed mode
  // instead, provide a desired inter-measurement period in
  // ms (e.g. sensor.startContinuous(100)).
  sensor.startContinuous();
}

void loop()
{
  Serial.print(sensor.readRangeContinuousMillimeters());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
}

Photon is powered via USB. I’m using the Adafruit sensor and my connections from the sensor to the Photon are as follows:
Sensor pin to Photon pin mapping
VIN - VIN
GND - GND
SDA - D0
SCL - D1

I get reading on the Serial window and they change as I move my hand closer and further away from the sensor. They seem to be similar to what I would get on the UNO.

This is fantastic! Thank you!!


VL53L1X Range sensor on Photon
#11

They’ll definitely work in a “standard” US mailbox since it’s dark in there and the length on the mailbox is well within the range. If you put the sensor towards the top, you could potentially tell if there is mail in the box or empty, provided of course that the mail is placed in line with the sensor. You could have two sensors (not sure how to change the I2C address.


#12

Does the chip have a Alert pin that can be used to wake up the Photon or Electron?


#13

Yes, the chip does. I don’t know if the Library has support for it. The board does break out a pin for this. From the datasheet of the sensor

Interrupt mode: An interrupt pin (GPIO1) sends an interrupt to the host when a new measurement is available.
The description of these 2 modes is available in the VL53L0X API User Manual.


#14

Sweet. I’m going to have to try to figure out how the interrupt works in the lower power modes. I don’t want to wake up the Photon or Electron unless the measurement is has a significant difference between the previous reading.


#15

Can anybody see the lib on Build? I still can’t but I know it’s there.

If you see it, can you post a link here to put it in my post further up?

Thanks


#16

@ScruffR
https://build.particle.io/libs/5849ca185953bab7450011d4/tab/Continuous.ino


#17

Thanks @bpr! :+1:
I’ve updated my original post.


#18

There is a function for that

void setAddress(uint8_t new_addr);

But since this function will only work against the default address 0x29 you need to power up the sensors one by one, reassigning the address before powering up the next one which will again start off with the default address.


I’ve released a v0.0.2 (which again I can’t see) that should correct some error from the original lib with the readReg32Bit() function and other 16 vs. 32 bit adaptions.
If you are using the lib, you may want to remove 0.0.1 and reimport 0.0.2.


#19

Since the Pololu library does lack some features (e.g. ranging interrupt triggers) I’m now porting the Adafruit library too.
This already builds with CLI & Dev, but for Build I’d need to rearrange the file structure.


On Build
https://build.particle.io/libs/584be6da014a6295620004db


#20

@ScruffR, Thank you for doing this!

I haven’t dug into the library code, and since you’re deep in it, I thought I’d ask you…Does the Pololu library or the Adafruit library support Timed Ranging? And further do either of the libraries support setting (and retrieving) the Ranging Profiles?

From the Datasheet

There are 4 different ranging profiles available via API example code. Customers can create their own ranging profile dependent on their use case performance requirements. For more details please refer to the VL53L0X API User Manual.

  1. Default mode
  2. High speed
  3. High accuracy
  4. Long range