cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple vl53l1x sensor

Ohong.538
Associate

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

0690X00000ArJNKQA3.jpg

8 REPLIES 8
Ohong.538
Associate

OH I find the another same question topic and AN4846 Application note ,but I don't know much about most things.

John E KVAM
ST Employee

​In theory the answer is simple.

Connect the reset lines to MCU output PIOs.

Put all sensors in reset.

Then take the first sensor out of reset.

Issue the command to change it's address.

Then take the next sensor out of reset and change it's address.

Repeat as often as you need.

I'm using 9 sensors and have no issues.

(I even change the address on the last sensor - so if any of them reset due to noise on the reset line, they will answer to the original address, and I will know I have an issue.)

In your code, create several Dev structures ( Call them Dev1, Dev2... or you create an array of structures.)

Have them all defaulted to I2cDevAddr = 0x52.

After issuing the command to change the address, update the I2cDevAddr to the new address.

and that should do it.

I use ST's VL53L1X UltraLite driver, so my calls are going to be slightly different from the Polulu calls, but you should be able figure out the logic.

My addreessuint16_t DevAddr[9] = {0x62, 0x64, 0x66, 0x68, 0x6A, 0x6C, 0x6E, 0x70, 0x72};

	ResetAllSensors();
	HAL_Delay(10);
	for (i = 0; i < NumOfTOFSensors; i++)
	{
		Dev[i] = 0x52;
		TurnOnSensor(i);
		HAL_Delay(5);
		do {
			status = VL53L1X_BootState(Dev[i], &temp);
			HAL_Delay(5);
			if (status) {
				UART_Print("BootState returned bad status\n");
			}
 
		} while (temp != 3);
 
 
		status += VL53L1X_SensorInit(Dev[i]);	/* Initialize sensor  */
		status += VL53L1X_SetI2CAddress(Dev[i], DevAddr[i]);	/* Change i2c address Left is now 0x62 and Dev1 */
 
		CHECK_ERROR(status);
 
		Dev[i] = DevAddr[i];
		//status += VL53L1X_SensorInit(Dev[i]);	/* Initialize sensor  */
	}
	UART_Print("All Chips booted\n");


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
S.Ma
Principal

A possible alternative if the sensors must stay up and running would be a SW I2C with different SCL (or SDA) lines (will cost same number of signals as VL reset lines.

Sgarr.1
Associate II

hola, estoy usando el ejemplo de lidar 2d, funciona para mí cuando uso solo un sensor, pero cuando uso dos sensores no funciona, ¿podrían ayudarme?

Sgarr.1
Associate II

hi, i am using the lidar 2d example, it works for me when i use only one sensor, but when i use two sensors it doesn't work, could you help me

John E KVAM
ST Employee

​here's the code I used in that demo.

I'd download the VL53L1X ultralite Driver - in it you will see some example projects.

build one of those to get your IDE configured, and then use the files in this zip.

note that there is a change in hte ULD to provide for a 12ms timing budget (this is no standard). You can choose to use this version or you can set your timing budget to 15ms and use the standard version of the ULD.


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
Hi jhon,i cant use this time 12 ms in the counting people application,use two sensor for the width of the door. Thanks El vie., 19 de junio de 2020 9:38 a. m., ST Community escribió:
John E KVAM
ST Employee

​In the official version of the driver we released 15 ms was the max. I wrote the Lidar code before the driver was finished and there was a 12ms.

I'd change the 12 to 15 and use the released driver.  It's guaranteed to work.

You will be 3ms slower, but you will get a little bit more distance out of the system, so it's not a big loss.

  • john

If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.