cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L1X range status 4 on long range

SBann.1
Associate II

I'm trying to measure distance in a very dark environment. I'm using long-range distance mode. Suddenly, the sensor started sending error 4. What can cause this and how to fix it?

Fixed, caused by an issue in the code.

4 REPLIES 4
John E KVAM
ST Employee

Well done! issues in the code are the hardest to find from this far away. Thanks for the update.


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.

@John E KVAM​ I'm having another issue. The distance ranging mode is not being switched when using this code:

// Send settings to sensor
// Delays are used to make sure we do not send to fast
Sensor->SetDistanceMode(DistanceMode);
DelayMs(50);
Sensor->SetTimingBudgetInMs(TimingBudgetSensorMs);
DelayMs(50);
Sensor->SetSignalThreshold(SignalThreshold);
DelayMs(50);
	
// Timeout period to make sure everything is set correctly
DelayMs(500);
	
// Start ranging
Sensor->StartRanging();
	
// Wait until measurement data is ready
uint8_t dataReady = false;
while(!dataReady) {
	Sensor->CheckForDataReady(&dataReady);
	DelayMs(5);
}
	
// Read measurement data
Sensor->GetDistanceInMm(&DistanceMM);
Sensor->GetRangeStatus(&SensorStatus);
Sensor->GetSignalRate(&Signal);
	
// Clear interrupt status (means that we are ready for next measurement)
Sensor->ClearInterrupt();
	
// Stop ranging
Sensor->StopRanging();

When I set DistanceMode to Short I get a RangeStatus error (4). Then I try running the same code with Long distancemode, but that isn't applied to the VL53L1X. I still get RangeStatus error 4 with almost the same signal value. How to fix?

John E KVAM
ST Employee

Range status 4 - VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL

What happens is that there are 2 sub-ranges per range with slightly different pulse intervals.

This is to detect wrap-around (also called Aliasing) where the photons from pulse N come back after the N+1 pulse, making a 4.1 meter range look like a 0.1 meter range.

But if there is a lot of motion you will also get a 4. Simply because the two sub-ranges give different results. (In whjich case you can treat the 4 as a warning, the returned distance was correct when the data was taken.)

The only other thing I can think of is that the call failed. I cannot tell if you are checking the return or not.

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

@John E KVAM​ It does not make a lot of sense.

Changed my code to the following:

Sensor->SetTimingBudgetInMs(TimingBudgetSensorMs);
Sensor->SetSignalThreshold(GetSignalThresholdShort());
Sensor->SetDistanceMode(EDistanceMode::Short);
DelayMs(500);
	
Sensor->StartRanging();
	
uint8_t dataReady = false;
while(!dataReady) {
	Sensor->CheckForDataReady(&dataReady);
	PowerManager::DelayMs(1);
}
	
Sensor->GetRangeStatus(&SensorStatusShort);
Sensor->GetDistanceInMm(&DistanceMM);
Sensor->GetSignalRate(&SignalShort);
	
Sensor->ClearInterrupt();
	
Sensor->StopRanging();
	
if(SensorStatusShort != ERangeStatus::RangeValid) {
	Sensor->SetTimingBudgetInMs(TimingBudgetSensorMs);
	Sensor->SetSignalThreshold(GetSignalThresholdLong());
	Sensor->SetDistanceMode(EDistanceMode::Long);
	DelayMs(500);
		
	Sensor->StartRanging();
		
	dataReady = false;
	while(!dataReady) {
		Sensor->CheckForDataReady(&dataReady);
		PowerManager::DelayMs(1);
	}
		
	Sensor->GetRangeStatus(&SensorStatusLong);
	Sensor->GetDistanceInMm(&DistanceMM);
	Sensor->GetSignalRate(&SignalLong);
		
	Sensor->ClearInterrupt();
		
	Sensor->StopRanging();
}

Sometimes I get 300cm in Short ranging mode (not even possible???). Sometimes I get error 4 in Long ranging mode with the same signal as in Short ranging mode.

Can you check the order of this code and make sure it's valid? It seems like the settings are not even applied to the sensor at all.