Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

VL53L1X library not working

Greetings,

I am an arduino user and just received 4 VL53L1X carriers for a project.

I installed both the Pololu and Sparkfun libraries for the sensor and uploaded in a Genuino 101, but did not get any reading.

I downloaded and run Pololu’s implementation of ST API and with that code I get proper measurements.

Has anyone else had a similar problem?

The wiring for all three tests was the same, I just change the example.

Also, I am thinking of changing the board to an Adafruit Feather Nrf52, will this work with this board?

Thanks for your time.

Manuel

Hello.

Are you using our carrier board? Are you using any kind of cover for the sensor? Are all four boards behaving the same way? Can you post pictures of your boards that show the connections, including any soldered connections you made?

If you have access to an Arduino Uno, you might try it to see if our library behaves the same way as the Genuino 101.

You might check with Adafruit to see how I2C is implemented on that Feather board and whether it might cause an issue with a library that uses the standard Wire Adruino library like our sensor carrier boards.

-Nathan

Hello Nathan, thanks for your reply,

Regarding your questions, yes, I am using the VL53L1X carrier board from Pololu.

For the first test I have made is without any kind of cover (although I have just removed the protective film from one of the sensors), the behaviour is similar in all four boards, whenever i open the serial monitor nothing appears.

I attach two images (sorry for the quality, just cell phone images) with one of the carriers with the angular conectors soldered (the other three have been similary soldered) and connected to the 101 for testing.

When making the same test with an Arduino Uno, there was no problem and the serial monitor shows the distance inmediately.

Regarding the Feather Board, thanks, I will get in touch with them to ask about it.

Thanks for your time, Manuel.

Thanks for those pictures. Are you certain the I2C interface is exposed on the A4 and A5 pins of that Genuino 101 board? You should probably be using the SDA and SCL pins in the opposite corner, though we would not expect any other software to work if you were using pins that are not I2C (also know as TWI or two-wire interface) pins,

-Nathan

Hello Nathan,

I am pretty much sure the interface is exposed in those pins, when I use the implementation of ST API, it works (as it does with the dedicated SDA and SCL pins)

Manuel.

Could you try using our library with the SDA and SCL pins on the Arduino to see if it works if you have not already tried that? If you did try that already and it didn’t work, could you let me know which of our example sketches you ran and how it behaved?

-Nathan

Hello Nathan,

I am going to try to write down all the tests I have done to try to help you as much as I can.

Board: Arduino Uno.
Connecting the Carrier (Vin to 5V, GND to GND, SDA to A4 and SCL to A5) to a Arduino Uno and uploading the example “Continuous” everything works fine, As soon as the sketch is uploaded I open the serial monitor and measures appear.

The Arduino Uno board also has dedicated SDA and SCL ports, again connecting the carrier (Vin to 5V, GND to GND, SDA to SDA and SCL to SCL ) we get the same results, measures appear without further problem.

And just for checks, I tried the very same things connecting to the 3.3V outlet of the Arduino Uno and it worked perfectly.

Board: Arduino/Genuino 101
Connecting the Carrier (Vin to 3.3V, GND to GND, SDA to A4 and SCL to A5) to a Arduino 101and uploading the example “Continuous” when I open the serial monitor, nothing appears. Changing the SDA and SCL the dedicated SDA and SCL ports on the board does not change anything.

I have also modified slightly the “Continuous” example as below:

/*
This example shows how to take simple range measurements with the VL53L1X. The
range readings are in units of mm.
*/

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

