A library to interface with the VL6180X laser time-of-flight sensor.
The VL6180X sensor works from 5mm - 100mm but with good ambient conditions can get measurements up to 200mm.
The package can be installed by adding nerves_vl6180x
to your list of dependencies in mix.exs
:
def deps do
[
{:nerves_vl6180x, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc. Once published, the docs can be found at https://hexdocs.pm/nerves_vl6180x.
# Open the I2C bus, optionally you can also bas the device address
{:ok, ref} = VL6180X.open("i2c-1")
# => {:ok, %VL6180X{bus: #Reference<0.718871911.268566539.177140>, device: 41}}
# Initialize the sensor
VL6180X.init(ref)
# => :ok
# Read distance
distance_in_mm = VL6180X.range(ref)
# => 147
# This is helpful for debugging strange behavior
VL6180X.range_status(ref)
# => {:ok, :no_error}
# The sensor also supports LUX reading, you need to add the GAIN (the support is experimental!)
lux = VL6180X.lux(ref, VL6180X.als_gain_20)
# => {:ok, 0.0}
This library is basically a port of the Adafruit python driver ❤️