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?
#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 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
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
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?