VL53L0X Time-of-Flight Ranging Sensor


That’s odd, since with #define VL53L0X_LOG_ENABLE 0 commented out, the lib should behave as with v0.0.1.

Does your sensors work with the Pololu lib?
For my boards I need to add external pull-ups to the I2C lines.


Both boards worked w/ pololu code.
Just not getting SOS now
Maybe I’m in over my head on this and causing us all confusion. I just noticed that when I do a local build I get a binary of size 3876, but the CLI build is 30964??? I must be doing something wrong. I use:

make clean all PLATFORM=photon APPDIR=../../appmain/vl53l0x TARGET_DIR=../../appmain/vl53l0x/target/ PARTICLE_DEVELOP=1 LTO=n program-dfu v=1

from modules, git checkout latest.

While for CLI I do:

C:\particle\appmain\vl53l0x>particle compile photon
C:\particle\appmain\vl53l0x>dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D photon_firmware_1481839806786.bin

I didn’t need to use pull-ups for the pololu code, but I’ve tried 4k7s to the 2.8v line with the adafruit code without achieving anything different than solid cyan
Update: Just tried with a different photon and now back to SOS. :scream:


@ScruffR @RWB

Not clear at all that I know what I’m doing, but it appears that in vl53l0x_api_core.cpp the function:

/* To convert ms into register value */
uint32_t VL53L0X_calc_timeout_mclks(VL53L0X_DEV Dev,
uint32_t timeout_period_us,
 uint8_t vcsel_period_pclks)

crashes because? the variable macro_period_ps gets set to zero therein.

I can’t get any farther on this tonight, maybe it’s a clue??


The biggest help I’m going to be for solving this problem is getting one of these sensors in master @peekay123 's hands so he can work his magic.

I can test and verify code anytime you guys have something to try.

@scruffr what all is in this Adafruit Library that is missing from the working Poulou library?

What more could you want over and above the continuous & single shot measurement modes other than setting the interrupt thresholds and the different sleep modes maybe? Just curious what other features you may be interested in.


The Adafruit library has the full STM feature set like recalibration, custom profile up-/down-load, dedicated functions for interrupt setup, …
That sensor is a powerful machine and hence has a ton of possible (but complicated) features and AFAIK there is no real API documentation but the actual code.
And that’s my problem here you don’t know the device but have to understand what the code is doing and back track to the how and why - and that code does a lot.

Getting it to build for Particle devices was a no-brainer, but have it run as expected - especially with boards that obviously behave differently - is driving me nuts.
For my own applications I’d not need anything else than the interrupt feature incorporated in the Pololu lib, but to find out how to get that there, I’d need to understand the STM/Adafruit lib first.


I give up! What the heck are spads anyway?


@ScruffR @bpr Is this Library for the 32bit Teensy 3.2 of any help possibly?


@RWB interesting! but he didn’t get the interrupt going, which is what we all want.


Yea but aren’t these part of the interrupt puzzle?


SPADs are Single Photon Avalange Diodes which are the used LASER emitters in the sensor.


@ScruffR @RWB @peekay123
I stumbled around hopelessly, couldn’t let it go, and it paid off. With some caveats. As soon as I got it the adafruit library more or less working, Windows 10 decided the photon was a mouse. After an hour of agitated fiddling I managed to solve that. However, my photon won’t use Serial anymore, just Serial1, but through USB not the TX-RX pins. I’m so confused now. Anyway, here’s a link to the code and see what you can make of it. It’s messy beyond belief, embarassingly so, but I have no engineering background so don’t laugh. What got this running was mostly the code provided by jerryn on the adafruit forum a week ago - he rewrote the vl53l0x_i2c_comms.cpp and Adafruit_VL53l0x.cpp files. Give it a whirl. The scaling seems off. Someone else please fix that and get the interrupt going.


I bet this thread is partially responsible for 55 of these bad boys disappearing from time I ordered this morning, to tonight.


I have not tried to run your code yet but I did download it and looked at most of the code in the files.

In the VL53L0X_device.h file I find these lines referring to the interrupt.

Can’t we write to these registers to change the interrupt GPIO pin functionality?

Can’t we also read and reset the Interrupt register after it has been tripped?

I guess we can try to write to the 0x00 register and see if it disables the GPIO Interrupt pin, and then write to register 0x01 and see if the GPIO pin goes high after something passes by the sensor?


Great job Brian (@bpr)! :+1:
That was a precious find. I do get good readings now too.
I’ve just pushed that as version 0.0.3 to Particle Build.

Brian, could you point me to the place where you found this?
I want to know what has been changed an why?

Thanks :+1:




I see, the thread started off the same way as ours: Pololu lib worked but Adafruits own not.


@bpr So which of the libraries do you prefer now that it sounds like both are working?

Any luck on figuring out how to properly configured the Interrupts? I’ve looked all the .H and .cpp files but there are so many of them it’s confusing :confused:


That’s the point :sunglasses:
Finding the word interrupt in the lib is not even 10% of the way to get them working :wink:
But since there are no official sample codes that show how to do it, it’s some detective work with trial and error and does take time.

@shiv, about endianness

Because there are operations that are agnostic to endianness (e.g. math operations on the numeric date type) and there are operations where differences in endianness can cause trouble (e.g. void* operations).


@ScruffR @bpr Here is another library that may or maynot be helpful :smiley:

He tried to get the interrupts working:


@RWB, @ScruffR, sorry for the radio silence and thank you @RWB for shipping me one of these bad boys. I’ll be looking a code as soon as I get the unit. Good work so far though!