Skip to main content
ADP1114
Associate III
August 15, 2019
Solved

Adding multiple vl53l0x sensors

  • August 15, 2019
  • 16 replies
  • 10884 views

Hi all

I have successfully implemented a single vl53l0x sensor, but wish to add more. I found the "AN4846 Application note Using multiple VL53L0X in a single design" documentation:

https://www.st.com/content/ccc/resource/technical/document/application_note/group0/0e/0a/96/1b/82/19/4f/c2/DM00280486/files/DM00280486.pdf/jcr:content/translations/en.DM00280486.pdf

Under "VL53L0X API management" it specifies:

In vl53L0x_platform.h API file set VL53L0x_SINGLE_DEVICE_DRIVER macro to 0 so that API implementation will be automatically adapted to a multi-device context.

But I cannot find anything called "VL53L0x_SINGLE_DEVICE_DRIVER" in the vl53L0x_platform.h file.

Where can I find it? Or has the files updated without the documentation being updated? If so should this step just be skipped?

Best answer by John E KVAM

​If you have one working, you are all set. There is a bit of a trick to it though.

Start with all sensors in shutdown.

Then bring up the first one by raising the shutdown pin. The sensor will come up to the default address.

Issue the command to change address.  - SetI2CAddress

Then bring up the second sensor.

Issue the command to change address. 

Repeat until all sensors have different addresses. - I use 0x62, 0x64, 0x66, 0x68, 0x6A...

Technically you don't have to change the address of the last one, but if you do you can use the default address as a health check. If you ever ping it and get an answer, one or more of your sensors has reset.

Then the trick is to insure you have the correct address set when making calls.

The psudo-code would look like this (it's for an L1X chip, but yours is similar:

void ResetAndInitializeAllSensors(void)
{
	VL53L1X_ERROR status;
 
	uint8_t i, Sensor, temp;
	int16_t Offset;
 
	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");

16 replies

Associate II
May 29, 2024

Thank you John for your quick feedback
I'm very disappointed because it seems that your designers didn't really understand the purpose of a bus like an I2C for us users: to limit wiring and host IOs consumption by connecting many devices in parallel on only 4 wire.

John E KVAM
ST Employee
May 29, 2024

99% of our customers use exactly one of these sensors and put them in cellphones and PCs and kiosks. It's actually a rare case that needs more than one of them. Of course, if you are that rare case then it is important. Adding a daisy-chain initialization system such as you describe gets debated from time to time, but it does not make economic sense to burden the vast majority of our customers with the cost of the extra hardware. 

I feel your frustration. And I agree with you. I keep asking, but then they show me the numbers and I have to agree that the chip designers are making good business choices. 

- john

 

Associate II
May 29, 2024

Sure your product probably satisfies 99% of your actual customers, but a more conventional use of i2c bus would find new customers you don't know yet...but it is an another subjet

Associate II
June 4, 2024

Hi John !

You wrote "Long story short - unfortunately you cannot cheat. You need one line for the Xshut on every sensor." :thinking_face:

Now loock at this :face_with_tears_of_joy: :

Just 4 I2C wires + only a fifth wire in cascade between GPIO pin and XSHUT pin of sensors and wihtout multiplexer.

It seems that you underestimate your products


Capture1.JPGCapture2.JPGCapture3.JPGCapture4.JPGCapture5.JPG

 

John E KVAM
ST Employee
June 4, 2024

So you hooked the GPIO1 (which is the interrupt line) of sensor A to the Xshut of sensor B. And when you are done doing the setup of the first sensor, the GPIO1 goes high (as it is an active low interrupt). But what happens when you start the sensor and you actually get an interrupt? That will drop the interrupt low and turn off the next sensor. 

Or did I miss something?

- john

Associate II
June 4, 2024

You're not far off, that's how the wiring works, you miss some others clever things.:beaming_face_with_smiling_eyes:

Thank you for your non-encouragement and your non-support, it's been a great source of motivation for us. :thumbs_up:

John E KVAM
ST Employee
June 4, 2024

In that case, I'll bet you a beer you can't do it. 

(I do have to admit that I'm frequently wrong. And if you get it to work, feel free to publish how you did it. I don't mind being taught new things.)

- john

Associate II
June 6, 2024

Hi John,

Take your plane ticket to Normandy and we'll explain how we did it. Then we'll go for a beer or two !