Skip to content

Instantly share code, notes, and snippets.

@ma2shita
Created November 4, 2019 03:01
Show Gist options
  • Select an option

  • Save ma2shita/0d4fde03aa65752a10b305004b8700eb to your computer and use it in GitHub Desktop.

Select an option

Save ma2shita/0d4fde03aa65752a10b305004b8700eb to your computer and use it in GitHub Desktop.
VL53L0X(I2C ToF distance sensor) using on Raspberry Pi
import time
import VL53L0X
# Create a VL53L0X object
tof = VL53L0X.VL53L0X(i2c_bus=1, i2c_address=0x29)
# I2C Address can change before tof.open()
# tof.change_address(0x32)
tof.open()
# Start ranging
tof.start_ranging(VL53L0X.Vl53l0xAccuracyMode.BETTER)
timing = tof.get_timing()
if timing < 20000:
timing = 20000
print("Timing %d ms" % (timing/1000))
while True:
distance = tof.get_distance()
if distance > 0:
print("%d mm" % (distance))
time.sleep(timing/1000000.00)
tof.stop_ranging()
tof.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment