Skip to content

Commit

Permalink
1) Add function to VL53L0X.py to show how to call the ST Library dire…
Browse files Browse the repository at this point in the history
…ctly from Python

2) Update example so time between calls to get_distance is based on device timing
  • Loading branch information
johnbryanmoore committed Jan 23, 2017
1 parent a9d6ad3 commit 19f8462
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions python/VL53L0X.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,15 @@ def get_distance(self):
"""Get distance from VL53L0X ToF Sensor"""
return tof.getDistance()

# This function included to show how to access the ST library directly
# from python instead of through the simplified interface
def get_timing(self):
Dev = POINTER(c_void_p)
Dev = tof.VL53L0X_get_dev()
budget = c_uint(0)
budget_p = pointer(budget)
Status = tof.VL53L0X_GetMeasurementTimingBudgetMicroSeconds(Dev, budget_p)
if (Status == 0):
return (budget.value + 1000)
else:
return 0
7 changes: 5 additions & 2 deletions python/VL53L0X_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@

tof.start_ranging(VL53L0X.VL53L0X_BETTER_ACCURACY_MODE)

for count in range(1,1001):
timing = tof.get_timing()
print ("Timing %d ms" % (timing/1000))

for count in range(1,101):
distance = tof.get_distance()
if (distance > 0):
cumul += distance
print ("%d mm, %d cm, %.2f avg, %d diff, %.2f from avg, %d count" % (distance, (distance/10), (float(cumul)/count), (last - distance), (float(cumul)/count)-distance, count))
last = distance
time.sleep(0.10)
time.sleep(timing/1000000.00)

tof.stop_ranging()

0 comments on commit 19f8462

Please sign in to comment.