I'm trying to get 2 VL53L4CD sensors to work together and have them tied into the same SDA/SCL ports on my ESP32-S3.
I keep getting an error where it reads once (probably when it first loops), but then gives me a i2cWriteReadNonStop returned Error issue. Am I using the with the setI2Caddress feature incorrectly? Or is there an actual bug? Or is it just not turning the device back on?
This is the code that I am using:
`/ Includes ------------------------------------------------------------------/
include
include
include
include
include
include
include
include
include
include
include
include
include
//#include
define DEV_I2C Wire
define SerialPort Serial
char report[64];
//address we will assign if dual sensor is present
uint8_t sensor1add = 0x29;
uint8_t sensor2add = 0x28;
//init Wifi
/void initWifi(){
Serial.print("Setting AP (Access Point)...");
// No password
WiFi.softAP (ssid);
// Start WiFi Access Point
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.print(IP);
// Print ESP8266 Local IP Adress
Serial.println(WiFi.localIP());
}/
//init sensors
void initSensor(VL53L4CD sensorX, uint8_t sensoradd)
{
// Init sensor1
//Set sensor address.
sensorX.VL53L4CD_SetI2CAddress(sensoradd);
// Configure VL53L4CD satellite component.
sensorX.begin();
// Switch off VL53L4CD satellite component.
sensorX.VL53L4CD_Off();
//Initialize VL53L4CD satellite component.
sensorX.InitSensor();
// Program the highest possible TimingBudget, without enabling the
// low power mode. This should give the best accuracy
sensorX.VL53L4CD_SetRangeTiming(200, 0);
sensorX.VL53L4CD_SetOffset(-10);
// Start Measurements
sensorX.VL53L4CD_StartRanging();
}
//getSensor1Reading
void getSensor1Reading(uint8_t status, uint8_t NewDataReady)
{
digitalWrite(xshut1, HIGH);
Serial.println("Sensor 1 is on");
if ((!status) && (NewDataReady != 0)) {
// (Mandatory) Clear HW interrupt to restart measurements
sensor1_vl53l4cd_sat.VL53L4CD_ClearInterrupt();
// Read measured distance. RangeStatus = 0 means valid data
sensor1_vl53l4cd_sat.VL53L4CD_GetResult(&results1);
snprintf(report, sizeof(report), "Status = %3u, Distance = %5u mm, Signal = %6u kcps/spad\r\n",
results1.range_status,
results1.distance_mm,
results1.signal_per_spad_kcps);
sensor1 = results1.distance_mm;
Serial.println((String)"This is Sensor1 " + (float)sensor1 + (String)"mm");
}
digitalWrite(xshut1, LOW);
}
//getSensor2Reading
void getSensor2Reading(uint8_t status, uint8_t NewDataReady)
{
digitalWrite(xshut2, HIGH);
Serial.println("Sensor 2 is on");
if ((!status) && (NewDataReady != 0)) {
// (Mandatory) Clear HW interrupt to restart measurements
sensor2_vl53l4cd_sat.VL53L4CD_ClearInterrupt();
// Read measured distance. RangeStatus = 0 means valid data
sensor2_vl53l4cd_sat.VL53L4CD_GetResult(&results2);
snprintf(report, sizeof(report), "Status = %3u, Distance = %5u mm, Signal = %6u kcps/spad\r\n",
results2.range_status,
results2.distance_mm,
results2.signal_per_spad_kcps);
sensor2 = results2.distance_mm;
Serial.println((String)"This is Sensor2 " + (float)sensor2 + (String)"mm");
}
digitalWrite(xshut2, LOW);
}
/void offset()
{
}/
/ Setup ---------------------------------------------------------------------/
void setup()
{
// Initialize serial for output.
SerialPort.begin(115200);
SerialPort.println("Starting...");
// Initialize I2C bus.
DEV_I2C.begin();
The error message:
Starting... Sensor 1 is on This is Sensor1 0.00mm Sensor 2 is on This is Sensor2 28.00mm Secpp:499] requestFrom(): i2cWriteReadNonStop returned Error -1 [ 5272][E][Wire.cpp:499] requestFrom(): i2cWriteReadNonStop returned Error -1 (this one loops on indefinitely and will occasionally be a 263)
Hello,
I'm trying to get 2 VL53L4CD sensors to work together and have them tied into the same SDA/SCL ports on my ESP32-S3.
I keep getting an error where it reads once (probably when it first loops), but then gives me a i2cWriteReadNonStop returned Error issue. Am I using the with the setI2Caddress feature incorrectly? Or is there an actual bug? Or is it just not turning the device back on?
This is the code that I am using: `/ Includes ------------------------------------------------------------------/
include
include
include
include
include
include
include
include
include
include
include
include
include
//#include
define DEV_I2C Wire
define SerialPort Serial
char report[64];
//address we will assign if dual sensor is present uint8_t sensor1add = 0x29; uint8_t sensor2add = 0x28;
// set the pins to shutdown
define xshut1 A0
define xshut2 A1
define GFX_BL DF_GFX_BL
//this holds the measurement VL53L4CD_Result_t results1; VL53L4CD_Result_t results2; float sensor1, sensor2;
//Components. VL53L4CD sensor1_vl53l4cd_sat(&DEV_I2C, xshut1); VL53L4CD sensor2_vl53l4cd_sat(&DEV_I2C, xshut2);
//init Wifi /void initWifi(){ Serial.print("Setting AP (Access Point)..."); // No password WiFi.softAP (ssid); // Start WiFi Access Point IPAddress IP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.print(IP); // Print ESP8266 Local IP Adress Serial.println(WiFi.localIP()); }/
//init sensors void initSensor(VL53L4CD sensorX, uint8_t sensoradd) { // Init sensor1 //Set sensor address. sensorX.VL53L4CD_SetI2CAddress(sensoradd); // Configure VL53L4CD satellite component. sensorX.begin(); // Switch off VL53L4CD satellite component. sensorX.VL53L4CD_Off(); //Initialize VL53L4CD satellite component. sensorX.InitSensor(); // Program the highest possible TimingBudget, without enabling the // low power mode. This should give the best accuracy sensorX.VL53L4CD_SetRangeTiming(200, 0); sensorX.VL53L4CD_SetOffset(-10); // Start Measurements sensorX.VL53L4CD_StartRanging(); }
//getSensor1Reading void getSensor1Reading(uint8_t status, uint8_t NewDataReady) { digitalWrite(xshut1, HIGH); Serial.println("Sensor 1 is on"); if ((!status) && (NewDataReady != 0)) { // (Mandatory) Clear HW interrupt to restart measurements sensor1_vl53l4cd_sat.VL53L4CD_ClearInterrupt(); // Read measured distance. RangeStatus = 0 means valid data sensor1_vl53l4cd_sat.VL53L4CD_GetResult(&results1); snprintf(report, sizeof(report), "Status = %3u, Distance = %5u mm, Signal = %6u kcps/spad\r\n", results1.range_status, results1.distance_mm, results1.signal_per_spad_kcps); sensor1 = results1.distance_mm; Serial.println((String)"This is Sensor1 " + (float)sensor1 + (String)"mm"); } digitalWrite(xshut1, LOW); }
//getSensor2Reading void getSensor2Reading(uint8_t status, uint8_t NewDataReady) { digitalWrite(xshut2, HIGH); Serial.println("Sensor 2 is on"); if ((!status) && (NewDataReady != 0)) { // (Mandatory) Clear HW interrupt to restart measurements sensor2_vl53l4cd_sat.VL53L4CD_ClearInterrupt(); // Read measured distance. RangeStatus = 0 means valid data sensor2_vl53l4cd_sat.VL53L4CD_GetResult(&results2); snprintf(report, sizeof(report), "Status = %3u, Distance = %5u mm, Signal = %6u kcps/spad\r\n", results2.range_status, results2.distance_mm, results2.signal_per_spad_kcps); sensor2 = results2.distance_mm; Serial.println((String)"This is Sensor2 " + (float)sensor2 + (String)"mm"); } digitalWrite(xshut2, LOW); }
/void offset() { }/
/ Setup ---------------------------------------------------------------------/ void setup() { // Initialize serial for output. SerialPort.begin(115200); SerialPort.println("Starting..."); // Initialize I2C bus. DEV_I2C.begin();
initSensor(sensor1_vl53l4cd_sat, sensor1add); initSensor(sensor2_vl53l4cd_sat, sensor2add); }
void loop() { uint8_t NewDataReady1 = 0; uint8_t NewDataReady2 = 0; uint8_t status1; uint8_t status2; do { status1 = sensor1_vl53l4cd_sat.VL53L4CD_CheckForDataReady(&NewDataReady1); status2 = sensor2_vl53l4cd_sat.VL53L4CD_CheckForDataReady(&NewDataReady2); } while (!NewDataReady1 || !NewDataReady2); getSensor1Reading(status1, NewDataReady1); getSensor2Reading(status2, NewDataReady2);
delay(100); }`
The error message:
Starting... Sensor 1 is on This is Sensor1 0.00mm Sensor 2 is on This is Sensor2 28.00mm Secpp:499] requestFrom(): i2cWriteReadNonStop returned Error -1 [ 5272][E][Wire.cpp:499] requestFrom(): i2cWriteReadNonStop returned Error -1 (this one loops on indefinitely and will occasionally be a 263)