VL6180 Time-of-flight Range Sensor

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
User avatar
deshipu
Posts: 1347
Joined: Thu May 28, 2015 5:54 pm

VL6180 Time-of-flight Range Sensor

Post by deshipu » Fri May 13, 2016 11:41 pm

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

shanemm
Posts: 1
Joined: Sat Jul 21, 2018 8:21 pm

Re: VL6180 Time-of-flight Range Sensor

Post by shanemm » Sat Jul 21, 2018 8:25 pm

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.

vic_sf
Posts: 1
Joined: Wed Jul 25, 2018 10:06 pm

Re: VL6180 Time-of-flight Range Sensor

Post by vic_sf » Wed Jul 25, 2018 10:12 pm

Hi deshipu,

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

spacemanspiffee
Posts: 1
Joined: Tue May 28, 2019 3:00 am

Re: VL6180 Time-of-flight Range Sensor

Post by spacemanspiffee » Tue May 28, 2019 3:06 am

[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.

Post Reply