Skip to content

Commit 8cefa5b

Browse files
fixing issues withtypes, updating examples to use begin
1 parent e35acdf commit 8cefa5b

File tree

9 files changed

+137
-116
lines changed

9 files changed

+137
-116
lines changed

examples/Example1_ReadDistance/Example1_ReadDistance.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#define SHUTDOWN_PIN 2
2121
#define INTERRUPT_PIN 3
2222

23-
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
23+
SFEVL53L1X distanceSensor;
24+
//Uncomment the following line to use the optional shutdown and interrupt pins.
25+
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2426

2527
void setup(void)
2628
{

examples/Example2_SetDistanceMode/Example2_SetDistanceMode.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Reading distance from the laser based VL53L1X
33
By: Nathan Seidle
4+
Revised by: Andy England
45
SparkFun Electronics
56
Date: April 4th, 2018
67
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
@@ -20,7 +21,9 @@
2021
#define SHUTDOWN_PIN 2
2122
#define INTERRUPT_PIN 3
2223

23-
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
24+
SFEVL53L1X distanceSensor;
25+
//Uncomment the following line to use the optional shutdown and interrupt pins.
26+
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2427

2528
void setup(void)
2629
{
@@ -44,6 +47,8 @@ void loop(void)
4447

4548
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
4649

50+
distanceSensor.stopRanging();
51+
4752
Serial.print("Distance(mm): ");
4853
Serial.print(distance);
4954

examples/Example3_StatusAndRate/Example3_StatusAndRate.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#define SHUTDOWN_PIN 2
2121
#define INTERRUPT_PIN 3
2222

23-
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
23+
SFEVL53L1X distanceSensor;
24+
//Uncomment the following line to use the optional shutdown and interrupt pins.
25+
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2426

2527
//Store distance readings to get rolling average
2628
#define HISTORY_SIZE 10
@@ -46,6 +48,7 @@ void loop(void)
4648
long startTime = millis();
4749
distanceSensor.startRanging(); //Write configuration block of 135 bytes to setup a measurement
4850
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
51+
distanceSensor.stopRanging();
4952
long endTime = millis();
5053

5154
Serial.print("Distance(mm): ");

examples/Example4_SetIntermeasurementPeriod/Example4_SetIntermeasurementPeriod.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#define SHUTDOWN_PIN 2
2121
#define INTERRUPT_PIN 3
2222

23-
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
23+
SFEVL53L1X distanceSensor;
24+
//Uncomment the following line to use the optional shutdown and interrupt pins.
25+
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2426

2527
void setup(void)
2628
{
@@ -39,8 +41,8 @@ void setup(void)
3941
void loop(void)
4042
{
4143
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
42-
4344
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
45+
distanceSensor.stopRanging();
4446

4547
Serial.print("Distance(mm): ");
4648
Serial.print(distance);

examples/Example5_LCDDemo/Example5_LCDDemo.ino

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
*/
1717
#include <Wire.h>
1818
#include "SparkFun_VL53L1X.h"
19+
#include <SoftwareSerial.h>
1920

2021
//Optional interrupt and shutdown pins.
2122
#define SHUTDOWN_PIN 2
2223
#define INTERRUPT_PIN 3
2324

24-
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
25-
26-
#include <SoftwareSerial.h>
25+
SFEVL53L1X distanceSensor;
26+
//Uncomment the following line to use the optional shutdown and interrupt pins.
27+
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2728

2829
SoftwareSerial lcd(10, A3); // RX, TX
2930

@@ -82,13 +83,9 @@ void loop(void)
8283

8384
//Write configuration block of 135 bytes to setup a measurement
8485
distanceSensor.startRanging();
85-
86-
//Poll for completion of measurement. Takes 40-50ms.
87-
while (distanceSensor.checkForDataReady() == false)
88-
delay(5);
89-
9086
int distanceMM = distanceSensor.getDistance();
91-
87+
distanceSensor.stopRanging();
88+
9289
lastReading = millis();
9390

9491
history[historySpot] = distanceMM;

keywords.txt

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,69 @@
11
#######################################
2-
# Syntax Coloring Map
2+
# Syntax Coloring Map For ST_FlightSense_Sensor_Shields
33
#######################################
44

55
#######################################
66
# Datatypes (KEYWORD1)
77
#######################################
88

9-
VL53L1X KEYWORD1
9+
SFEVL53L1X KEYWORD1
1010

1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
1414

15-
init KEYWORD2
16-
begin KEYWORD2
17-
startRanging KEYWORD2
18-
checkForDataReady KEYWORD2
19-
setTimingBudgetInMs KEYWORD2
20-
getTimingBudgetInMs KEYWORD2
21-
setDistanceModeLong KEYWORD2
22-
setDistanceModeShort KEYWORD2
23-
getDistanceMode KEYWORD2
24-
setIntermeasurementPeriod KEYWORD2
25-
getIntermeasurementPeriod KEYWORD2
26-
checkBootState KEYWORD2
27-
getSensorID KEYWORD2
28-
getDistance KEYWORD2
29-
getSignalPerSpad KEYWORD2
30-
getAmbientPerSpad KEYWORD2
31-
getSignalRate KEYWORD2
32-
getSpadNb KEYWORD2
33-
getAmbientRate KEYWORD2
34-
getRangeStatus KEYWORD2
35-
setOffset KEYWORD2
36-
getOffset KEYWORD2
37-
setXTalk KEYWORD2
38-
getXTalk KEYWORD2
39-
setDistanceThreshold KEYWORD2
40-
getDistanceThresholdWindow KEYWORD2
41-
getDistanceThresholdLow KEYWORD2
42-
getDistanceThresholdHigh KEYWORD2
43-
setROI KEYWORD2
44-
getROIX KEYWORD2
45-
getROIY KEYWORD2
46-
setSignalThreshold KEYWORD2
47-
getSignalThreshold KEYWORD2
48-
setSigmaThreshold KEYWORD2
49-
getSigmaThreshold KEYWORD2
50-
startTemperatureUpdate KEYWORD2
51-
calibrateOffset KEYWORD2
52-
calibrateXTalk KEYWORD2
53-
54-
readRegister KEYWORD2
55-
readRegister16 KEYWORD2
56-
writeRegister KEYWORD2
57-
writeRegister16 KEYWORD2
15+
init KEYWORD2
16+
begin KEYWORD2
17+
checkID KEYWORD2
18+
sensorOn KEYWORD2
19+
sensorOff KEYWORD2
20+
getSoftwareVersion KEYWORD2
21+
setI2CAddress KEYWORD2
22+
getI2CAddress KEYWORD2
23+
clearInterrupt KEYWORD2
24+
setInterruptPolarityHigh KEYWORD2
25+
setInterruptPolarityLow KEYWORD2
26+
getInterruptPolarity KEYWORD2
27+
startRanging KEYWORD2
28+
stopRanging KEYWORD2
29+
checkForDataReady KEYWORD2
30+
setTimingBudgetInMs KEYWORD2
31+
getTimingBudgetInMs KEYWORD2
32+
setDistanceModeLong KEYWORD2
33+
setDistanceModeShort KEYWORD2
34+
getDistanceMode KEYWORD2
35+
setIntermeasurementPeriod KEYWORD2
36+
getIntermeasurementPeriod KEYWORD2
37+
checkBootState KEYWORD2
38+
getSensorID KEYWORD2
39+
getDistance KEYWORD2
40+
getSignalPerSpad KEYWORD2
41+
getAmbientPerSpad KEYWORD2
42+
getSignalRate KEYWORD2
43+
getSpadNb KEYWORD2
44+
getAmbientRate KEYWORD2
45+
getRangeStatus KEYWORD2
46+
setOffset KEYWORD2
47+
getOffset KEYWORD2
48+
setXTalk KEYWORD2
49+
getXTalk KEYWORD2
50+
setDistanceThreshold KEYWORD2
51+
getDistanceThresholdWindow KEYWORD2
52+
getDistanceThresholdLow KEYWORD2
53+
getDistanceThresholdHig KEYWORD2
54+
setROI KEYWORD2
55+
getROIX KEYWORD2
56+
getROIY KEYWORD2
57+
setSignalThreshold KEYWORD2
58+
getSignalThreshold KEYWORD2
59+
setSigmaThreshold KEYWORD2
60+
getSigmaThreshold KEYWORD2
61+
startTemperatureUpdate KEYWORD2
62+
calibrateOffset KEYWORD2
63+
calibrateXTalk KEYWORD2
5864

5965
#######################################
6066
# Constants (LITERAL1)
6167
#######################################
68+
69+

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=SparkFun VL53L1X 4m Laser Distance Sensor
2-
version=1.1.1
2+
version=1.1.2
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X
66
paragraph=The VL53L1X is the latest Time Of Flight (ToF) sensor to be released. It uses a VCSEL (vertical cavity surface emitting laser) to emit a class 1 IR laser and time the reflection to the target. What does all this mean? You can measure the distance to an object up to 4 meters away with millimeter resolution! That’s pretty incredible. We’ve found the precision of the sensor to be 1mm but the accuracy is around +/-5mm. Available at: https://www.sparkfun.com/products/14667
77
category=Sensors
88
url=https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library
9-
architectures=*
9+
architectures=*

src/SparkFun_VL53L1X.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void SFEVL53L1X::setOffset(int16_t offset)
230230

231231
int16_t SFEVL53L1X::getOffset()
232232
{
233-
int16_t temp;
233+
uint16_t temp;
234234
_device->VL53L1X_GetOffset(&temp);
235235
return temp;
236236
}
@@ -275,7 +275,7 @@ uint16_t SFEVL53L1X::getDistanceThresholdHigh()
275275

276276
void SFEVL53L1X::setROI(uint16_t x, uint16_t y)
277277
{
278-
_device->VL53L1X_SetROI(x, y);
278+
_device->VL53L1X_SetROI(x, x);
279279
}
280280

281281
uint16_t SFEVL53L1X::getROIX()
@@ -331,5 +331,6 @@ void SFEVL53L1X::calibrateOffset(uint16_t targetDistanceInMm)
331331

332332
void SFEVL53L1X::calibrateXTalk(uint16_t targetDistanceInMm)
333333
{
334-
_device->VL53L1X_CalibrateXtalk(targetDistanceInMm, getXTalk());
335-
};
334+
int16_t xTalk = getXTalk();
335+
_device->VL53L1X_CalibrateXtalk(targetDistanceInMm, xTalk);
336+
};

src/SparkFun_VL53L1X.h

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,60 @@
99
class SFEVL53L1X
1010
{
1111
public:
12-
SFEVL53L1X(TwoWire &i2cPort = Wire, int shutdownPin = -1, int interruptPin = -1);
13-
bool init();
14-
bool checkID();
15-
void sensorOn();
16-
void sensorOff(); //virtual void VL53L1_Off(void)
17-
VL53L1X_Version_t getSoftwareVersion();//VL53L1X_ERROR VL53L1X_GetSWVersion(VL53L1X_Version_t *pVersion);
18-
void setI2CAddress(uint8_t addr);//VL53L1X_ERROR VL53L1X_SetI2CAddress(uint8_t new_address);
19-
int getI2CAddress();
20-
void clearInterrupt();//VL53L1X_ERROR VL53L1X_ClearInterrupt();
21-
void setInterruptPolarityHigh();//VL53L1X_ERROR VL53L1X_SetInterruptPolarity(uint8_t IntPol);
22-
void setInterruptPolarityLow();
23-
uint8_t getInterruptPolarity();//VL53L1X_ERROR VL53L1X_GetInterruptPolarity(uint8_t *pIntPol);
24-
void startRanging();//Begins taking measurements
25-
void stopRanging();//Stops taking measurements
26-
bool checkForDataReady();//VL53L1X_ERROR VL53L1X_CheckForDataReady(uint8_t *isDataReady);
27-
void setTimingBudgetInMs(uint16_t timingBudget);//VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs(uint16_t TimingBudgetInMs);
28-
uint16_t getTimingBudgetInMs();//VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs(uint16_t *pTimingBudgetInMs);
29-
void setDistanceModeLong();//VL53L1X_ERROR VL53L1X_SetDistanceMode(uint16_t DistanceMode);
30-
void setDistanceModeShort();//VL53L1X_ERROR VL53L1X_GetDistanceMode(uint16_t *pDistanceMode);
31-
uint8_t getDistanceMode();
32-
void setIntermeasurementPeriod(uint16_t intermeasurement);//VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs(uint16_t InterMeasurementInMs);
33-
uint16_t getIntermeasurementPeriod();//VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs(uint16_t * pIM);
34-
bool checkBootState();//VL53L1X_ERROR VL53L1X_BootState(uint8_t *state);
35-
uint16_t getSensorID();//VL53L1X_ERROR VL53L1X_GetSensorId(uint16_t *id);
36-
uint16_t getDistance();//Returns distance
37-
uint16_t getSignalPerSpad();//VL53L1X_ERROR VL53L1X_GetSignalPerSpad(uint16_t *signalPerSp);
38-
uint16_t getAmbientPerSpad();//VL53L1X_ERROR VL53L1X_GetAmbientPerSpad(uint16_t *amb);
39-
uint16_t getSignalRate();//VL53L1X_ERROR VL53L1X_GetSignalRate(uint16_t *signalRate);
40-
uint16_t getSpadNb();//VL53L1X_ERROR VL53L1X_GetSpadNb(uint16_t *spNb);
41-
uint16_t getAmbientRate();//VL53L1X_ERROR VL53L1X_GetAmbientRate(uint16_t *ambRate);
42-
uint8_t getRangeStatus();//VL53L1X_ERROR VL53L1X_GetRangeStatus(uint8_t *rangeStatus);
43-
void setOffset(int16_t offset);//VL53L1X_ERROR VL53L1X_SetOffset(int16_t OffsetValue);
44-
int16_t getOffset();//VL53L1X_ERROR VL53L1X_GetOffset(int16_t *Offset);
45-
void setXTalk(uint16_t xTalk);//VL53L1X_ERROR VL53L1X_SetXtalk(uint16_t XtalkValue);
46-
uint16_t getXTalk();//VL53L1X_ERROR VL53L1X_GetXtalk(uint16_t *Xtalk);
47-
void setDistanceThreshold(uint16_t lowThresh, uint16_t hiThresh, uint8_t window);//VL53L1X_ERROR VL53L1X_SetDistanceThreshold(uint16_t ThreshLow,
48-
// uint16_t ThreshHigh, uint8_t Window,
49-
// uint8_t IntOnNoTarget);
50-
uint16_t getDistanceThresholdWindow();//VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow(uint16_t *window);
51-
uint16_t getDistanceThresholdLow();//VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow(uint16_t *low);
52-
uint16_t getDistanceThresholdHigh();//VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh(uint16_t *high);
53-
void setROI(uint16_t x, uint16_t y);//VL53L1X_ERROR VL53L1X_SetROI(uint16_t X, uint16_t Y);
54-
uint16_t getROIX();//VL53L1X_ERROR VL53L1X_GetROI_XY(uint16_t *ROI_X, uint16_t *ROI_Y);
55-
uint16_t getROIY();
56-
void setSignalThreshold(uint16_t signalThreshold);//VL53L1X_ERROR VL53L1X_SetSignalThreshold(uint16_t signal);
57-
uint16_t getSignalThreshold();//VL53L1X_ERROR VL53L1X_GetSignalThreshold(uint16_t *signal);
58-
void setSigmaThreshold(uint16_t sigmaThreshold);//VL53L1X_ERROR VL53L1X_SetSigmaThreshold(uint16_t sigma);
59-
uint16_t getSigmaThreshold();//VL53L1X_ERROR VL53L1X_GetSigmaThreshold(uint16_t *signal);
60-
void startTemperatureUpdate();//VL53L1X_ERROR VL53L1X_StartTemperatureUpdate();
61-
void calibrateOffset(uint16_t targetDistanceInMm);//int8_t VL53L1X_CalibrateOffset(uint16_t TargetDistInMm, int16_t *offset);
62-
void calibrateXTalk(uint16_t targetDistanceInMm);//int8_t VL53L1X_CalibrateXtalk(uint16_t TargetDistInMm, uint16_t *xtalk);
12+
SFEVL53L1X(TwoWire &i2cPort = Wire, int shutdownPin = -1, int interruptPin = -1); //Constructs our Distance sensor without an interrupt or shutdown pin
13+
bool init(); //Deprecated version of begin
14+
bool begin(); //Initialization of sensor
15+
bool checkID(); //Check the ID of the sensor, returns true if ID is correct
16+
void sensorOn(); //Toggles shutdown pin to turn sensor on and off
17+
void sensorOff(); //Toggles shutdown pin to turn sensor on and off
18+
VL53L1X_Version_t getSoftwareVersion(); //Get's the current ST software version
19+
void setI2CAddress(uint8_t addr); //Set the I2C address
20+
int getI2CAddress(); //Get the I2C address
21+
void clearInterrupt(); // Clear the interrupt flag
22+
void setInterruptPolarityHigh(); //Set the polarity of an active interrupt to High
23+
void setInterruptPolarityLow(); //Set the polarity of an active interrupt to Low
24+
uint8_t getInterruptPolarity(); //get the current interrupt polarity
25+
void startRanging(); //Begins taking measurements
26+
void stopRanging(); //Stops taking measurements
27+
bool checkForDataReady(); //Checks the to see if data is ready
28+
void setTimingBudgetInMs(uint16_t timingBudget); //Set the timing budget for a measurement
29+
uint16_t getTimingBudgetInMs(); //Get the timing budget for a measurement
30+
void setDistanceModeLong(); //Set to 4M range
31+
void setDistanceModeShort(); //Set to 1.3M range
32+
uint8_t getDistanceMode(); //Get the distance mode, returns 1 for short and 2 for long
33+
void setIntermeasurementPeriod(uint16_t intermeasurement); //Set time between measurements in ms
34+
uint16_t getIntermeasurementPeriod(); //Get time between measurements in ms
35+
bool checkBootState(); //Check if the VL53L1X has been initialized
36+
uint16_t getSensorID(); //Get the sensor ID
37+
uint16_t getDistance(); //Returns distance
38+
uint16_t getSignalPerSpad(); //Returns the average signal rate per SPAD (The sensitive pads that detect light, the VL53L1X has a 16x16 array of these) in kcps/SPAD, or kilo counts per second per SPAD.
39+
uint16_t getAmbientPerSpad(); //Returns the ambient noise when not measuring a signal in kcps/SPAD.
40+
uint16_t getSignalRate(); //Returns the signal rate in kcps. All SPADs combined.
41+
uint16_t getSpadNb(); //Returns the current number of enabled SPADs
42+
uint16_t getAmbientRate(); // Returns the total ambinet rate in kcps. All SPADs combined.
43+
uint8_t getRangeStatus(); //Returns the range status, which can be any of the following. 0 = no error, 1 = signal fail, 2 = sigma fail, 7 = wrapped target fail
44+
void setOffset(int16_t offset); //Manually set an offset in mm
45+
int16_t getOffset(); //Get the current offset in mm
46+
void setXTalk(uint16_t xTalk); //Manually set the value of crosstalk in counts per second (cps), which is interference from any sort of window in front of your sensor.
47+
uint16_t getXTalk(); //Returns the current crosstalk value in cps.
48+
void setDistanceThreshold(uint16_t lowThresh, uint16_t hiThresh, uint8_t window);//Set bounds for the interrupt. lowThresh and hiThresh are the bounds of your interrupt while window decides when the interrupt should fire. The options for window are shown below.
49+
//0: Interrupt triggered on measured distance below lowThresh.
50+
//1: Interrupt triggered on measured distance above hiThresh.
51+
//2: Interrupt triggered on measured distance outside of bounds.
52+
//3: Interrupt triggered on measured distance inside of bounds.
53+
uint16_t getDistanceThresholdWindow(); //Returns distance threshold window option
54+
uint16_t getDistanceThresholdLow(); //Returns lower bound in mm.
55+
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.
57+
uint16_t getROIX(); //Returns the width of the ROI in SPADs
58+
uint16_t getROIY(); //Returns the height of the ROI in SPADs
59+
void setSignalThreshold(uint16_t signalThreshold); //Programs the necessary threshold to trigger a measurement. Default is 1024 kcps.
60+
uint16_t getSignalThreshold(); //Returns the signal threshold in kcps
61+
void setSigmaThreshold(uint16_t sigmaThreshold); //Programs a new sigma threshold in mm. (default=15 mm)
62+
uint16_t getSigmaThreshold(); //Returns the current sigma threshold.
63+
void startTemperatureUpdate(); //Recalibrates the sensor for temperature changes. Run this any time the temperature has changed by more than 8°C
64+
void calibrateOffset(uint16_t targetDistanceInMm); //Autocalibrate the offset by placing a target a known distance away from the sensor and passing this known distance into the function.
65+
void calibrateXTalk(uint16_t targetDistanceInMm); //Autocalibrate the crosstalk by placing a target a known distance away from the sensor and passing this known distance into the function.
6366
private:
6467
TwoWire *_i2cPort;
6568
int _shutdownPin;

0 commit comments

Comments
 (0)