Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/VL53LxConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# example config fo VL53L1X distance sensor

DAQModule: VL53LxConfig
type: 1 # sensor type 0: VL53L0X 1: VL53L1x
range : 1 # 1: short 2: medium 3: long range
type: 1 # sensor type 0: VL53L0X 1: VL53L1X
range : 1 # 1: short 2: long range (this setting only affects the VL531X)
2 changes: 0 additions & 2 deletions installlibs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ while true; do

sudo pip3 install installlibs/whl/*.whl; # python wheels

sudo pip3 install installlibs/tgz/*.tar.gz; # python packages

# Install all sensor drivers specified in the
sudo pip3 install -r requirements.txt;

Expand Down
Binary file removed installlibs/tgz/VL53L0X-1.0.4.tar.gz
Binary file not shown.
Binary file removed installlibs/tgz/VL53L1X-0.0.5.tar.gz
Binary file not shown.
91 changes: 46 additions & 45 deletions phypidaq/VL53LxConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,23 @@
from __future__ import print_function, division, unicode_literals
from __future__ import absolute_import

import sys

# import relevant pieces for VL53L0X /1X distance sensor
import VL53L1X
import VL53L0X
import board
import adafruit_vl53l1x
import adafruit_vl53l0x

VL53_Ranges = ['short', 'medium', 'long']
VL53L1_mmRanges = [0., 1300., 3000., 4000.]
VL53L0_mmRanges = [1200., 1200., 1200., 2000., 1200.]
VL53L1_Max_Range = 4000.0
VL53L0_Max_Range = 1200.0


class VL53LxConfig(object):
""" VL53L1X and FL53L0X configuration and interface """
""" VL53L1X and VL53L0X configuration and interface """

def __init__(self, confdict=None):
if confdict is None:
confdict = {}

# -- number of Channels
# if 'NChannels' in confdict:
# self.NChannels = confdict['NChannels']
# else:
# Set the number of channels
self.NChannels = 1 # sensor only has one channel

# sensor type
Expand All @@ -35,59 +30,65 @@ def __init__(self, confdict=None):
self.type = 1 # VL53LX1 is default

if 'range' in confdict:
self.range = confdict['range']
if self.type == 1:
self.mmranges = VL53L1_mmRanges
# Check if the range has a valid value
if confdict['range'] in [1, 2]:
# Set to the given value
self.range = confdict['range']
else:
# Set to default
self.range = 1
else:
self.mmranges = VL53L0_mmRanges
print("VL53Lx: range set to %s " % (self.mmranges[self.range]))
# possible vales VL53L1X: 1 short, 2 medium, 3 long
# possible vales VL53L0X: 0, 1, 2 1.2 m
# 3 2.0 m
# 4 1.2 m, high speed (20ms)
print("Skipping range for the VL53L0X")
else:
self.range = 2 # medium range
if self.type == 1:
# Set the default if nothing is specified
self.range = 1

if 'I2CADDR' in confdict:
self.I2CAddr = confdict['I2CADDR']
print("VL53L1X: I2C address set to %x " % (self.I2CAddr))
print("VL53L1X: I2C address set to %x " % self.I2CAddr)
else:
self.I2CAddr = 0x29 # use default

if 'busnum' in confdict:
self.busnum = confdict['busnum']
print("VL53L1X: bus number set to %x " % (self.busnum))
print("VL53L1X: bus number set to %x " % self.busnum)
else:
self.busnum = 1 # use default

# provide channel parameters
self.ChanNams = ['d']
self.ChanLims = [[0., self.mmranges[self.range]]]
if self.type == 1:
self.ChanLims = [[0., VL53L1_Max_Range]]
else:
self.ChanLims = [[0., VL53L0_Max_Range]]

self.i2c = None
self.sensor = None

def init(self):
# Hardware configuration:
try:
if self.type == 1:
# Create a VL53L1X instance
self.vl53 = VL53L1X.VL53L1X(i2c_bus=self.busnum, i2c_address=self.I2CAddr)
else:
# Create a VL53L0X instance
self.vl53 = VL53L0X.VL53L0X(i2c_bus=self.busnum, i2c_address=self.I2CAddr)
except Exception as e:
print("VLC53L1XConfig: Error initialising device - exit")
print(str(e))
sys.exit(1)
try:
self.vl53.open() # initialise and configure sensor
except Exception as e:
print("VLC53L1XConfig: Error configuring device - exit")
print(str(e))
sys.exit(1)
self.vl53.start_ranging(self.range) # start measurements
self.i2c = board.I2C()
if self.type == 1:
self.sensor = adafruit_vl53l1x.VL53L1X(self.i2c, address=self.I2CAddr)
# Set the distance mode
self.sensor.distance_mode = self.range
# Start measuring
self.sensor.start_ranging()
else:
self.sensor = adafruit_vl53l0x.VL53L0X(self.i2c, address=self.I2CAddr)
# Active the continuous mode
self.sensor = self.sensor.continuous_mode()

def acquireData(self, buf):
buf[0] = self.vl53.get_distance() # distance in mm
if self.type == 1:
if self.sensor.data_ready:
buf[0] = self.sensor.distance * 10 # Return the distance in mm
else:
buf[0] = self.sensor.range # distance in mm

def closeDevice(self):
# nothing to do here
self.vl53.stop_ranging() # stop measurements
if self.type == 1:
# Stop measurements
self.sensor.stop_ranging()
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ adafruit-circuitpython-ads1x15==2.2.21
adafruit-circuitpython-adxl34x==1.12.8
adafruit-circuitpython-mcp4725==1.4.11
adafruit-circuitpython-tcs34725==3.3.16
adafruit-circuitpython-vl53l0x==3.6.8
adafruit-circuitpython-vl53l1x==1.1.10
Adafruit-PlatformDetect==3.15.3
Adafruit-PureIO==1.1.9
pyftdi==0.53.2
Expand Down