Page 1 of 1

VL6180 Time-of-flight Range Sensor

Posted: Fri May 13, 2016 11:41 pm
by deshipu
Another driver for the ESP8266 port, this time an I²C-based distance sensor, VL6180. This is mostly based on the Sparkfun's Arduino library. For now just distance measurement. https://bitbucket.org/thesheep/micropython-vl6180/src

Re: VL6180 Time-of-flight Range Sensor

Posted: Sat Jul 21, 2018 8:25 pm
by shanemm
Very useful library. It took me a minute to figure out how it works because I don't know python but here's my code that worked on esp32 and displays a value from 0-255 depending on the range sensed:


------------------------------------------------------------------------------------------------------------------------
import network
import machine
import esp
import neopixel
import time
from machine import I2C
from vl6180 import Sensor
from machine import Pin
from umqtt.simple import MQTTClient

def D2L():
i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22))
sensor=Sensor(i2c)
np=neopixel.NeoPixel(machine.Pin(5),1)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect("name_of_network", "password")
sta_if.isconnected()
client = MQTTClient('some mqtt number', 'test.mosquitto.org')
client.connect()

while 1:
x=sensor.range()
np[0]=(0,0,x)
np.write()
client.publish('name_of_network', str(x))
------------------------------------------------------------------------------------------------------------------------

It looks like the scaling isn't working right and I only get from 10 to 50 before the sensor jumps to 255. If anyone knows what I might be doing wrong here I'd appreciate some suggestions. Otherwise I'll post back here when I figure it out.

Re: VL6180 Time-of-flight Range Sensor

Posted: Wed Jul 25, 2018 10:12 pm
by vic_sf
Hi deshipu,

Would you know if this sensor and library will work with micro:bit?

Re: VL6180 Time-of-flight Range Sensor

Posted: Tue May 28, 2019 3:06 am
by spacemanspiffee
[quote=shanemm post_id=28740 time=1532204724 user_id=4158]
Very useful library. It took me a minute to figure out how it works because I don't know python but here's my code that worked on esp32 and displays a value from 0-255 depending on the range sensed:


------------------------------------------------------------------------------------------------------------------------
import network
import machine
import esp
import neopixel
import time
from machine import I2C
from vl6180 import Sensor
from machine import Pin
from umqtt.simple import MQTTClient

def D2L():
i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22))
sensor=Sensor(i2c)
np=neopixel.NeoPixel(machine.Pin(5),1)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect("name_of_network", "password")
sta_if.isconnected()
client = MQTTClient('some mqtt number', 'test.mosquitto.org')
client.connect()

while 1:
x=sensor.range()
np[0]=(0,0,x)
np.write()
client.publish('name_of_network', str(x))
------------------------------------------------------------------------------------------------------------------------

It looks like the scaling isn't working right and I only get from 10 to 50 before the sensor jumps to 255. If anyone knows what I might be doing wrong here I'd appreciate some suggestions. Otherwise I'll post back here when I figure it out.
[/quote]

There is a simple way to fix this, requiring only a small change to the vl6180x.py file.
At line 84: "self._set_reg8(0x002D, 0x10 | 0x01) # Range check enables"
delete the | 0x01 so that the line now looks like: "self._set_reg8(0x002D, 0x10) # Range check enables"

This disables an error caused by issues with convergence timing and extended the range out to about 190 mm for me.

Re: VL6180 Time-of-flight Range Sensor

Posted: Mon Dec 13, 2021 1:42 pm
by soggycashew
I know this is an old post but I need a VL6180x driver for micropython with an example, your link is dead you posted.

Thanks!

Re: VL6180 Time-of-flight Range Sensor

Posted: Mon Dec 13, 2021 3:13 pm
by rkompass
On https://awesome-micropython.com there is a link to the driver that works.