VL53L1X with Teensy 3.6

Trying to take advantage of the multiple I2C ports on the T3.6, but so far no luck.

I am using the latest VL53L1X library from Pololu, and Pololu sensors.

I’m using the Arduino IDE version 1.8.15

the github site…

mentions this approach, but it throws an error:

  • void setBus(TwoWire * bus)
    Configures this object to use the specified I²C bus. bus should be a pointer to a TwoWire object; the default bus is Wire, which is typically the first or only I²C bus on an Arduino. If your Arduino has more than one I²C bus and you have the VL53L0X connected to the second bus, which is typically called Wire1, you can call sensor.setBus(&Wire1);.

code:
#include <Wire.h> // Arduino Wire Library
#include <VL53L1X.h> // Pololu library, Version: 1.3.0, Release date: 2021-04-16

VL53L1X VL53L1X_left(); // 3-4: WIRE2_PINS SCL(3)/SDA(4)
VL53L1X_left.setBus(&Wire2);

error:
‘VL53L1X_left’ does not name a type

If I try:

VL53L1X VL53L1X_left(&Wire2); // 3-4: WIRE2_PINS SCL(3)/SDA(4)
// VL53L1X_left.setBus(&Wire2);

I get (perhaps not unexpectedly):

no matching function for call to ‘VL53L1X::VL53L1X(TwoWire*)’

I have tried using ‘&Wire1’ just in case, same exact errors.

anyone ever solve this? any ideas?

thanks in advance!

Hi, if you try to compile and upload the example codes( Continuous, ContinuousMultipleSensors and Continuouswithdetails) of the library, do they work?

I can compile those ok. I have not tested them in hardware but I do not have the xSHUT pins connected, trying not to use that approach to reduce wiring complexity and improve latency.

I have been able to use one sensor at a time in the past, so I think the hardware is good.

I did upgrade the library to 1.3.1, but that also fails to compile with the &Wire1 or &Wire2 approach.

Not sure what the trick is.

full (debug version) of code here:

Hi, rhipps.

Where are you calling setBus() from? I suspect you’re trying to do it from outside a function, i.e. right after your VL53L1X_left object is declared (globally), which will not work. Instead, you will need to call it from inside a function, probably setup():

#include <Wire.h> // Arduino Wire Library
#include <VL53L1X.h> // Pololu library, Version: 1.3.0, Release date: 2021-04-16

VL53L1X VL53L1X_left(); // 3-4: WIRE2_PINS SCL(3)/SDA(4)

void setup()
{
  // ...
  VL53L1X_left.setBus(&Wire2);
  // ...
}

If that does not help, could you post the entire program that you are having trouble with (either inside a code block in a post or as a file attachment)?

Kevin

Kevin,

I modified my code to try your suggestion, and it’s compiling now!! Now to test it on hardware!

pre-setup function:

#include <VL53L1X.h> // Pololu library

VL53L1X VL53L1X_left;
int dVL53L1X_left;

VL53L1X VL53L1X_right;
int dVL53L1X_right;

Kevin,

(my last post got truncated, full response below)

I modified my code to try your suggestion, and it’s compiling now!! Now to test it on hardware!

before the setup function:

#include <VL53L1X.h> // Pololu library

VL53L1X VL53L1X_left;
int dVL53L1X_left;

VL53L1X VL53L1X_right;
int dVL53L1X_right;

in setup function:

// I2C setup
// Arduino I2C library
Wire.begin();
Wire.setClock(400000); // Increase I2C bus speed to 400 kHz
Wire1.begin();
Wire1.setClock(400000); // Increase I2C bus speed to 400 kHz
Wire2.begin();
Wire2.setClock(400000); // Increase I2C bus speed to 400 kHz
//Wire3.begin(); // not supported on Arduino wire.h
//Wire3.setClock(400000); // Increase I2C bus speed to 400 kHz

VL53L1X_left.setBus(&Wire2);
VL53L1X_right.setBus(&Wire1);

Thanks for your help!!