Example 4: Set Intermeasurement Period

examples/Example4_SetIntermeasurementPeriod.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
	Reading distance from the laser based VL53L1X
	By: Nathan Seidle
	Ported: Wes Furuya
	SparkFun Electronics
	Date: October 31, 2019
	License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

	SparkFun labored with love to create this code. Feel like supporting open source hardware?
	Buy a board from SparkFun! https://www.sparkfun.com/products/14667

	This example prints the distance to an object.

	Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
"""

from qwiic_VL53L1X import VL53L1X
import time

print("VL53L1X Qwiic Test\n")
ToF = VL53L1X()

if (ToF.SensorInit() == None):					 # Begin returns 0 on a good init
	print("Sensor online!\n")

ToF.SetInterMeasurementInMs(40)

print("Inter Measurement Period (ms): %s \n", ToF.GetInterMeasurementInMs())

while True:
	try:
		ToF.StartRanging()						 # Write configuration bytes to initiate measurement
		time.sleep(.005)
		distance = ToF.GetDistance()	 # Get the result of the measurement from the sensor
		time.sleep(.005)
		ToF.StopRanging()

		distanceInches = distance / 25.4
		distanceFeet = distanceInches / 12.0

		print("Distance(mm): %s Distance(ft): %s" % (distance, distanceFeet))

	except Exception as e:
		print(e)