Home Circuitpython Adafruit Feather M0 and VL6180X module circuitpython example

Adafruit Feather M0 and VL6180X module circuitpython example

by shedboy71

In this example we connect a VL6180X Proximity sensor, gesture and ambient light sensing (ALS) module to an Adafruit Feather M0 running Circuitpython

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
Adafruit Feather M0 Express Adafruit (PID 3403) Feather M0 Express – Designed for CircuitPython – ATSAMD21 Cortex M0
vl6180x VL6180X Range Finder Optical Ranging Sensor Module
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

feather and vl6180x layout

feather and vl6180x layout

Code Example

I used Mu for development

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

[codesyntax lang=”python”]

# Demo of reading the range and lux from the VL6180x distance sensor and
# printing it every second.
# Author: Tony DiCola
import time

import board
import busio

import adafruit_vl6180x


# Create I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Create sensor instance.
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 Mu REPL window

Light (1x gain): 0.0lux
Range: 73mm
Light (1x gain): 0.0lux
Range: 54mm
Light (1x gain): 0.0lux
Range: 33mm
Light (1x gain): 0.0lux
Range: 15mm

Links

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

You may also like

Leave a Comment