VL53L1X with Red Board vs Nano

Hey y’all, I’m currently working with Pololu’s VL53L1X breakout board and their VL53L1X Arduino Library. Specifically, I’m trying to put multiple sensors on a single I2C bus. I was able to get the following code working on a Sparkfun RedBoard.

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

uint8_t S_1_X = 11;
VL53L1X sensor;

uint8_t S_2_X = 12;
VL53L1X sensor2;

void setup()
{
  Wire.begin();
  Serial.begin (115200);
  delay(500);

  /* Set XSHUT pins to LOW to reset all VL53L1X */
  pinMode(S_1_X, OUTPUT);
  pinMode(S_2_X, OUTPUT);
  digitalWrite(S_2_X, LOW);
  digitalWrite(S_1_X, LOW);
  delay(150);

  digitalWrite(S_2_X, HIGH);  /* turn on second ToF */
  pinMode(S_2_X, INPUT);
  Serial.println("sensor2 reset");
  sensor2.init();
  Serial.println("sensor2 initialized.");
  delay(100);
  sensor2.setAddress(0x31);
  Serial.println("sensor2 address changed");
  delay(150);

  digitalWrite(S_1_X, HIGH);
  pinMode(S_1_X, INPUT);
  Serial.println("sensor1 reset");
  sensor.init();  /* set at default address of 0x29 */
  Serial.println("sensor1 initialized.");
  delay(150);
  
  sensor.setTimeout(500);
  sensor2.setTimeout(500);

  Serial.println("Scanning for I2C addresses...");
  for (byte i = 1; i < 120; i++)
  {

    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
    {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      delay (1);
    }
  }

  sensor.setDistanceMode(VL53L1X::Short);
  sensor.setMeasurementTimingBudget(50000);
  sensor.startContinuous(50);

  sensor2.setDistanceMode(VL53L1X::Short);
  sensor2.setMeasurementTimingBudget(50000);
  sensor2.startContinuous(50);

}

void loop()
{
  Serial.print(sensor.read());
  Serial.print(',');
  Serial.print(sensor2.read());
  Serial.println();
}

However, I tried to connect the sensors to an Arduino Nano and they no longer output the correct values. There seems to be a conflict on the I2C bus but I’m a super noob so I’m not too sure. When I connected the sensors to the Nano, it was able to detect only one I2C address (sensor2). It was able to read sensor2’s value but wasn’t able to read sensor’s value. For reference, based on the pinout I have, I’ve connected sensor to D7 (11) and sensor2 to D8 (12).

Any help would be appreciated!

You are probably correct. First program your nano with a scan program to scan the I2C buss then try each sensor independently. None should have the same address. Then start adding one by one and be sure the problem does not come back. Be sure you are not overloading the power supply with these sensors, that could cause all types of funny things to happen. When all are connected the scan should show the address of each board. Also check you may have to much pull up on the buss, each board may have a set of pull up resistors. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

From the link:

The sensor’s 7-bit slave address defaults to 0101001b on power-up. It can be changed to any other value by writing one of the device configuration registers, but the new address only applies until the sensor is reset or powered off. ST provides an application note (196k pdf) that describes how to use multiple VL53L0X sensors on the same I²C bus by individually bringing each sensor out of reset and assigning it a unique address, and the approach can be easily adapted to apply to the VL53L1X instead.