cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L1X - implementing non-blocking communication

farmingmachine
Associate

Hello!

I am using the vl53l1x on a raspberry pi with python (pimoroni library) and want to implement the NON-BLOCKING communication

So I changed the “wait_method�? in the api (vl53l1_api_core.c) for measurements to NON_BLOCKING and recompiled/reinstalled the module with the following funtion to get the distance from the sensor:

 ```c

int32_t getDistance(VL53L1_Dev_t *dev)

{

VL53L1_Error Status = VL53L1_ERROR_NONE;

int32_t current_distance = -1;

uint8_t dataready = 0;

Status = VL53L1_GetMeasurementDataReady(dev, &dataready); // VL53L1_GetMeasurementDataReady takes a pointer, so we pass the address of dataready

if (dataready == 1)

{

Status = VL53L1_GetRangingMeasurementData(dev, pRangingMeasurementData);

current_distance = pRangingMeasurementData->RangeMilliMeter;

VL53L1_ClearInterruptAndStartMeasurement(dev);

}

return current_distance;

}

``` 

However, using the following code in Python, the result is still a blocking/waiting communication for when data is ready (dataready=1). I used the following code and printed out the time spent for the get_distance() function. As you can see, it is 1 ms for when data is not ready and about 30 ms for when data is ready (tried it with different timing budgets and periods, but same effect of 30 ms waiting)

The Python code for the picture:

tof.set_timing(30000, 40)

print("budget", tof.get_timing())

time.sleep(0.5)

while running:

elapsed = 0

current_time = time.time()

time_before = time.time()

distance_in_mm = tof.get_distance() # Grab the range in mm

print("time spend", time.time()-time_before) # print the time spent for grabbing the range

if distance_in_mm>0:

print("Distance: {}mm".format(distance_in_mm))

while elapsed < 0.05: #wait to complete the 50 ms cycle

elapsed = time.time()-current_time

print("50 ms loop done"+"\n")

0 REPLIES 0