cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone please post sample code on how to get histogram data from vl53l3cx. I have the dev board nucleo f401 re and the both the sensor and the eval kit.

DMehr.2
Associate II
 
7 REPLIES 7
John E KVAM
ST Employee

In order to get the range, the histogram information is uploaded to your MCU, and some processing is done. So the data you seek is already on your host. The function is called

VL53LX_Error VL53LX_GetAdditionalData(VL53LX_DEV Dev,
		VL53LX_AdditionalData_t *pAdditionalData);

But it's not quite that easy. There are 2 ranges and they toggle back an forth. One range consists of 4 bins of ambient light and 20 data bins.

The alternating range consists of 24 range bins.

Range on a flat wall print out the 24 bins, gathering the data into a spreadsheet.

You will soon figure it out.

(The two range timing have to do with a search for 'radar aliasing' effects. google it.)

And each bin is about 20cm worth of distance.


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.
DMehr.2
Associate II

Can you please provide a sample project in which the above function is used. I cant figure out how to do so.

John E KVAM
ST Employee

I used it like this:

if(pMultiRangingData->RangeData[j].RangeMilliMeter <10) {
	VL53LX_GetAdditionalData(Dev,pAdditionalData);
	if ((pMultiRangingData->StreamCount & 1) == 1){
		for (j=4;j<24;j++){
			printf("%ld,", pAdditionalData->VL53LX_p_006.bin_data[j]);
		}
	}else{
		for (j=0;j<20;j++){
			printf("%ld,", pAdditionalData->VL53LX_p_006.bin_data[j]);
		}
	}
	printf("\n");
}

In this bit of code, I was interested in what the histogram of a very near object looked like.

If a near target, then get the additional data. Use the streamcount to determine even or odd. The first 4 bins of the odd numbered collects contain ambient light data. So you need to remove those.

Dump the data into excel and you should see it all line up.


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.
DMehr.2
Associate II

How to declare the dev and padditonaldata variables? Also where should I write this code, in main.c or app_tof.c. Also what should i include as header files?

John E KVAM
ST Employee

I did all my work in main.c

There are not so many lines that it's worth breaking out.

	VL53LX_AdditionalData_t AdditionalData;
	VL53LX_AdditionalData_t *pAdditionalData= &AdditionalData;

And the trouble with including snippets is that one is always leaving out the declarations.

I included my main.c if that helps.

The trouble is this is some code I hacked as an experiment. Please don't judge it too harshly.


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.
DMehr.2
Associate II

 Dev->I2cHandle = &hi2c1;

 Dev->I2cDevAddr = 0x52;

These lines throw an error

/home/dashingzombie/Downloads/asas/Projects/NUCLEO-F401RE/Examples/53L3A2/53L3A2_SimpleRanging/Src/main.c:113:6: error: 'VL53L3CX_Object_t' {aka 'struct <anonymous>'} has no member named 'I2cHandle'

 113 |  Dev->I2cHandle = &hi2c1;

   |   ^~

/home/dashingzombie/Downloads/asas/Projects/NUCLEO-F401RE/Examples/53L3A2/53L3A2_SimpleRanging/Src/main.c:114:6: error: 'VL53L3CX_Object_t' {aka 'struct <anonymous>'} has no member named 'I2cDevAddr'

 114 |  Dev->I2cDevAddr = 0x52;   |  ^~

John E KVAM
ST Employee

in the main.c is the line:

I2C_HandleTypeDef hi2c1;

Which defines the I2C handle.

The structure I2C_HandleTypeDef is defined in stm32F4xx_hal.i2c.h

But if you are using the F401RE, the example code provided on ST.com should just work.

that code is in:

STSW-IMG015

  • 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.