Can't connect more than two TOF sensors to arduino nano

I'm trying to connect three VL53L0X sensors to the arduino nano. Unfortunatly i can only get two to work at the same time and when i connect the third one the init() function of the pololu library hangs. I tried adding some 20k pull up resistors that i had laying around but they didn't change anything.

Any ideas what i could try other than buying a multiplexer?

Welcome to the forum

Post your sketch that uses 3 sensors and don't forget to use < CODE/ > tags when you do

1 Like
#include <Wire.h>
#include <VL53L0X.h>

const int sensor_count = 3;
const int sensor_pin[sensor_count] = {2, 3, 4};
const int sensor_address[sensor_count] = {0x00, 0x01, 0x02};

VL53L0X sensor[sensor_count];

void setup() {
    for (int i = 0; i < sensor_count; i++) {
        pinMode(sensor_pin[i], OUTPUT);
        digitalWrite(sensor_pin[i], HIGH);
        delay(10);

        sensor[i].init()
        sensor[i].setAddress(sensor_address[i]);
        sensor[i].startContinuous();
    }
}

void loop() {
    Serial.print(sensor[0].readRangeContinuousMillimeters());
    Serial.print(",");
    Serial.print(sensor[1].readRangeContinuousMillimeters());
    Serial.print(",");
    Serial.print(sensor[2].readRangeContinuousMillimeters());
   Serial.println();

   delay(100);
}

Works fine with two sensors but stops working with the third. I have the sensors connected on a digital pin so i can power them on one by one to set the i2c address. I also tried connecting the sensors to 5v and using xshut to set the address but had the same result.

I don't think that will work. You need to initialise them individually.

That is weird, can you post a schematic of that please.

Works for 2 sensors

I just connected the VIN pins on the sensor to a digital pin on the arduino (pin 2,3,4) and set them high to power the sensor instead of using the 5V output on the arduino

change the I2C address,

That is mad, do not do it. Have you checked how much current you can supply from an output pin?

By the way repeating words is not a schematic.

I'm already doing that

Most I2C devices only have 2 address available.

The pins can provide enough power. I also tried connecting the VIN to 5v and using the xshut pins to set the address so i don't think thats the problem

An I2C expander module may be needed.

I2C scanner

What did the I2C scanner report?

It just prints Scanning

When only 2 devices are connected?

With 3

When only 2 devices are connected what is printed out?

does your code do this:

?

I2C device found at address 0x29. I can't set the i2c address permanantly for this sensor

Good luck.

I tried it like this but had the same problem

That is where you are wrong.
The big no no is removing the power from a device that is connected to other active signals. This will result in these active signals being a source of parasitic power to the chip. It is simply not the way to deactivate this chip.

The way you need to do it is by controlling the XSHUT pin. Normally you have this pin attached to an Arduino output pin driving it LOW. Then when you want to use this sensor, you sent its XSHUT pin HIGH and use the sensor.

Can you provide a link to where you got this sensor board as your "picture" inside that so called schematic is not one I recognise?

Thats what i meant by: