Skip to content

Commit d16485b

Browse files
committed
(-) comments & (+) instructions to examples.rst
1 parent 97b755b commit d16485b

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

docs/examples.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Ensure your device works with this simple test.
1010
Multiple VL53L0X on Same I2C Bus
1111
--------------------------------
1212

13+
Copy "../examples/vl53l0x_multiple_sensors.py" to your "CIRCUITPY" drive, then run the script with ``from vl53l0x_multiple_sensors import *``
14+
1315
.. literalinclude:: ../examples/vl53l0x_multiple_sensors.py
1416
:caption: examples/vl53l0x_multiple_sensors.py
1517
:linenos:

examples/vl53l0x_multiple_sensors.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,50 @@
77
"""
88
import time
99
import board
10-
import busio
1110
from digitalio import DigitalInOut
1211
from adafruit_vl53l0x import VL53L0X
1312

14-
# declare the singleton variable for the default I2C bus
15-
i2c = busio.I2C(board.SCL, board.SDA)
13+
# declare the singleton variable for the default I2C bus
14+
i2c = board.I2C()
1615

17-
# declare the digital output pins connected to the "SHDN" pin on each VL53L0X sensor (this
18-
# pin is labeled "XSHUT" on non-Adafruit breakout boards). Default behavior upon
19-
# instantiation is (direction=INPUT) + (pull=None) = LOW output signal
20-
x_shut = [
16+
# declare the digital output pins connected to the "SHDN" pin on each VL53L0X sensor
17+
xshut = [
2118
DigitalInOut(board.D7),
2219
DigitalInOut(board.D9)
20+
# add more sensors by defining their SHDN pins here
2321
]
24-
# idealy you might want to use an IO extender as these pins are only used to control the
25-
# VL53L0X's power state.
2622

27-
for power_pin in x_shut:
28-
# make sure these pins are an digital output, not a digital input
23+
for power_pin in xshut:
24+
# make sure these pins are a digital output, not a digital input
2925
power_pin.switch_to_output(value=False)
3026
# These pins are active when Low, meaning:
3127
# if the output signal is LOW, then the VL53L0X sensor is off.
3228
# if the output signal is HIGH, then the VL53L0X sensor is on.
33-
# (value=False) = LOW output signal; LOW output disables/shutsdown the VL53L0X
3429
# all VL53L0X sensors are now off
3530

3631
# initialize a list to be used for the array of VL53L0X sensors
3732
vl53 = []
3833

3934
# now change the addresses of the VL53L0X sensors
40-
for i, power_pin in enumerate(x_shut):
35+
for i, power_pin in enumerate(xshut):
4136
# turn on the sensor to allow hardware check
4237
power_pin.value = True
4338
# instantiate the VL53L0X sensors on the I2C bus & insert it into the "vl53" list
4439
vl53.insert(i, VL53L0X(i2c)) # also performs hardware check
4540
# don't need to change the address of the last VL53L0X sensor
46-
if i < len(x_shut) - 1:
41+
if i < len(xshut) - 1:
4742
# default address is 0x29. Change that to something else
48-
vl53[i].set_address(i + 0x30) # address assigned should not be already in use
43+
vl53[i].set_address(i + 0x30) # address assigned should NOT be already in use
4944
# there is a helpful list of pre-designated I2C addresses for various I2C devices at
5045
# https://learn.adafruit.com/i2c-addresses/the-list
51-
# According to this list 0x30-0x34 are available although the list may be outdated/incomplete.
52-
# you can scan for all I2C devices and detirmine their addresses using:
53-
# "i2cdetect 1 -y" (without quotes) on a Raspberry Pi terminal or
54-
# In the python REPR, execute the following commands:
46+
# According to this list 0x30-0x34 are available, although the list may be incomplete.
47+
# In the python REPR, you can scan for all I2C devices that are attached and detirmine
48+
# their addresses using:
5549
# >>> import busio
5650
# >>> i2c = busio.I2C(board.SCL, board.SDA)
57-
# >>> i2c.try_lock() # if False is returned: something else is using the i2c bus
58-
# >>> [hex(x) for x in i2c.scan()]
59-
# >>> i2c.unlock() # free up the bus for something else to use it
51+
# >>> if i2c.try_lock(): # i2c.scan() requires a lock on the I2C bus
52+
# >>> [hex(x) for x in i2c.scan()]
53+
# >>> i2c.unlock() # free up the bus for something else to use it
6054

6155
def detect_range(count=5):
6256
""" take count=5 samples """
@@ -66,6 +60,5 @@ def detect_range(count=5):
6660
time.sleep(1.0)
6761
count -= 1
6862

69-
print("""\
70-
multiple VL53L0X sensors' addresses are assigned properly\n\
71-
execute detect_range() to read each sensors range readings""")
63+
print("Multiple VL53L0X sensors' addresses are assigned properly\n"
64+
"execute detect_range() to read each sensors range readings")

0 commit comments

Comments
 (0)