Hello,
I am trying to run Time of Flight sensors (VL53L0X) using the Adafruit_VL53L0X library on an ESP32-S3. Starting from the beginning, the ToF sensors are connected via a TCA9548A, which acts as a switch. First, I create the appropriate Wire instance and scan the entire bus. I find the address 0x70, which is the address of the TCA9539 switch, and so far everything works. Next, I select which channel I want to operate on (selecting an example device) and try to initialize the ToF sensor, but I get the following error:`Bus 0 selected successfully.
[ 143][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 160][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 166][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 172][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 179][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 185][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 191][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 197][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 204][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 210][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 216][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 222][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 229][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 235][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 241][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 247][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 254][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 260][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 266][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 272][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 279][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 285][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 292][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 299][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 305][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 311][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 328][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 336][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 342][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 348][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 355][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 361][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 368][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 374][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 381][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 387][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 393][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 400][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 406][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 413][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 420][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
[ 426][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
Failed to boot VL53L0X
Here is the code which i am using:
#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_VL53L0X.h"
//#include <twi.h>
//https://forum.pololu.com/t/multiple-vl53l0x-sensor-with-tca9548a-i2c-multiplexer-using-median-filter/15227
#define I2C_MASTER_SCL_IO 5 // GPIO number used for I2C master clock
#define I2C_MASTER_SDA_IO 4 // GPIO number used for I2C master data
#define I2C_MASTER_FREQ_HZ 100000 // I2C master clock frequency
#define TCA9539_ADDR 0x74 // I2C address of the TCA9539PWR
#define TOF_G_PIN 16
#define TOF_R_PIN 32
#define TOF_B_PIN 64
void TCA9548A_Select(uint8_t bus);
void tca9539_init();
void tca9539_write_register(uint8_t reg_addr, uint8_t value);
void set_tof(uint8_t red, uint8_t green, uint8_t blue);
#define NUM_SENSORS 6
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
//Adafruit_VL53L0X lox = Adafruit_VL53L0X();
//Adafruit_VL53L0X lox[NUM_SENSORS];
void setup(){
Serial.begin(115200);
Wire.begin(I2C_MASTER_SDA_IO, I2C_MASTER_SCL_IO, I2C_MASTER_FREQ_HZ);
Wire.setPins(I2C_MASTER_SDA_IO, I2C_MASTER_SCL_IO);
byte error, address;
int nDevices;
tca9539_init();
set_tof(0,0,0);
Serial.println("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++) {
// The i2c_scanner uses the return value of
// the Write.endTransmission to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
nDevices++;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
TCA9548A_Select(0);
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
}else{
Serial.println(F("VL53L0X booted successfully"));
}
}