cancel
Showing results for 
Search instead for 
Did you mean: 

Unreasonable Data from VL53L8CX Sensor

kgb
Associate II

Hello Everyone,

I am currently using the vl53lmz_uld_api  tto process data measured by the VL53L8CX sensor. I have also used the "example_12_cnh_data" to retrieve data from my sensor. However, the incoming data seems completely incorrect, and I don't know where the issue lies. When I hold my sensor 20-25 cm in front of an obstacle, I receive highly unreasonable data:

Zone :  40, Status :   0, Distance : 1383 mm

Zone :  41, Status :  13, Distance : 1892 mm

Zone :  42, Status :   5, Distance : 1371 mm

Zone :  43, Status :   5, Distance : 1367 mm

Zone :  44, Status :   5, Distance : 1347 mm

Zone :  45, Status :   5, Distance : 1370 mm

Zone :  46, Status :   5, Distance : 2448 mm

Zone :  47, Status :   9, Distance : 2262 mm

Zone :  48, Status :   4, Distance : 2977 mm

Zone :  49, Status :   0, Distance : 1398 mm

Zone :  50, Status :   5, Distance : 1381 mm

 

 

Can someone please help me to understand what i am doing wrong  here is my main.c: 

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
  MX_DMA_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
 // UartComm_Restart();

  //__________MY CODE ___________

 p_dev.platform.address = 0x52;


 Reset_Sensor();

 if (status != VL53LMZ_STATUS_OK){
 		printf("vl53lmz_init failed : %d\n");
 		return status;
 	}

	/* (Mandatory) Initialise the VL53LMZ sensor */
	status = vl53lmz_init(&p_dev);
	if(status)
	{
		printf("VL53LMZ ULD Loading failed\n");
		return status;
	}

	printf("VL53LMZ ULD ready ! (Version : %s)\n",
			VL53LMZ_API_REVISION);

	status = vl53lmz_set_resolution(&p_dev, 64);
	status |= vl53lmz_set_ranging_mode(&p_dev, VL53LMZ_RANGING_MODE_AUTONOMOUS);
	status |= vl53lmz_set_ranging_frequency_hz(&p_dev, 5);
	status |= vl53lmz_set_integration_time_ms(&p_dev, 20);
	if(status)
	{
		printf("ERROR - Failed basic configuration sequence, status=%u\n", status);
		return status;
	}

	status = vl53lmz_cnh_init_config( &cnh_config,
											0,		/* StartBin 	*/
											18,		/* NumBins   	*/
											1);	/* SubSample 	*/

	if (status != VL53LMZ_STATUS_OK){
			printf("VL53LMZ CNH init config failed\n");
			return status;
		}

	status = vl53lmz_cnh_create_agg_map( &cnh_config,
												64,				/* Resolution. Must match value used in vl53lmz_set_resolution() */
												0,				/* StartX 		*/
												0,				/* StartY 		*/
												1,				/* MergeX		*/
												1,				/* MergeY		*/
												8,				/* Cols			*/
												8 );			/* Rows 		*/

	if (status != VL53LMZ_STATUS_OK){
			printf("VL53LMZ CNH set aggregate map failed\n");
			return status;
		}

	status = vl53lmz_cnh_calc_required_memory( &cnh_config, &cnh_data_size );
	if (status != VL53LMZ_STATUS_OK){
		printf("VL53LMZ CNH calc required memory failed\n");
		if (cnh_data_size < 0){
			printf("Required memory is too high : %d. Maximum is %d!\n", (int)-cnh_data_size, (int)VL53LMZ_CNH_MAX_DATA_BYTES);
		}
		return status;
	}


	/* Send this CNH configuration to the sensor.										*/
	status = vl53lmz_cnh_send_config(&p_dev,&cnh_config);
	if (status != VL53LMZ_STATUS_OK){
		printf("VL53LMZ CNH send config failed\n");
		return status;
	}

	/* First create the standard data upload(output) configuration. 						*/
	status = vl53lmz_create_output_config(&p_dev);
	if (status != VL53LMZ_STATUS_OK){
		printf("VL53LMZ CNH create output config failed\n");
		return status;
	}

	/* Next, add the CNH data block, sized correctly for the configuration we are using. */
	union Block_header cnh_data_bh;
	cnh_data_bh.idx = VL53LMZ_CNH_DATA_IDX;
	cnh_data_bh.type = 4;
	cnh_data_bh.size = cnh_data_size / 4;
	status = vl53lmz_add_output_block(&p_dev, cnh_data_bh.bytes);
	if (status != VL53LMZ_STATUS_OK){
		printf("VL53LMZ CNH add output block failed\n");
		return status;
	}

	status = vl53lmz_send_output_config_and_start(&p_dev);

	   	printf("Started ranging\n");



  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
	   	while (1)

	   	{

	   		   		// __________________ MY CODE _______________
	   		   	    uint8_t buffer[512];
	   		   	    uint8_t *ptr = buffer;
	   		   	    size_t buffer_index = 0;  // To keep track of the actual size of the data

	   		   	    status = vl53lmz_check_data_ready(&p_dev, &isReady);
	   		   	    if (isReady)
	   		   	    {
	   		   	        vl53lmz_get_ranging_data(&p_dev, &Results);

	   		   	        printf("Print data no : %3u\n", p_dev.streamcount);
	   		   	        for (i = 0; i < 64; i++)
	   		   	        {


	   		   	            uint16_t zone = i;
	   		   	            uint16_t distance = Results.distance_mm[VL53LMZ_NB_TARGET_PER_ZONE * i];
                            /*
	   		   	            memcpy(ptr + buffer_index, &zone, sizeof(uint16_t));
	   		   	            buffer_index += sizeof(uint16_t);
	   		   	            memcpy(ptr + buffer_index, &distance, sizeof(uint16_t));
	   		   	            buffer_index += sizeof(uint16_t);
                             */
	   		   	           printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
	   		   	                   i,
	   		   	                   Results.target_status[VL53LMZ_NB_TARGET_PER_ZONE * i],
	   		   	                   distance);
	   		   	        }

	   		   	        status = vl53lmz_results_extract_block(&p_dev, VL53LMZ_CNH_DATA_IDX, (uint8_t *)cnh_data_buffer, cnh_data_size);
	   		   	        if (status != VL53LMZ_STATUS_OK)
	   		   	        {
	   		   	            printf("ERROR at %s(%d) : vl53lmz_results_extract_block failed : %d\n", __func__, __LINE__, status);
	   		   	            return status;
	   		   	        }

	   		   	        for (agg_id = 0; agg_id < cnh_config.nb_of_aggregates; agg_id++)
	   		   	        {
	   		   	            vl53lmz_cnh_get_block_addresses(&cnh_config,
	   		   	                                            agg_id,
	   		   	                                            cnh_data_buffer,
	   		   	                                            &(p_hist), &(p_hist_scaler),
	   		   	                                            &(p_ambient), &(p_ambient_scaler));

	   		   	            amb_value = ((float)*p_ambient) / (2 << *p_ambient_scaler);

	   		   	            printf("Agg, %2d, Ambient, % .1f, Bins, ", agg_id, amb_value);

	   		   	            for (bin_num = 0; bin_num < cnh_config.feature_length; bin_num++)
	   		   	            {
	   		   	                bin_value = ((float)p_hist[bin_num]) / (2 << p_hist_scaler[bin_num]);
	   		   	                printf("% .1f, ", bin_value);
	   		   	            }
                             /*
	   		   	            uint16_t Agg_id = agg_id;
	   		   	            float ambient = amb_value;
	   		   	            float bins_val = bin_value;

	   		   	            memcpy(ptr + buffer_index, &Agg_id, sizeof(uint16_t)); buffer_index += sizeof(uint16_t);
	   		   	            memcpy(ptr + buffer_index, &ambient, sizeof(float));  buffer_index += sizeof(float);
	   		   	            memcpy(ptr + buffer_index, &bins_val, sizeof(float)); buffer_index += sizeof(float);
                              */
	   		   	            // Now transmit only the actual data in the buffer
	   		   	            //HAL_UART_Transmit(&huart2, sizeof(buffer) , buffer, HAL_MAX_DELAY) ;

	   		   	            printf("\n");
	   		   	        }

	   		   	        loop++;
	   		   	    }

	   		   	    // Wait a few ms to avoid too high polling
	   		   	   // WaitMs(&(p_dev.platform), 5);
	   		   	    HAL_MAX_DELAY;
	   		   	}




}
0 REPLIES 0