Skip to content

Commit 8e13c5f

Browse files
adding ability to set optical center
1 parent 95fe750 commit 8e13c5f

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun VL53L1X 4m Laser Distance Sensor
2-
version=1.1.6
2+
version=1.2.0
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X

src/SparkFun_VL53L1X.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
This is a library written for the VL53L1X I2C Distance sensor.
3+
4+
Written by Andy England @ SparkFun Electronics, October 17th, 2017
5+
6+
The sensor uses I2C to communicate, as well as a single (optional)
7+
interrupt line that is not currently supported in this driver.
8+
9+
https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library
10+
11+
Do you like this library? Help support SparkFun. Buy a board!
12+
13+
Development environment specifics:
14+
Arduino IDE 1.8.1
15+
16+
This program is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
GNU General Public License for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
125
#include <stdlib.h>
226
#include "Arduino.h"
327
#include "SparkFun_VL53L1X.h"
@@ -273,9 +297,9 @@ uint16_t SFEVL53L1X::getDistanceThresholdHigh()
273297
return temp;
274298
}
275299

276-
void SFEVL53L1X::setROI(uint16_t x, uint16_t y)
300+
void SFEVL53L1X::setROI(uint8_t x, uint8_t y, uint8_t opticalCenter)
277301
{
278-
_device->VL53L1X_SetROI(x, x);
302+
_device->VL53L1X_SetROI(x, y, opticalCenter);
279303
}
280304

281305
uint16_t SFEVL53L1X::getROIX()

src/SparkFun_VL53L1X.h

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
This is a library written for the VL53L1X I2C Distance sensor.
3+
4+
Written by Andy England @ SparkFun Electronics, October 17th, 2017
5+
6+
The sensor uses I2C to communicate, as well as a single (optional)
7+
interrupt line that is not currently supported in this driver.
8+
9+
https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library
10+
11+
Do you like this library? Help support SparkFun. Buy a board!
12+
13+
Development environment specifics:
14+
Arduino IDE 1.8.1
15+
16+
This program is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
GNU General Public License for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
125
#pragma once
226

327
#include "Arduino.h"
@@ -53,7 +77,28 @@ class SFEVL53L1X
5377
uint16_t getDistanceThresholdWindow(); //Returns distance threshold window option
5478
uint16_t getDistanceThresholdLow(); //Returns lower bound in mm.
5579
uint16_t getDistanceThresholdHigh(); //Returns upper bound in mm
56-
void setROI(uint16_t x, uint16_t y); //Set the height and width of the ROI in SPADs, lowest possible option is 4. ROI is always centered.
80+
/**Table of Optical Centers**
81+
*
82+
* 128,136,144,152,160,168,176,184, 192,200,208,216,224,232,240,248
83+
* 129,137,145,153,161,169,177,185, 193,201,209,217,225,233,241,249
84+
* 130,138,146,154,162,170,178,186, 194,202,210,218,226,234,242,250
85+
* 131,139,147,155,163,171,179,187, 195,203,211,219,227,235,243,251
86+
* 132,140,148,156,164,172,180,188, 196,204,212,220,228,236,244,252
87+
* 133,141,149,157,165,173,181,189, 197,205,213,221,229,237,245,253
88+
* 134,142,150,158,166,174,182,190, 198,206,214,222,230,238,246,254
89+
* 135,143,151,159,167,175,183,191, 199,207,215,223,231,239,247,255
90+
91+
* 127,119,111,103, 95, 87, 79, 71, 63, 55, 47, 39, 31, 23, 15, 7
92+
* 126,118,110,102, 94, 86, 78, 70, 62, 54, 46, 38, 30, 22, 14, 6
93+
* 125,117,109,101, 93, 85, 77, 69, 61, 53, 45, 37, 29, 21, 13, 5
94+
* 124,116,108,100, 92, 84, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4
95+
* 123,115,107, 99, 91, 83, 75, 67, 59, 51, 43, 35, 27, 19, 11, 3
96+
* 122,114,106, 98, 90, 82, 74, 66, 58, 50, 42, 34, 26, 18, 10, 2
97+
* 121,113,105, 97, 89, 81, 73, 65, 57, 49, 41, 33, 25, 17, 9, 1
98+
* 120,112,104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 Pin 1
99+
*
100+
* To set the center, set the pad that is to the right and above the exact center of the region you'd like to measure as your opticalCenter*/
101+
void setROI(uint8_t x, uint8_t y, uint8_t opticalCenter); //Set the height and width of the ROI(region of interest) in SPADs, lowest possible option is 4. Set optical center based on above table
57102
uint16_t getROIX(); //Returns the width of the ROI in SPADs
58103
uint16_t getROIY(); //Returns the height of the ROI in SPADs
59104
void setSignalThreshold(uint16_t signalThreshold); //Programs the necessary threshold to trigger a measurement. Default is 1024 kcps.

src/vl53l1x_class.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -738,20 +738,19 @@ VL53L1X_ERROR VL53L1X::VL53L1X_GetDistanceThresholdHigh(uint16_t *high)
738738
return status;
739739
}
740740

741-
VL53L1X_ERROR VL53L1X::VL53L1X_SetROI(uint16_t X, uint16_t Y)
741+
VL53L1X_ERROR VL53L1X::VL53L1X_SetROI(uint8_t X, uint8_t Y, uint8_t opticalCenter)
742742
{
743-
uint8_t OpticalCenter;
744743
VL53L1X_ERROR status = 0;
745744

746-
status =VL53L1_RdByte(Device, VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD, &OpticalCenter);
745+
status =VL53L1_RdByte(Device, VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD, &opticalCenter);
747746
if (X > 16)
748747
X = 16;
749748
if (Y > 16)
750749
Y = 16;
751750
if (X > 10 || Y > 10){
752-
OpticalCenter = 199;
751+
opticalCenter = 199;
753752
}
754-
status = VL53L1_WrByte(Device, ROI_CONFIG__USER_ROI_CENTRE_SPAD, OpticalCenter);
753+
status = VL53L1_WrByte(Device, ROI_CONFIG__USER_ROI_CENTRE_SPAD, opticalCenter);
755754
status = VL53L1_WrByte(Device, ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE,
756755
(Y - 1) << 4 | (X - 1));
757756
return status;

src/vl53l1x_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class VL53L1X : public RangeSensor
457457
* The smallest acceptable ROI size = 4\n
458458
* @param X:ROI Width; Y=ROI Height
459459
*/
460-
VL53L1X_ERROR VL53L1X_SetROI(uint16_t X, uint16_t Y);
460+
VL53L1X_ERROR VL53L1X_SetROI(uint8_t X, uint8_t Y, uint8_t opticalCenter);
461461

462462
/**
463463
*@brief This function returns width X and height Y

0 commit comments

Comments
 (0)