-
Notifications
You must be signed in to change notification settings - Fork 1
/
vl53l1x_example.py
49 lines (40 loc) · 1.32 KB
/
vl53l1x_example.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
45
46
47
48
49
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2021 Carter Nelson for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
# Simple demo of the VL53L1X distance sensor.
# Will print the sensed range/distance every second.
import utime
from machine import I2C
from pyb import Pin
import adafruit_vl53l1x
#i2c2_scl = Pin(Pin.cpu.B13)
#i2c2_scl.init(mode=Pin.ALT, alt=Pin.AF4_I2C2)
#i2c2_sda = Pin(Pin.cpu.B14)
#i2c2_sda.init(mode=Pin.ALT, alt=Pin.AF4_I2C2)
i2c = I2C(1, freq=400_000)
vl53 = adafruit_vl53l1x.VL53L1X(i2c)
# OPTIONAL: can set non-default values
vl53.distance_mode = 1
vl53.timing_budget = 50
print("VL53L1X Simple Test.")
print("--------------------")
model_id, module_type, mask_rev = vl53.model_info
print("Model ID: 0x{:0X}".format(model_id))
print("Module Type: 0x{:0X}".format(module_type))
print("Mask Revision: 0x{:0X}".format(mask_rev))
print("Distance Mode: ", end="")
if vl53.distance_mode == 1:
print("SHORT")
elif vl53.distance_mode == 2:
print("LONG")
else:
print("UNKNOWN")
print("Timing Budget: {}".format(vl53.timing_budget))
print("--------------------")
vl53.start_ranging()
while True:
if vl53.data_ready:
print("Distance: {} mm".format(vl53.distance))
vl53.clear_interrupt()
time.sleep(0.2)