VL53L1X sensor;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Starting the Example");
  Wire.begin();
  Wire.setClock(400000); // use 400 kHz I2C

  sensor.setTimeout(500);
  Serial.println("About to initialize sensor");
  if (!sensor.init())
  {
    Serial.println("Failed to detect and initialize sensor!");
    while (1);
  }
  
  // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
  // You can change these settings to adjust the performance of the sensor, but
  // the minimum timing budget is 20 ms for short distance mode and 33 ms for
  // medium and long distance modes. See the VL53L1X datasheet for more
  // information on range and timing limits.
  sensor.setDistanceMode(VL53L1X::Long);
  sensor.setMeasurementTimingBudget(50000);

  // Start continuous readings at a rate of one measurement every 50 ms (the
  // inter-measurement period). This period should be at least as long as the
  // timing budget.
  sensor.startContinuous(50);
  Serial.println("End of Setup");
}

void loop()
{
  Serial.println("Begining of loop");
  Serial.print(sensor.read());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
  Serial.println("End of loop");
}

As you can see, I have added the “while(!Serial);” line to prevent the code start executing before I open the serial monitor and several “Serial.println” with messages to see where the code stops.

With this code on the Arduino Uno and connected as I mentioned before, I get the following in the serial Monitor:

And when I upload on the Arduino 101 all i get is:

Please note that I have made these modifications only to check where the code “stops”, not saving in any moment or changing the example code by any means.

I have done one last thing, I have opened an Arduino 101 example and see there the “wire.h” file was, then I have oppened an Arduino Uno example and check its “wire.h” file, they are located in completelly different folders:

One is “C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src”
While the other is in “C:\Users\Manuel\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\Wire\src”

I have used Textpad to check if the files are different and indeed they are, this is the results of the comparison:

Comparar: (<)C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.h (2682 bytes)
   con: (>)C:\Users\Manuel\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\Wire\src\Wire.h (2270 bytes)

