Home CodeCircuitpython Raspberry Pi Pico and VL6180X module circuitpython example

Raspberry Pi Pico and VL6180X module circuitpython example

by rp2040guy71

In this article we connect a VL6180X  to a Raspberry Pi Pico running Circuitpython

Sensor Information

First lets look at some information about the sensor from the manufacturer

The VL6180X is a ground-breaking technology allowing absolute distance to be measured independent of target reflectance.

Instead of estimating the distance by measuring the amount of light reflected back from the object (which is significantly influenced by color and surface), the VL6180X precisely measures the time the light takes to travel to the nearest object and reflect back to the sensor (Time-of-Flight).

Combining an IR emitter, a range sensor and an ambient light sensor, the VL6180X is easy to integrate and saves the end-product maker long and costly optical and mechanical design optimizations.

The module is designed for low power operation. Ranging and ALS measurements can be automatically performed at user defined intervals. Multiple threshold and interrupt schemes are supported to minimize host operations.

Host control and result reading is performed using an I2C interface. Optional additional functions, such as measurement ready and threshold interrupts, are provided by two programmable GPIO pins.

Key Features

  • Three-in-one smart optical module
    • Proximity sensor
    • Ambient Light Sensor
    • VCSEL light source
  • Fast, accurate distance ranging
    • Measures absolute range from 0 to above 10 cm (ranging beyond 10cm is dependent on conditions)
    • Independent of object reflectance
    • Ambient light rejection
    • Cross-talk compensation for cover glass
  • Gesture recognition
    • Distance and signal level can be used by host system to implement gesture recognition
  • Ambient light sensor
    • High dynamic range
    • Accurate/sensitive in ultra-low light
    • Calibrated output value in lux
  • Two programmable GPIO
    • Window and thresholding functions for both ranging and ALS
This was my sensor of choice that I used

Parts Required

 

Name Link
Pico Raspberry Pi Pico Development Board
VL6180X VL6180X Range Finder Optical Ranging Sensor Module
Connecting cables Aliexpress product link

Amazon.com link

Ebay link

 

Schematic/Connection

I used the Adafruit vl6180x sensor and in this case used the Stemma connection

For the STEMMA QT cables, it uses the Qwiic convention:

Black for GND
Red for V+
Blue for SDA
Yellow for SCL

So color coded for ease of use, this layout shows a connection to the module

Code Example

I used Thonny for development

The following is based on a library , I copied the adafruit_vl6180x.mpy library for this device to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries

This is the basic example which comes with the library

[codesyntax lang=”python”]

import time
import board
import adafruit_vl6180x
import busio

# Create sensor object, communicating over the board's default I2C bus
i2c = busio.I2C(scl=board.GP1, sda=board.GP0) # uses board.SCL and board.SDA
sensor = adafruit_vl6180x.VL6180X(i2c)

# Main loop prints the range and lux every second:
while True:
    # Read the range in millimeters and print it.
    range_mm = sensor.range
    print("Range: {0}mm".format(range_mm))
    # Read the light, note this requires specifying a gain value:
    # - adafruit_vl6180x.ALS_GAIN_1 = 1x
    # - adafruit_vl6180x.ALS_GAIN_1_25 = 1.25x
    # - adafruit_vl6180x.ALS_GAIN_1_67 = 1.67x
    # - adafruit_vl6180x.ALS_GAIN_2_5 = 2.5x
    # - adafruit_vl6180x.ALS_GAIN_5 = 5x
    # - adafruit_vl6180x.ALS_GAIN_10 = 10x
    # - adafruit_vl6180x.ALS_GAIN_20 = 20x
    # - adafruit_vl6180x.ALS_GAIN_40 = 40x
    light_lux = sensor.read_lux(adafruit_vl6180x.ALS_GAIN_1)
    print("Light (1x gain): {0}lux".format(light_lux))
    # Delay for a second.
    time.sleep(1.0)

[/codesyntax]

Output

Here is what I saw in Thonny REPL window

Range: 95mm
Light (1x gain): 0.0lux
Range: 94mm
Light (1x gain): 0.0lux
Range: 96mm
Light (1x gain): 0.0lux
Range: 27mm
Light (1x gain): 0.0lux
Range: 17mm
Light (1x gain): 0.0lux
Range: 19mm
Light (1x gain): 0.0lux

Links

https://www.st.com/resource/en/datasheet/vl6180x.pdf

You may also like

1 comment

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More