Skip to content

Time of Flight Distance Wireling Python Tutorial

TinyCircuits Time-of-Flight Wireling product photo

This Wireling features a VL53L0X Infrared Time-of-Flight sensor, most often used for distance detection between 2cm and 2m!

Technical Details

VL53L0X Time-of-Flight Sensor Specs

  • Fully integrated miniature module
    • 940 nm laser VCSEL
    • VCSEL driver
    • Ranging sensor with advanced embedded micro controller
  • Fast, accurate distance ranging
    • Measures absolute range up to 2m
    • Reported range is independent of the target reflectance
    • Advanced embedded optical cross-talk compensation to simplify cover glass selection
  • Eye safe
  • I²C
    • Compatible with 400 kHz (FAST mode)
    • Address: 0x52

TinyDuino Power Requirements

  • Voltage: 3.0V - 5.5V 
  • Current:
    • Hardware Standby: 5uA
    • Software Standby: 6uA
    • Timed Ranging Inter Measurement: 16uA
    • Active Ranging Average Consumption: 19mA

Pins Used

  • A5/SCL - I²C Serial Clock line
  • A4/SDA - I²C Serial Data line

Dimensions

  • 10mm x 10mm (.393 inches x .393 inches)
  • Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 3.70mm (0.15 inches)
  • Weight: 1 gram (.04 ounces)

Materials

Hardware

Required Software

  • Python 3 (Python 2 is not supported!)
  • All Python packages mentioned in the Pi Hat setup tutorial (tinycircuits-wireling, Adafruit-Blinka, adafruit-circuitpython-ads1x15, and adafruit-circuitpython-busdevice)
  • The VL53l0X package mentioned later
  • VL53l0X Python Example

Hardware Assembly

Plug your Wireling into the port you plan on using! The default in the included program is port 0.

If you want to use a different port, you just need to change the port value in the program mentioned later.


Programming

Install the necessary library:

pip3 install adafruit-circuitpython-vl53l0x

Then you can download (above under Software) the Time-of-Flight Distance Sensor Wireling Python example:

vl53l0x_example.py
# Simple demo of the VL53L0X distance sensor.
# This program is meant to be used with a Wireling Pi Hat, and Time of Flight (Distance) Sensor Wireling
# Prints the distance in mm read by the sensor every second
# Adapted from Adafruit example by: Corey Miller for TinyCircuits
# Initialized: 9-10-19
# Last Updated: 12-16-19

import time
import board
import busio
import adafruit_vl53l0x
import tinycircuits_wireling

# Initialize and enable power to Wireling Pi Hat
wireling = tinycircuits_wireling.Wireling()

# Toggle this variable to use the Light Sensor Wireling on a different port (0-3)
port = 0
wireling.selectPort(port)

# Initialize I2C bus and sensor.
i2c = busio.I2C(board.SCL, board.SDA)
vl53 = adafruit_vl53l0x.VL53L0X(i2c)

# Optionally adjust the measurement timing budget to change speed and accuracy.
# See the example here for more details:
#   https://github.com/pololu/vl53l0x-arduino/blob/master/examples/Single/Single.ino
# For example a higher speed but less accurate timing budget of 20ms:
#vl53.measurement_timing_budget = 20000
# Or a slower but more accurate timing budget of 200ms:
#vl53.measurement_timing_budget = 200000
# The default timing budget is 33ms, a good compromise of speed and accuracy.

# Main loop will read the range and print it every second.
while True:
    print('Range: {0}mm'.format(vl53.range))
    time.sleep(1.0)


Run Program

Navigate in the terminal to the directory with the file parent to the examples folder.

python3 vl53l0x_example.py

The distance read by the sensor will then begin printing out in terms of mm every second. The sensor is extremely accurate up to 2m from the sensor, and fairly accurate past that. Results may be inaccurate if the sensor is less than 20mm far away from any object.


Downloads


Contact Us

If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

Thanks for making with us!