Multiple vl53l1x sensor
Hello , I need to use 2~3 vl53l1x sensor breakout(from pololu)
with nodemcu32s ,use arduino ide ,
My code is below, It work fine if I only use one chip ,
#include <Wire.h>
#include <vl53l1_api.h>
VL53L1_Dev_t dev;
VL53L1_DEV Dev = &dev;
int status;
VL53L1_UserRoi_t roiConfig;
VL53L1_DetectionConfig_t detectionConfig1;
void setup()
{
uint8_t byteData;
uint16_t wordData;
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000);
Dev->I2cDevAddr = 0x52;
VL53L1_software_reset(Dev);
delay(10);
roiConfig.TopLeftX = 4;
roiConfig.TopLeftY = 11;
roiConfig.BotRightX = 11;
roiConfig.BotRightY = 4;
detectionConfig1.DetectionMode = 1;
detectionConfig1.Distance.CrossMode = 3;
detectionConfig1.IntrNoTarget = 0;
detectionConfig1.Distance.High = 1360;
detectionConfig1.Distance.Low = 50;//detectionConfig1 閥值設定值
Serial.println(F("AUTO Ranging Test)"));
status = VL53L1_WaitDeviceBooted(Dev);
status = VL53L1_DataInit(Dev);
status = VL53L1_StaticInit(Dev);
status = VL53L1_SetDistanceMode(Dev, VL53L1_DISTANCEMODE_SHORT);//�?離模�?
status = VL53L1_SetLimitCheckEnable(Dev,VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);//enable funtion
status = VL53L1_SetLimitCheckValue(Dev,VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 0.40*65536);//funtion value �?低�?�增加探測�?離
status = VL53L1_SetThresholdConfig(Dev, &detectionConfig1);//閥值設定
status = VL53L1_SetUserROI(Dev, &roiConfig);
status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, 20000);//時�?�?算(in short mode(min) )
status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, 27);//�?�測間隔
status = VL53L1_StartMeasurement(Dev);//開始
if(status)
{
Serial.println(status);
while(1);
}
}
void loop() {
static VL53L1_RangingMeasurementData_t RangingData;
status = VL53L1_WaitMeasurementDataReady(Dev);
status = VL53L1_GetRangingMeasurementData(Dev, &RangingData);
if(!status)
{
Serial.print("狀態: ");
Serial.print(RangingData.RangeStatus);
Serial.print(", DISTANCE: ");
Serial.println(RangingData.RangeMilliMeter/10);
VL53L1_ClearInterruptAndStartMeasurement(Dev);
}
}Q1:
Where should i put the SetDeviceAddress
should i just define VL53L1_Dev_t dev ,Dev =&dev ?
I really need to use this api because i need threshold function and ROI function
Can you modify my code?
Q2:
How to connect pins
I use 21 22 pin (Original SDA SCL on esp32) ,3V3 and GND
how should i connect wire ,need connect xshut pin if i want use multi sensor??

