Connecting two distance sensors
We have wired in two sensors, each on a separate set of pins. Create the read_2_sensors.py
file. The imports look identical:
import time import board import busio import adafruit_vl53l1x
When we come to set up the sensors, we first need to set up two I2C
buses on the different pins and then use them:
i2c0 = busio.I2C(sda=board.GP0, scl=board.GP1) i2c1 = busio.I2C(sda=board.GP2, scl=board.GP3) vl53_l = adafruit_vl53l1x.VL53L1X(i2c0) vl53_r = adafruit_vl53l1x.VL53L1X(i2c1)
We can also apply the same configuration settings for both sensors:
vl53_l.distance_mode = 1 vl53_l.timing_budget = 100 vl53_r.distance_mode = 1 vl53_r.timing_budget = 100
The main loop starts in the same way, with both sensors going into ranging mode:
vl53_l.start_ranging() vl53_r.start_ranging() while True:
And in this case, we will check for ready data from both sensors before printing:
if vl53_l.data_ready and vl53_r.data_ready:...