一、编译源码
编译vl53l0x_test.c生成vl53l0x_test,然后将vl53l0x_test上传到硬件终端。
程序中已设定传感器工作在CONTINUOUS_TIMED_RANGING模式。
二、校准
一般在使用传感器之前需要经行串扰和偏移校准,这样才能获取准确的距离值。
1、串扰校准
如果传感器上方有玻璃或亚克力盖板,需要对传感器进行串扰校准。校准前需要将黑色目标放置在距离盖板600mm处,然后执行./vl53l0x_test -c进行校准,校准的参数会由驱动保存到文件中,永久生效。目标物离盖板的距离值可以调整,默认是600,可修改vl53l0x_test.c中的以下宏定义进行调整。
#define XTALK_TARGET 600
2、偏移校准
传感器上方有无盖板都需要进行偏移校准。校准前需要将白色目标放置在距离盖板或传感器表面100mm处,然后执行./vl53l0x_test -o进行校准,校准的参数会由驱动保存到文件中,永久生效。目标物离盖板或传感器表面的距离值可以调整,默认是100,可修改vl53l0x_test.c中的以下宏定义进行调整。
#define OFFSET_TARGET 100
三、调试
1、执行./vl53l0x_test测量距离
# ./vl53l0x_test
[ 3820.089948] Call of VL53L0X_DataInit
[ 3820.100097] VL53L0X_GetDeviceInfo:
[ 3820.111196] Device Name : VL53L0X ES1 or later
[ 3820.115786] Device Type : VL53L0X
[ 3820.119205] Device ID : VL5
[ 3820.122100] Product type: 238
[ 3820.125160] ProductRevisionMajor : 1
[ 3820.128847] ProductRevisionMinor : 1
[ 3820.132544] Call of VL53L0X_StaticInit
[ 3820.160884] Call of VL53L0X_PerformRefCalibration
[ 3820.186952] Call of VL53L0X_PerformRefSpadManagement
[ 3820.263061] Call of VL53L0X_SetDeviceMode
[ 3820.268559] DeviceMode:0x0, interMeasurems:30==
[ 3820.273648] Configure Long Ranging
[ 3820.277307] Set Timing Budget = 26000
^CRange:2139, Error:0, SigRate_mcps: 22528, AmbRate_mcps: 12800
2、测试low mode中断门限模式
例如设置当距离≤300mm时才产生中断,执行./vl53l0x_test -L 300
# ./vl53l0x_test -L 300
Configuring Low threshold = 300, High threhold = 0[ 4009.689413] Call of VL53L0X_DataInit
[ 4009.701821] VL53L0X_GetDeviceInfo:
[ 4009.712938] Device Name : VL53L0X ES1 or later
[ 4009.717527] Device Type : VL53L0X
[ 4009.720962] Device ID : VL5
[ 4009.723844] Product type: 238
[ 4009.726903] ProductRevisionMajor : 1
[ 4009.730599] ProductRevisionMinor : 1
[ 4009.734288] Call of VL53L0X_StaticInit
[ 4009.762612] Call of VL53L0X_PerformRefCalibration
[ 4009.788681] Call of VL53L0X_PerformRefSpadManagement
[ 4009.864785] Call of VL53L0X_SetDeviceMode
[ 4009.870689] DeviceMode:0x3, interMeasurems:30==
[ 4009.875758] Configure Long Ranging
[ 4009.879417] Set Timing Budget = 26000
^CRange: 265, Error:0, SigRate_mcps: 202240, AmbRate_mcps: 13824
只有当300mm内有物体时才会输出距离。
3、Timed模式低功耗调试
当设置为此模式时,VL53L0X会在一个Inter Measurement Period内启动一次测量,其余时间会处于软件休眠状态,但是VL53L0X存在一个问题,如果将低门限值设置在255以上,无法进入软件休眠,要将低门限值设置在255以下才能进入软件休眠模式。