Example 4: Set Intermeasurement Period

examples/Example4_SetIntermeasurementPeriod.py
 1#-----------------------------------------------------------------------
 2# VL53L1X - Example 4
 3#-----------------------------------------------------------------------
 4#
 5# Ported by  SparkFun Electronics, October 2019
 6# Author: Nathan Seidle
 7# Ported: Wes Furuya
 8# SparkFun Electronics
 9# 
10# License: This code is public domain but you buy me a beer if you use
11# this and we meet someday (Beerware license).
12#
13# Compatibility: https://www.sparkfun.com/products/14722
14# 
15# Do you like this library? Help support SparkFun. Buy a board!
16# For more information on VL53L1x (ToF), check out the product page
17# linked above.
18#
19# This program is distributed in the hope that it will be useful, but
20# WITHOUT ANY WARRANTY without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22# General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program.  If not, see <http:www.gnu.org/licenses/>.
26#
27#=======================================================================
28# Copyright (c) 2019 SparkFun Electronics
29#
30# Permission is hereby granted, free of charge, to any person obtaining
31# a copy of this software and associated documentation files (the
32# "Software"), to deal in the Software without restriction, including
33# without limitation the rights to use, copy, modify, merge, publish,
34# distribute, sublicense, and/or sell copies of the Software, and to
35# permit persons to whom the Software is furnished to do so, subject to
36# the following conditions:
37#
38# The above copyright notice and this permission notice shall be
39# included in all copies or substantial portions of the Software.
40#
41# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
42# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48#=======================================================================
49
50"""
51	Reading distance from the laser based VL53L1X
52
53	This example configures the inter-measurement period of the sensor
54	and then prints the distance to an object. If you are getting weird
55	readings, be sure the vacuum tape has been removed from the sensor.
56"""
57
58import qwiic
59import time
60
61print("VL53L1X Qwiic Test\n")
62ToF = qwiic.QwiicVL53L1X()
63
64if (ToF.sensor_init() == None):					 # Begin returns 0 on a good init
65	print("Sensor online!\n")
66
67ToF.set_inter_measurement_in_ms(40)
68
69print("Inter Measurement Period (ms): %s \n", ToF.get_inter_measurement_in_ms())
70
71while True:
72	try:
73		ToF.start_ranging()						 # Write configuration bytes to initiate measurement
74		time.sleep(.005)
75		distance = ToF.get_distance()	 # Get the result of the measurement from the sensor
76		time.sleep(.005)
77		ToF.stop_ranging()
78
79		distanceInches = distance / 25.4
80		distanceFeet = distanceInches / 12.0
81
82		print("Distance(mm): %s Distance(ft): %s" % (distance, distanceFeet))
83
84	except Exception as e:
85		print(e)