VL53L0X Time-of-Flight Ranging Sensor


#21

If you refer with “Timed Ranging” to “Continous Mode Ranging” with a definable delay between range cycles, then yes - both libraries do.
In the Pololu one there is a Continous.ino that shows a back to back ranging and the comment in there suggests to provide the delay in milliseconds if you don’t want max speed back to back ranging.

For the Adafruit library I’m still struggling with getting it up on Build, so I haven’t had chance to test it properly - but since that’s the “full” (as far as can see) API set provided by STM, there is no doubt it’s supported there too.

For the latter question about the ranging profiles, it’s possible with both, but only the Adafruit one has a dedicated API while Pololu has stripped away a lot of the complex APIs (for ease of standard use) and you’d need to set and read registers “manually”.


#22

Thank you for all of the information @ScruffR


#23

Sweet!

I have 2 of these sensors coming Monday and I’m wanting and hoping I can use them to trigger their interrupt pin to wake a Photon or Electron when something passes in front of the sensor past a predefined distance.

I’m assuming that is what the “Ranging Interrupt Triggers” do?


#24

That’s what it should do.

You should be able to set a threshold distance and can set the interrupt to either trigger when a reading is closer than that (e.g. intrusion alarm) or when the reading is further away (e.g. lost contact to object).


#25

That’s great to hear.

Looking forward to testing the new library you’re working on when it’s ready.

Do you have any particular applications you plan on using it for?


#26

I must say, I’m getting really fed up with the broken “Contribute Library” feature in Particle Build, but it should already be public on Build (although I can’t see it).

There should be a lib called ADAFRUIT_VL53L0X but I can’t see, nor click, nor test it.


#27

I just looked and it shows up for me:


#28

I’ve got two libraries published on Build
VL53L0X I can see too, but the newer more complex ADAFRUIT_VL53L0X is missing for me.


#29

That one shows up also:

Is there an interrupt example in there? Haven’t been through this one yet.


#30

Hmm, I can’t see it on your screenshots
You’re looking at ADAFRUIT_VS... not ADAFRUIT_VL53L0X


#31

Woops, your right, I got the wrong one :blush:

Do you have a link where I could download your library and load it into Particle DEV?


#32

But now I’ve logged in with another account and there it was

On Build
https://build.particle.io/libs/584be6da014a6295620004db
and this is the repo on GitHub


#33

Sweet. Your direct link works but it does not show up in the Library on Build when I search for that library for some reason.


#34

@ScruffR, I think it would be worth it to document some of the things one needs to get in order to port a library to work with Photon/Electron and Build. Obviously the guide/Wiki would be just that and not a sure-fire way of porting a library. I was simply stuck on the initial steps (Arduino.h etc.). One has to know what the Particle build system includes by default, what some header files may be called or what a header file is substituted with in build etc.

What do you think?


#35

There were some threads that dealt with that, but since Libraries 2.0 and IDE 2.0 which will bring some improvements and better compatibility are (over)due, there is not much point to invest extra effort into this “sinking ship” :wink:

Porting from Arduino to Particle.io (Simplified-Hopefully)
[solved] Porting from Arduino to Particle
https://community.particle.io/t/tutorial-how-to-port-an-arduino-library-to-the-spark-core/3578 (hidden, but should have been published - never did tho’)
Library List + Porting How To
Support for Arduino #Include files


#36

@shiv, once Libraries 2.0 come out, it will include a lot of built-in Arduino compatibility. However, the hardware-specific libraries will remain the real challenge. :wink:


#37

@ScruffR I received 2 of the VL53L0X today and tried to get it working with your code on the Build IDE and the code off your GitHub and flashed via the Particle DEV.

Both ways end up with the Electron flashing a RED SOS pattern right after this line of serial print:

If I unplug the i2c lines I do not get the RED SOS errors, so it seems that when the main loop starts it triggers a crash which triggers the SOS message.

Here is a video of the SOS:

https://www.dropbox.com/s/3gzpo2xr129wh6p/VID_20161212_145814444.mp4?dl=0

I’m sure I have the Vin, GND, SDA, and SCL lines correct, and I have tried 2 separate boards with the same results. Any ideas?

FYI - Your less advanced VL53L0X library on Build IDE does work after trying that. I was looking to use the library with the interrupt functions.


#38

Dealing with this same situation with my class. I have a ton of sensors and a ton of students. I am trying to simplifying how to setup a sensor, the .ino .h .cpp files. Digital and Analog sensors are fairly easy but I2C, uArt and SPI take a bit of coordination of several files.

Here is a list of my RobotShop sensors and I probably have the same number from Seeedstudio

I am thinking of making a database on my website (http://rocksetta.com ) that anyone could upload sensor info and links or using a github site such as: https://github.com/hpssjellis/robotics-sensors that my students can push solutions for the sensors they are working on. Either setup would probably just have a bunch of links to @peekay123 github site at https://github.com/pkourany

I find the student’s need a sheet of paper stored with each sensor with this minimum amount of information:

  1. Title with sensors full name
  2. Image of sensor
  3. Link to more information about hooking up example.ino files, header files, etc
  4. QRCode to the link
  5. Summary info about how to hook the Sensor up to the Photon

The following fits in a sandwich bag with the sensor.

The example link in the image is https://github.com/hpssjellis/robotics-sensors/tree/master/sensors/serial/pixy
.

Anyone got any other ideas?


Spark + Pixy - Using the Pixy with a Spark Core
#39

I’ve still not been able to test that library myself - so far I just managed to get the pins soldered to one of my boards :blush:

But I’ll see if I can find something


#41

@ScruffR @shiv Using the normal code example the sensor maxes out at 4 feet / 1260 mm.

I copied the Arduino long range example code over to ScruffR’s library port and it works!

In long range mode the sensor will measure up to 6.2 feet away vs. 4 feet with the normal settings which makes a big difference for me.

It’s working great as a trip sensor spanning a 5.5 foot wide hallway with stable output. :smiley:

I did notice that Christmas lights in the background it will cause random readings to show up using the long range settings so try to keep background lights to a minimum.

Use the code below with this library: https://build.particle.io/build/584f095f31c7319f1d001284

/* This example shows how to use continuous mode to take
range measurements with the VL53L0X. It is based on
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.

The range readings are in units of mm. */
#define _PARTICLE_BUILD_IDE_
#if defined(_PARTICLE_BUILD_IDE_)
#  include "VL53L0X/VL53L0X.h"
#else
#  include "VL53L0X.h"
#endif

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


VL53L0X sensor;

#define LONG_RANGE

// Uncomment ONE of these two lines to get
// - higher speed at the cost of lower accuracy OR
// - higher accuracy at the cost of lower speed

//#define HIGH_SPEED
#define HIGH_ACCURACY

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

  sensor.init();
  sensor.setTimeout(250);

 
 #if defined LONG_RANGE
  // lower the return signal rate limit (default is 0.25 MCPS)
  sensor.setSignalRateLimit(0.1);
  // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif

#if defined HIGH_SPEED
  // reduce timing budget to 20 ms (default is about 33 ms)
  sensor.setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
  // increase timing budget to 200 ms
  sensor.setMeasurementTimingBudget(200000); 
#endif

}

void loop()
{

int distancemm = sensor.readRangeSingleMillimeters();

if (distancemm >= 9000)  //Change 9000 to the maximum distance you want to get readings from. Only readings below this number will serial print. 
{
  // action A
}
else
{
  Serial.println(distancemm);
}
}


Now the only thing left to figure out is how to get the interrupt GPIO pin working and how to set the threshold that triggers it.