1,20c1,19
< /*
<   TwoWire.h - TWI/I2C library for Arduino & Wiring
<   Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
< 
<   This library is free software; you can redistribute it and/or
<   modify it under the terms of the GNU Lesser General Public
<   License as published by the Free Software Foundation; either
<   version 2.1 of the License, or (at your option) any later version.
< 
<   This library is distributed in the hope that it will be useful,
<   but WITHOUT ANY WARRANTY; without even the implied warranty of
<   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
<   Lesser General Public License for more details.
< 
<   You should have received a copy of the GNU Lesser General Public
<   License along with this library; if not, write to the Free Software
<   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
< 
<   Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
< */
---
> /*
>  * TwoWire.h - TWI/I2C library for Linux Userspace
>  * Copyright (c) 2013 Parav https://github.com/meanbot.
>  * All rights reserved.
>  *
>  * This library is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU Lesser General Public
>  * License as published by the Free Software Foundation; either
>  * version 2.1 of the License, or (at your option) any later version.
>  *
>  * This library is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>  * Lesser General Public License for more details.
>  *
>  * You should have received a copy of the GNU Lesser General Public
>  * License along with this library; if not, write to the Free Software
>  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
>  */
25,26c24,79
< #include <inttypes.h>
< #include "Stream.h"
---
> #include "Stream.h"
> #include "variant.h"
> #include "ss_i2c_iface.h"
> 
> #define BUFFER_LENGTH   32
> #define I2C_SPEED_SLOW  1
> #define I2C_SPEED_FAST  2
> 
> class TwoWire : public Stream {
> public:
> 	TwoWire(I2C_CONTROLLER _controller_id);
> 	void begin(void);
>     void begin(int speed);
>     void setClock(long speed);
> 	void beginTransmission(uint8_t);
> 	void beginTransmission(int);
> 	uint8_t endTransmission(void);
> 	uint8_t endTransmission(uint8_t);
> 	uint8_t requestFrom(uint8_t, uint8_t);
> 	uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
> 	uint8_t requestFrom(int, int);
> 	uint8_t requestFrom(int, int, int);
> 	virtual size_t write(uint8_t);
> 	virtual size_t write(const uint8_t *, size_t);
> 	virtual int available(void);
> 	virtual int read(void);
> 	virtual int peek(void);
> 	virtual void flush(void);
> 
> 	inline size_t write(unsigned long n) { return write((uint8_t)n); }
> 	inline size_t write(long n) { return write((uint8_t)n); }
> 	inline size_t write(unsigned int n) { return write((uint8_t)n); }
> 	inline size_t write(int n) { return write((uint8_t)n); }
> 	using Print::write;
> 
> private:
> 	// RX Buffer
> 	uint8_t *rxBuffer;
> 	uint8_t rxBufferIndex;
> 	uint8_t rxBufferLength;
> 
> 	// TX Buffer
> 	uint8_t txAddress;
> 	uint8_t *txBuffer;
> 	uint8_t txBufferLength;
> 
> 	int init_status;
> 
>     I2C_CONTROLLER controller_id;
> };
> 
> #if WIRE_INTERFACES_COUNT > 0
> extern TwoWire Wire;
> #endif
> 
> #endif
28,85d81
< #define BUFFER_LENGTH 32
< 
< // WIRE_HAS_END means Wire has end()
< #define WIRE_HAS_END 1
< 
< class TwoWire : public Stream
< {
<   private:
<     static uint8_t rxBuffer[];
<     static uint8_t rxBufferIndex;
<     static uint8_t rxBufferLength;
< 
<     static uint8_t txAddress;
<     static uint8_t txBuffer[];
<     static uint8_t txBufferIndex;
<     static uint8_t txBufferLength;
< 
<     static uint8_t transmitting;
<     static void (*user_onRequest)(void);
<     static void (*user_onReceive)(int);
<     static void onRequestService(void);
<     static void onReceiveService(uint8_t*, int);
<   public:
<     TwoWire();
<     void begin();
<     void begin(uint8_t);
<     void begin(int);
<     void end();
<     void setClock(uint32_t);
<     void beginTransmission(uint8_t);
<     void beginTransmission(int);
<     uint8_t endTransmission(void);
<     uint8_t endTransmission(uint8_t);
<     uint8_t requestFrom(uint8_t, uint8_t);
<     uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
< 	uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
<     uint8_t requestFrom(int, int);
<     uint8_t requestFrom(int, int, int);
<     virtual size_t write(uint8_t);
<     virtual size_t write(const uint8_t *, size_t);
<     virtual int available(void);
<     virtual int read(void);
<     virtual int peek(void);
<     virtual void flush(void);
<     void onReceive( void (*)(int) );
<     void onRequest( void (*)(void) );
< 
<     inline size_t write(unsigned long n) { return write((uint8_t)n); }
<     inline size_t write(long n) { return write((uint8_t)n); }
<     inline size_t write(unsigned int n) { return write((uint8_t)n); }
<     inline size_t write(int n) { return write((uint8_t)n); }
<     using Print::write;
< };
< 
< extern TwoWire Wire;
< 
< #endif
< 

As you can see, I do think that the problem might be related with this.

Any help or guidance you can provide will be eagerly accepted.

Thanks, Manuel.

After I found about the duplicate wire.h files i put all my sketches on a secure folder and uninstalled and installed the latest IDE from Arduino.

Still was not able to get it to work with the Genuino 101.

Manuel.

I tried our library and sensor on another Arduino 101 here and was able to replicate your problem (freezing on the sensor.init() line). It appears to be something specific to that board, but it is not immediately obvious what the problem is. We will try to look into more in the next couple of days.

-Nathan

1 Like

Thanks Nathan for your answer and dedication.

I hope to get good news from you soon.

Manuel.

Good Morning to all,

Is there any change in the library in order to work with Arduino 101?.

Thanks, Manuel.

Hi, Manuel.

I looked into this today and made a small change that should stop the Arduino 101 from hanging in the init() function. When you get a chance, could you update to the latest version of the VL53L1X library (1.0.1) and see if it works for you?

Kevin

1 Like

Hello Kevin,

Finally today I have been able to install and check your new library, now it works perfectly.

Thank you very much for your time and attention, keep up the good work!

Regards, Manuel.

1 Like