uint8_t status, isAlive, isReady, i, j;
uint16_t loop;
VL53L5CX_Configuration Dev; / Sensor configuration /
uint16_t distance[VL53L5CX_RESOLUTION_8X8]; / Array of 64 zones which returns the data /
uint32_t timestamp = 0;
//
/ Customer platform /
//
/* Fill the platform structure with customer's implementation. For this
example, only the I2C address is used.
*/
Dev.platform.address = VL53L5CX_DEFAULT_I2C_ADDRESS;
/ (Optional) Reset sensor toggling PINs (see platform, not in API) /
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
from the default one (filled with 0x20 for this example).
*/
//status = vl53l5cx_set_i2c_address(&Dev, 0x20);
//
/ Power on sensor and init /
//
/ (Optional) Check if there is a VL53L5CX sensor connected /
status = vl53l5cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L5CX not detected at requested address\n");
return status;
}
/ Program continuous mode (best one for speed) /
status = vl53l5cx_set_ranging_mode(&Dev, VL53L5CX_RANGING_MODE_CONTINUOUS);
/ Change resolution. Use 8x8 for this example, but 4x4 is also supported /
//status = vl53l5cx_set_resolution(&Dev, VL53L5CX_RESOLUTION_8x8);
status = vl53l5cx_set_resolution(&Dev, VL53L5CX_RESOLUTION_8X8);
/ Reduce sharpener. This is mandatory as the signal strength is very low /
status = vl53l5cx_set_sharpener_percent(&Dev, 0);
/ Increase max frequency. Dedicated function to be created in the future /
uint8_t frequency_hz = 50; // Max 4x4: 150 fps / max 8x8: 50 fps
status = vl53l5cx_dci_replace_data(&Dev, Dev.temp_buffer,
VL53L5CX_DCI_FREQ_HZ, 4,(uint8_t*)&frequency_hz, 1, 0x01);
//
/ Ranging loop /
//
/ Use dedicated start ranging function in “plugin_fast_ranging” /
status = vl53l5cx_start_fast_ranging(&Dev);
loop = 0;
while(loop < 1000)
{
/* Use polling function to know when a new measurement is ready.
Another way can be to wait for HW interrupt raised on PIN A3
(GPIO 1) when a new measurement is ready */
status = vl53l5cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
/* Get all the distances and decompress them */
status = vl53l5cx_get_fast_ranging_data(&Dev, distance);
/* Print 8x8 zones */
for(i = 0; i < 8; i++){
for(j = 0; j < 8; j++){
/* Check if distance is valid. Max distance has been limited to 2047 mm in the
* firmware. When a target status is flagged as invalid, the distance is set to 2048. It
* allows to easily detect invalid data.
*/
if(distance[i * 8 + j] == VL53L5CX_FAST_RANGING_INVALID_STATUS)
{
printf("xxxx, ");
}
else
{
printf("%4u, ", distance[i * 8 + j]);
}
}
printf("\n");
}
printf("\n");
/* For STM32 only: print the time elapsed since last frame */
printf("Time %d ms\n",(int)(HAL_GetTick() - timestamp));
timestamp = HAL_GetTick();
// loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
//WaitMs(&(Dev.platform), 5);
}
/ Stop the sensor: use dedicated stop ranging function in “plugin_fast_ranging” /
status = vl53l5cx_stop_fast_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}
8x8模式最大可以跑到50Hz,但是要改一下寄存器。
int example17(void) {
// / VL53L5CX ranging variables / //
uint8_t status, isAlive, isReady, i, j; uint16_t loop; VL53L5CX_Configuration Dev; / Sensor configuration / uint16_t distance[VL53L5CX_RESOLUTION_8X8]; / Array of 64 zones which returns the data / uint32_t timestamp = 0;
// / Customer platform / //
/* Fill the platform structure with customer's implementation. For this
/ (Optional) Reset sensor toggling PINs (see platform, not in API) / //Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
// / Power on sensor and init / //
/ (Optional) Check if there is a VL53L5CX sensor connected / status = vl53l5cx_is_alive(&Dev, &isAlive); if(!isAlive || status) { printf("VL53L5CX not detected at requested address\n"); return status; }
/ (Mandatory) Init VL53L5CX sensor / status = vl53l5cx_init(&Dev); if(status) { printf("VL53L5CX ULD Loading failed\n"); return status; }
printf("VL53L5CX ULD ready ! (Version : %s)\n", VL53L5CX_API_REVISION);
// / Set some params / //
/ Program continuous mode (best one for speed) / status = vl53l5cx_set_ranging_mode(&Dev, VL53L5CX_RANGING_MODE_CONTINUOUS);
/ Change resolution. Use 8x8 for this example, but 4x4 is also supported / //status = vl53l5cx_set_resolution(&Dev, VL53L5CX_RESOLUTION_8x8);
status = vl53l5cx_set_resolution(&Dev, VL53L5CX_RESOLUTION_8X8);
/ Reduce sharpener. This is mandatory as the signal strength is very low / status = vl53l5cx_set_sharpener_percent(&Dev, 0);
/ Increase max frequency. Dedicated function to be created in the future / uint8_t frequency_hz = 50; // Max 4x4: 150 fps / max 8x8: 50 fps status = vl53l5cx_dci_replace_data(&Dev, Dev.temp_buffer, VL53L5CX_DCI_FREQ_HZ, 4,(uint8_t*)&frequency_hz, 1, 0x01);
// / Ranging loop / //
/ Use dedicated start ranging function in “plugin_fast_ranging” / status = vl53l5cx_start_fast_ranging(&Dev);
loop = 0; while(loop < 1000) { /* Use polling function to know when a new measurement is ready.
}
/ Stop the sensor: use dedicated stop ranging function in “plugin_fast_ranging” / status = vl53l5cx_stop_fast_ranging(&Dev); printf("End of ULD demo\n"); return status; }
自己顶一下
[md]感谢