adafruit_vl6180x

CircuitPython module for the VL6180X distance sensor. See examples/simpletest.py for a demo of the usage.

  • Author(s): Tony DiCola, Jonas Schatz

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_vl6180x.VL6180X(i2c: I2C, address: int = 41, offset: int = 0)[source]

Create an instance of the VL6180X distance sensor. You must pass in the following parameters:

Parameters:

i2c (~I2C) – An instance of the I2C bus connected to the sensor.

Optionally you can specify:

Parameters:
  • address (int) – The I2C address of the sensor. If not specified the sensor’s default value will be assumed.

  • offset (int) – The offset to be applied to measurements, in mm

property continuous_mode_enabled: bool

Checks if continuous mode is enabled

property offset: int

Read and sets the manual offset for the sensor, in millimeters

property range: int

Read the range of an object in front of sensor and return it in mm.

property range_from_history: int | None

Read the latest range data from history To do so, you don’t have to wait for a complete measurement.

property range_history_enabled: bool

Checks if history buffer stores range data

property range_status: int

Retrieve the status/error from a previous range read. This will return a constant value such as:

Error

Description

ERROR_NONE

No error

ERROR_SYSERR_1

System error 1 (see datasheet)

ERROR_SYSERR_5

System error 5 (see datasheet)

ERROR_ECEFAIL

ECE failure

ERROR_NOCONVERGE

No convergence

ERROR_RANGEIGNORE

Outside range ignored

ERROR_SNR

Too much noise

ERROR_RAWUFLOW

Raw value underflow

ERROR_RAWOFLOW

Raw value overflow

ERROR_RANGEUFLOW

Range underflow

ERROR_RANGEOFLOW

Range overflow

property ranges_from_history: List[int] | None

Read the last 16 range measurements from history

read_lux(gain: int) float[source]

Read the lux (light value) from the sensor and return it. Must specify the gain value to use for the lux reading:

Setting

Value

ALS_GAIN_1

1x

ALS_GAIN_1_25

1.25x

ALS_GAIN_1_67

1.67x

ALS_GAIN_2_5

2.5x

ALS_GAIN_5

5x

ALS_GAIN_10

10x

ALS_GAIN_20

20x

ALS_GAIN_40

40x

Parameters:

gain (int) – The gain value to use

start_range_continuous(period: int = 100) None[source]

Start continuous range mode

Parameters:

period (int) – Time delay between measurements, in milliseconds; the value you will be floored to the nearest 10 milliseconds (setting to 157 ms sets it to 150 ms). Range is 10 - 2550 ms.

stop_range_continuous() None[source]

Stop continuous range mode. It is advised to wait for about 0.3s afterwards to avoid issues with the interrupt flags