Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot get more than one VL53L4CD at once #62

Closed
siteswapjuggler opened this issue Jan 28, 2024 · 1 comment
Closed

cannot get more than one VL53L4CD at once #62

siteswapjuggler opened this issue Jan 28, 2024 · 1 comment

Comments

@siteswapjuggler
Copy link

siteswapjuggler commented Jan 28, 2024

Hello,

I'm trying to get two VL53L4CD working at the same time. I already something similar with VL6180x sensor before by using xshutdown pin, changing the adress then working from a different I2C adress. But I didn't success with this library.

Here is my code:

#include <Wire.h>
#include <SparkFun_VL53L1X.h>

#define LEFT_TOF_PIN 6
#define RIGHT_TOF_PIN 7

SFEVL53L1X tofLeft, tofRight;
uint16_t tofLeftDistance, tofRightDistance;

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

  //----------------------------
  // power off both ToF sensor
  //----------------------------

  digitalWrite(LEFT_TOF_PIN, LOW);
  pinMode(LEFT_TOF_PIN, OUTPUT);

  digitalWrite(RIGHT_TOF_PIN, LOW);
  pinMode(RIGHT_TOF_PIN, OUTPUT);

  //----------------------------
  // power on left ToF sensor
  //----------------------------

  digitalWrite(LEFT_TOF_PIN, HIGH);
  tofLeft.begin();
  tofLeft.setI2CAddress(0x54);
  tofLeft.setDistanceModeShort();
  delay(100);

  //----------------------------
  // power on right ToF sensor
  //----------------------------

  digitalWrite(RIGHT_TOF_PIN, HIGH);
  tofRight.begin();
  tofRight.setI2CAddress(0x56);
  tofRight.setDistanceModeShort();
  delay(100);

  //----------------------------
  // start ranging both sensor
  //----------------------------

  tofLeft.startRanging();
  tofRight.startRanging();

  //----------------------------
  // start serial port
  //----------------------------

  Serial.begin(115200);
}

void loop(void) {
  if (tofLeft.checkForDataReady()) {
    tofLeftDistance = tofLeft.getDistance();
    tofLeft.clearInterrupt();
  }

  if (tofRight.checkForDataReady()) {
    tofRightDistance = tofRight.getDistance();
    tofRight.clearInterrupt();
  }

  Serial.print("Left (mm): ");
  Serial.print(tofLeftDistance);
  Serial.print("\tRight (mm): ");
  Serial.print(tofRightDistance);
  Serial.println();

  delay(100);
}
@siteswapjuggler
Copy link
Author

siteswapjuggler commented Jan 28, 2024

Finally did it with this code

#include <Wire.h>
#include <SparkFun_VL53L1X.h>

SFEVL53L1X tofLeft(Wire,7);
SFEVL53L1X tofRight(Wire,6);
uint16_t tofLeftDistance, tofRightDistance;

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

  //-----------------------------------
  // init ToF with different addresses
  //-----------------------------------

  tofLeft.sensorOn();
  tofLeft.begin();
  tofLeft.setI2CAddress(0x2A << 1);

  tofRight.sensorOn();
  tofRight.begin();
  tofRight.setI2CAddress(0x2B << 1);

  tofLeft.setDistanceModeShort();
  tofRight.setDistanceModeShort();

  tofLeft.startRanging();
  tofRight.startRanging();

  //-----------------------------------
  // start serial port
  //-----------------------------------

  Serial.begin(115200);
}

void loop(void) {
  if (tofLeft.checkForDataReady()) {
    tofLeftDistance = tofLeft.getDistance();
    tofLeft.clearInterrupt();
  }

  if (tofRight.checkForDataReady()) {
    tofRightDistance = tofRight.getDistance();
    tofRight.clearInterrupt();
  }

  Serial.print("Left (mm): ");
  Serial.print(tofLeftDistance);
  Serial.print("\tRight (mm): ");
  Serial.print(tofRightDistance);
  Serial.println();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant