From 065e29261bd5aaabd5306d4adfb7712cd054c1e2 Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Sun, 24 May 2020 09:24:50 -0500 Subject: [PATCH 01/19] Reduce hard delay. Improve startup time for units that are already measuring. --- library.properties | 2 +- src/vl53l1x_class.cpp | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/library.properties b/library.properties index 0bac1db..8d1786d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun VL53L1X 4m Laser Distance Sensor -version=1.2.8 +version=1.2.9 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X diff --git a/src/vl53l1x_class.cpp b/src/vl53l1x_class.cpp index 1bcb8cb..4b05cef 100644 --- a/src/vl53l1x_class.cpp +++ b/src/vl53l1x_class.cpp @@ -166,7 +166,7 @@ VL53L1X_ERROR VL53L1X::VL53L1X_SetI2CAddress(uint8_t new_address) VL53L1X_ERROR VL53L1X::VL53L1X_SensorInit() { VL53L1X_ERROR status = 0; - uint8_t Addr = 0x00, tmp = 0, timeout = 0; + uint8_t Addr = 0x00, dataReady = 0, timeout = 0; for (Addr = 0x2D; Addr <= 0x87; Addr++) { @@ -174,20 +174,15 @@ VL53L1X_ERROR VL53L1X::VL53L1X_SensorInit() } status = VL53L1X_StartRanging(); - delay(103); //Wait the default intermeasurement period of 103ms before checking for dataready - - while (tmp == 0) + //We need to wait at least the default intermeasurement period of 103ms before dataready will occur + //But if a unit has already been powered and polling, it may happen much faster + while (dataReady == 0) { - status = VL53L1X_CheckForDataReady(&tmp); - timeout++; - if (timeout > 50) - { - status = VL53L1_ERROR_TIME_OUT; - return status; - } + status = VL53L1X_CheckForDataReady(&dataReady); + if (timeout++ > 150) + return VL53L1_ERROR_TIME_OUT; delay(1); } - tmp = 0; status = VL53L1X_ClearInterrupt(); status = VL53L1X_StopRanging(); status = VL53L1_WrByte(Device, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */ From 28ae87e2cdc1c06027fbf56c7dc66838bc01c8ca Mon Sep 17 00:00:00 2001 From: Joseph Duchesne Date: Sun, 11 Oct 2020 12:12:35 -0400 Subject: [PATCH 02/19] Added One-Shot Ranging trigger --- src/SparkFun_VL53L1X.cpp | 4 ++++ src/SparkFun_VL53L1X.h | 1 + src/vl53l1x_class.cpp | 10 +++++++++- src/vl53l1x_class.h | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 39c7fa2..8b24de0 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -133,6 +133,10 @@ void SFEVL53L1X::startRanging() _device->VL53L1X_StartRanging(); } +void SFEVL53L1X::startOneshotRanging() { + _device->VL53L1X_StartOneshotRanging(); +} + void SFEVL53L1X::stopRanging() { _device->VL53L1X_StopRanging(); diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index 712233d..423fdf9 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -47,6 +47,7 @@ class SFEVL53L1X void setInterruptPolarityLow(); //Set the polarity of an active interrupt to Low uint8_t getInterruptPolarity(); //get the current interrupt polarity void startRanging(); //Begins taking measurements + void startOneshotRanging(); // Start one-shot ranging void stopRanging(); //Stops taking measurements bool checkForDataReady(); //Checks the to see if data is ready void setTimingBudgetInMs(uint16_t timingBudget); //Set the timing budget for a measurement diff --git a/src/vl53l1x_class.cpp b/src/vl53l1x_class.cpp index 4b05cef..338d7b5 100644 --- a/src/vl53l1x_class.cpp +++ b/src/vl53l1x_class.cpp @@ -223,11 +223,19 @@ VL53L1X_ERROR VL53L1X::VL53L1X_GetInterruptPolarity(uint8_t *pInterruptPolarity) VL53L1X_ERROR VL53L1X::VL53L1X_StartRanging() { VL53L1X_ERROR status = 0; - + // Consider: maybe also VL53L1_WrByte(Device, SYSTEM__INTERRUPT_CLEAR, 0x01); /* clear interrupt trigger */ status = VL53L1_WrByte(Device, SYSTEM__MODE_START, 0x40); /* Enable VL53L1X */ return status; } +VL53L1X_ERROR VL53L1X::VL53L1X_StartOneshotRanging() +{ + VL53L1X_ERROR status = 0; + VL53L1_WrByte(Device, SYSTEM__INTERRUPT_CLEAR, 0x01); /* clear interrupt trigger */ + status = VL53L1_WrByte(Device, SYSTEM__MODE_START, 0x10); /* Enable VL53L1X one-shot ranging */ + return status; +} + VL53L1X_ERROR VL53L1X::VL53L1X_StopRanging() { VL53L1X_ERROR status = 0; diff --git a/src/vl53l1x_class.h b/src/vl53l1x_class.h index 606aabf..458014b 100644 --- a/src/vl53l1x_class.h +++ b/src/vl53l1x_class.h @@ -304,6 +304,11 @@ class VL53L1X : public RangeSensor */ VL53L1X_ERROR VL53L1X_StartRanging(); + /** + * @brief This function starts a one-shot ranging distance operation\n + */ + VL53L1X_ERROR VL53L1X_StartOneshotRanging(); + /** * @brief This function stops the ranging. */ From 159c19e4855efd7ec4c88dfbe8a89264d83f9921 Mon Sep 17 00:00:00 2001 From: Elias Santistevan Date: Thu, 20 Jan 2022 09:45:12 -0700 Subject: [PATCH 03/19] Adds sensorID for an alternate part. --- src/SparkFun_VL53L1X.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 39c7fa2..85b6344 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -54,7 +54,7 @@ bool SFEVL53L1X::checkID() { uint16_t sensorId; _device->VL53L1X_GetSensorId(&sensorId); - if (sensorId == 0xEACC) + if (sensorId == 0xEACC | sensorId == 0xEBAA) return true; return false; } @@ -359,4 +359,4 @@ void SFEVL53L1X::calibrateXTalk(uint16_t targetDistanceInMm) { uint16_t xTalk = getXTalk(); _device->VL53L1X_CalibrateXtalk(targetDistanceInMm, &xTalk); -}; \ No newline at end of file +}; From 2ae2e9db73bcc9d897f3be656e8402d4b9668fcb Mon Sep 17 00:00:00 2001 From: Elias Santistevan Date: Thu, 20 Jan 2022 09:47:23 -0700 Subject: [PATCH 04/19] Rolls version --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 8d1786d..4042f76 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun VL53L1X 4m Laser Distance Sensor -version=1.2.9 +version=1.2.10 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X From 71314d15e76ccca91842c57b7c9c0f5f0e36c0e6 Mon Sep 17 00:00:00 2001 From: Elias Santistevan Date: Thu, 20 Jan 2022 10:03:14 -0700 Subject: [PATCH 05/19] Fixes bitwise OR to logical OR operator in sensorID check * rolls version --- library.properties | 2 +- src/SparkFun_VL53L1X.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 4042f76..c3e0e97 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun VL53L1X 4m Laser Distance Sensor -version=1.2.10 +version=1.2.11 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 85b6344..52b1093 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -54,7 +54,7 @@ bool SFEVL53L1X::checkID() { uint16_t sensorId; _device->VL53L1X_GetSensorId(&sensorId); - if (sensorId == 0xEACC | sensorId == 0xEBAA) + if ( (sensorId == 0xEACC) || (sensorId == 0xEBAA) ) return true; return false; } From ce448e7b535b705098928c9ebd683f3f9b03f08c Mon Sep 17 00:00:00 2001 From: Ricardo Ramos <45825126+PPVJM@users.noreply.github.com> Date: Fri, 21 Jan 2022 18:07:27 -0300 Subject: [PATCH 06/19] Added get and set detection threshold functionality. --- .../Example8_SetGetDetectionThresholds.ino | 126 ++++++++++++++++++ src/SparkFun_VL53L1X.cpp | 42 +++++- src/SparkFun_VL53L1X.h | 19 +++ 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 examples/Example8_SetGetDetectionThresholds/Example8_SetGetDetectionThresholds.ino diff --git a/examples/Example8_SetGetDetectionThresholds/Example8_SetGetDetectionThresholds.ino b/examples/Example8_SetGetDetectionThresholds/Example8_SetGetDetectionThresholds.ino new file mode 100644 index 0000000..16bfbfb --- /dev/null +++ b/examples/Example8_SetGetDetectionThresholds/Example8_SetGetDetectionThresholds.ino @@ -0,0 +1,126 @@ +/* + Reading distance from the laser based VL53L1X + By: Nathan Seidle + Revised by: Andy England and Ricardo Ramos + SparkFun Electronics + Date: January 21st, 2022 + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). + + SparkFun labored with love to create this code. Feel like supporting open source hardware? + Buy a board from SparkFun! https://www.sparkfun.com/products/14667 + + This example sets high and low thresholds for detection. + + Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor. +*/ + +#include +#include "SparkFun_VL53L1X.h" //Click here to get the library: http://librarymanager/All#SparkFun_VL53L1X + +//Optional interrupt and shutdown pins. +#define SHUTDOWN_PIN 2 +#define INTERRUPT_PIN 3 + +SFEVL53L1X distanceSensor; +//Uncomment the following line to use the optional shutdown and interrupt pins. +//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN); + +void setup(void) +{ + Wire.begin(); + + Serial.begin(115200); + Serial.println("VL53L1X Qwiic Test"); + + if (distanceSensor.begin() != 0) //Begin returns 0 on a good init + { + Serial.println("Sensor failed to begin. Please check wiring. Freezing..."); + while (1) + ; + } + Serial.println("Sensor online!"); + + DetectionConfig dc; // struct instance which holds the detection configuration + dc.IntOnNoTarget = 1; // No longer used - just use 1 per ST + dc.distanceMode = DISTANCE_SHORT; // short distance mode + dc.thresholdHigh = 300; // high threshold of 300 mm + dc.thresholdLow = 70; // low threshold of 70 mm + dc.windowMode = WINDOW_IN; // will measure and trigger interrrupt when measurement fall between 70 and 300 mm + + if(distanceSensor.setThresholdConfig(&dc) == true) + { + Serial.println("Thresholds programmed. Reading configuration back..."); + dc = {}; + if(distanceSensor.getThresholdConfig(&dc) == true) + { + Serial.print("IntOnNoTarget: "); + Serial.println(dc.IntOnNoTarget); + Serial.print("Distance Mode: "); + + if(dc.distanceMode == DISTANCE_SHORT) + Serial.println("DISTANCE_SHORT (0)"); + else + Serial.println("DISTANCE_LONG (1)"); + + Serial.print("Threshold High: "); + Serial.println(dc.thresholdHigh); + Serial.print("Threshold Low: "); + Serial.println(dc.thresholdLow); + Serial.print("Window mode: "); + switch (dc.windowMode) + { + case WINDOW_BELOW: + Serial.println("WINDOW_BELOW (0)"); + break; + + case WINDOW_ABOVE: + Serial.println("WINDOW_ABOVE (1)"); + break; + + case WINDOW_OUT: + Serial.println("WINDOW_OUT (2)"); + break; + + case WINDOW_IN: + Serial.println("WINDOW_IN (3)"); + break; + + default: + break; + } + } + } + else + { + Serial.println("Could not set threshold configuration."); + } + Serial.println("Starting measurements in 2 seconds."); + delay(2000); + Serial.println("Measurements started!"); + +} + +void loop(void) +{ + distanceSensor.startRanging(); //Write configuration bytes to initiate measurement + + while (!distanceSensor.checkForDataReady()) + { + delay(1); + } + int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor + distanceSensor.clearInterrupt(); + + distanceSensor.stopRanging(); + + Serial.print("Distance(mm): "); + Serial.print(distance); + + float distanceInches = distance * 0.0393701; + float distanceFeet = distanceInches / 12.0; + + Serial.print("\tDistance(ft): "); + Serial.print(distanceFeet, 2); + + Serial.println(); +} diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 52b1093..f03d4f3 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -54,7 +54,7 @@ bool SFEVL53L1X::checkID() { uint16_t sensorId; _device->VL53L1X_GetSensorId(&sensorId); - if ( (sensorId == 0xEACC) || (sensorId == 0xEBAA) ) + if ((sensorId == 0xEACC) || (sensorId == 0xEBAA)) return true; return false; } @@ -360,3 +360,43 @@ void SFEVL53L1X::calibrateXTalk(uint16_t targetDistanceInMm) uint16_t xTalk = getXTalk(); _device->VL53L1X_CalibrateXtalk(targetDistanceInMm, &xTalk); }; + +bool SFEVL53L1X::setThresholdConfig(DetectionConfig *config) +{ + VL53L1X_ERROR error = _device->VL53L1X_SetDistanceThreshold(config->thresholdLow, config->thresholdHigh, + (uint8_t)config->windowMode, (uint8_t)config->IntOnNoTarget); + return (error == VL53L1_ERROR_NONE); +} + +bool SFEVL53L1X::getThresholdConfig(DetectionConfig *config) +{ + uint16_t temp16 = 0; + + VL53L1X_ERROR error = _device->VL53L1X_GetDistanceMode(&temp16); + if (error != 0) + return false; + else + config->distanceMode = temp16; + + error = _device->VL53L1X_GetDistanceThresholdWindow(&temp16); + if (error != 0) + return false; + else + config->windowMode = temp16; + + config->IntOnNoTarget = 1; + + error = _device->VL53L1X_GetDistanceThresholdLow(&temp16); + if (error != 0) + return false; + else + config->thresholdLow = temp16; + + error = _device->VL53L1X_GetDistanceThresholdHigh(&temp16); + if (error != 0) + return false; + else + config->thresholdHigh = temp16; + + return true; +} \ No newline at end of file diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index 712233d..4334533 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -30,6 +30,22 @@ #include "vl53l1_error_codes.h" #include "vl53l1x_class.h" +#define DISTANCE_SHORT 0 +#define DISTANCE_LONG 1 +#define WINDOW_BELOW 0 +#define WINDOW_ABOVE 1 +#define WINDOW_OUT 2 +#define WINDOW_IN 3 + +struct DetectionConfig +{ + uint16_t distanceMode = DISTANCE_SHORT; // distance mode : DISTANCE_SHORT (0) or DISTANCE_LONG (1) + uint16_t windowMode = WINDOW_IN; // window mode : WINDOW_BELOW (0), WINDOW_ABOVE (1), WINDOW_OUT (2), WINDOW_IN (3) + uint8_t IntOnNoTarget = 1; // = 1 (No longer used - just use 1) + uint16_t thresholdHigh = 0; // (in mm) : the threshold above which one the device raises an interrupt if Window = 1 + uint16_t thresholdLow = 0; // (in mm) : the threshold under which one the device raises an interrupt if Window = 0 +}; + class SFEVL53L1X { public: @@ -108,6 +124,9 @@ class SFEVL53L1X void startTemperatureUpdate(); //Recalibrates the sensor for temperature changes. Run this any time the temperature has changed by more than 8°C 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. 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. + bool setThresholdConfig(DetectionConfig* config); //Sets threshold configuration struct + bool getThresholdConfig(DetectionConfig* config); //Gets current threshold settings. Returns false on error, true otherwise. Stores results in pointer to struct argument. + private: TwoWire *_i2cPort; int _shutdownPin; From 83195ac5d7f43c76c494e3fab6ec7d9e9f6782d7 Mon Sep 17 00:00:00 2001 From: Ricardo Ramos <45825126+PPVJM@users.noreply.github.com> Date: Mon, 31 Jan 2022 18:16:49 -0300 Subject: [PATCH 07/19] Merged pull request and added One Shot example to library. --- .../Example9_OneShotMeasurement.ino | 66 +++++++++++++++++++ src/SparkFun_VL53L1X.cpp | 5 ++ src/SparkFun_VL53L1X.h | 1 + src/vl53l1x_class.cpp | 16 ++++- src/vl53l1x_class.h | 5 ++ 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 examples/Example9_OneShotMeasurement/Example9_OneShotMeasurement.ino diff --git a/examples/Example9_OneShotMeasurement/Example9_OneShotMeasurement.ino b/examples/Example9_OneShotMeasurement/Example9_OneShotMeasurement.ino new file mode 100644 index 0000000..37ae7e1 --- /dev/null +++ b/examples/Example9_OneShotMeasurement/Example9_OneShotMeasurement.ino @@ -0,0 +1,66 @@ +/* + Reading distance from the laser based VL53L1X using a one-shot measurement. + By: Nathan Seidle + Revised by: Andy England, Ricardo Ramos + Pull request by: Joseph Duchesne + SparkFun Electronics + Date: January 31st, 2022 + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). + + SparkFun labored with love to create this code. Feel like supporting open source hardware? + Buy a board from SparkFun! https://www.sparkfun.com/products/14667 + + This example makes a one shot measurement. + + Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor. +*/ + +#include +#include "SparkFun_VL53L1X.h" //Click here to get the library: http://librarymanager/All#SparkFun_VL53L1X + +//Optional interrupt and shutdown pins. +#define SHUTDOWN_PIN 2 +#define INTERRUPT_PIN 3 + +SFEVL53L1X distanceSensor; +//Uncomment the following line to use the optional shutdown and interrupt pins. +//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN); + +void setup(void) +{ + Wire.begin(); + + Serial.begin(115200); + Serial.println("VL53L1X Qwiic Test"); + + if (distanceSensor.begin() != 0) //Begin returns 0 on a good init + { + Serial.println("Sensor failed to begin. Please check wiring. Freezing..."); + while (1) + ; + } + Serial.println("Sensor online!"); + + +} + +void loop(void) +{ + distanceSensor.startOneshotRanging(); //Write configuration bytes to initiate measurement + while (!distanceSensor.checkForDataReady()) + { + delay(1); + } + int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor + + Serial.print("Distance(mm): "); + Serial.print(distance); + + float distanceInches = distance * 0.0393701; + float distanceFeet = distanceInches / 12.0; + + Serial.print("\tDistance(ft): "); + Serial.print(distanceFeet, 2); + + Serial.println(); +} diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index f03d4f3..9cdaa04 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -133,6 +133,11 @@ void SFEVL53L1X::startRanging() _device->VL53L1X_StartRanging(); } +void SFEVL53L1X::startOneshotRanging() +{ + _device->VL53L1X_StartOneshotRanging(); +} + void SFEVL53L1X::stopRanging() { _device->VL53L1X_StopRanging(); diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index 4334533..b0a4834 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -63,6 +63,7 @@ class SFEVL53L1X void setInterruptPolarityLow(); //Set the polarity of an active interrupt to Low uint8_t getInterruptPolarity(); //get the current interrupt polarity void startRanging(); //Begins taking measurements + void startOneshotRanging(); // Start one-shot ranging void stopRanging(); //Stops taking measurements bool checkForDataReady(); //Checks the to see if data is ready void setTimingBudgetInMs(uint16_t timingBudget); //Set the timing budget for a measurement diff --git a/src/vl53l1x_class.cpp b/src/vl53l1x_class.cpp index 4b05cef..4d161aa 100644 --- a/src/vl53l1x_class.cpp +++ b/src/vl53l1x_class.cpp @@ -223,11 +223,21 @@ VL53L1X_ERROR VL53L1X::VL53L1X_GetInterruptPolarity(uint8_t *pInterruptPolarity) VL53L1X_ERROR VL53L1X::VL53L1X_StartRanging() { VL53L1X_ERROR status = 0; - + VL53L1_WrByte(Device, SYSTEM__INTERRUPT_CLEAR, 0x01); /* clear interrupt trigger */ status = VL53L1_WrByte(Device, SYSTEM__MODE_START, 0x40); /* Enable VL53L1X */ return status; } + +VL53L1X_ERROR VL53L1X::VL53L1X_StartOneshotRanging() +{ + VL53L1X_ERROR status = 0; + VL53L1_WrByte(Device, SYSTEM__INTERRUPT_CLEAR, 0x01); /* clear interrupt trigger */ + status = VL53L1_WrByte(Device, SYSTEM__MODE_START, 0x10); /* Enable VL53L1X one-shot ranging */ + return status; +} + + VL53L1X_ERROR VL53L1X::VL53L1X_StopRanging() { VL53L1X_ERROR status = 0; @@ -963,7 +973,7 @@ VL53L1X_ERROR VL53L1X::VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t * status = VL53L1_I2CRead(Dev->I2cDevAddr, index, buffer, 4); if (!status) { - *data = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3]; + *data = (buffer[0] << 24) + (buffer[1] << 16U) + (buffer[2] << 8) + buffer[3]; } return status; } @@ -998,7 +1008,7 @@ VL53L1X_ERROR VL53L1X::VL53L1_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr buffer[0] = RegisterAddr >> 8; buffer[1] = RegisterAddr & 0xFF; dev_i2c->write(buffer, 2); - for (int i = 0; i < NumByteToWrite; i++) + for (uint16_t i = 0; i < NumByteToWrite; i++) dev_i2c->write(pBuffer[i]); dev_i2c->endTransmission(true); diff --git a/src/vl53l1x_class.h b/src/vl53l1x_class.h index 606aabf..458014b 100644 --- a/src/vl53l1x_class.h +++ b/src/vl53l1x_class.h @@ -304,6 +304,11 @@ class VL53L1X : public RangeSensor */ VL53L1X_ERROR VL53L1X_StartRanging(); + /** + * @brief This function starts a one-shot ranging distance operation\n + */ + VL53L1X_ERROR VL53L1X_StartOneshotRanging(); + /** * @brief This function stops the ranging. */ From 5481a09ce552d0b0e3a4af9d1e2638c07cd72a25 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Tue, 1 Feb 2022 10:50:59 +1000 Subject: [PATCH 08/19] Fix setThresholdConfig and incorrect distance mode definitions --- src/SparkFun_VL53L1X.cpp | 10 +++++----- src/SparkFun_VL53L1X.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 9cdaa04..459602d 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -164,12 +164,12 @@ uint16_t SFEVL53L1X::getTimingBudgetInMs() void SFEVL53L1X::setDistanceModeLong() { - _device->VL53L1X_SetDistanceMode(2); + _device->VL53L1X_SetDistanceMode(DISTANCE_LONG); } void SFEVL53L1X::setDistanceModeShort() { - _device->VL53L1X_SetDistanceMode(1); + _device->VL53L1X_SetDistanceMode(DISTANCE_SHORT); } uint8_t SFEVL53L1X::getDistanceMode() @@ -368,9 +368,9 @@ void SFEVL53L1X::calibrateXTalk(uint16_t targetDistanceInMm) bool SFEVL53L1X::setThresholdConfig(DetectionConfig *config) { - VL53L1X_ERROR error = _device->VL53L1X_SetDistanceThreshold(config->thresholdLow, config->thresholdHigh, - (uint8_t)config->windowMode, (uint8_t)config->IntOnNoTarget); - return (error == VL53L1_ERROR_NONE); + return _device->VL53L1X_SetDistanceMode(config->distanceMode) == VL53L1_ERROR_NONE && + _device->VL53L1X_SetDistanceThreshold(config->thresholdLow, config->thresholdHigh, + (uint8_t)config->windowMode, (uint8_t)config->IntOnNoTarget) == VL53L1_ERROR_NONE; } bool SFEVL53L1X::getThresholdConfig(DetectionConfig *config) diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index b0a4834..08b6ae6 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -30,8 +30,8 @@ #include "vl53l1_error_codes.h" #include "vl53l1x_class.h" -#define DISTANCE_SHORT 0 -#define DISTANCE_LONG 1 +#define DISTANCE_SHORT 1 +#define DISTANCE_LONG 2 #define WINDOW_BELOW 0 #define WINDOW_ABOVE 1 #define WINDOW_OUT 2 From ebe6a227d220691084faedeccf5a1a293487c9fd Mon Sep 17 00:00:00 2001 From: "Ho Yun \"Bobby" Date: Tue, 15 Feb 2022 19:44:34 -0700 Subject: [PATCH 09/19] Update README.md --- README.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0c524f8..41ad203 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,30 @@ SparkFun Qwiic 4m Distance Sensor with VL53L1X ======================================== [![Build Status](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/workflows/LibraryBuild/badge.svg)](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/actions) + -![SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)](https://cdn.sparkfun.com//assets/parts/1/2/9/4/8/14722-SparkFun_Distance_Sensor_Breakout-_4_Meter__VL53L1X__Qwiic_-01.jpg) + + + + + + + + + +
SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)SparkFun Distance Sensor - 1.3 Meter, VL53L4CD (Qwiic)
SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic) [SEN-14722]SparkFun Distance Sensor - 1.3 Meter, VL53L4CD (Qwiic)[SEN-18993]
-[*SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)(SEN-14722)*](https://www.sparkfun.com/products/14722) +The VL53L1X is a Time Of Flight (ToF) sensor that use 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? Using the VL53L1X, you can measure the distance to an object up to 4 meters away with millimeter resolution! That’s pretty incredible. -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’re far from done: The VL53L1X is a highly complex sensor with a multitude of options and configurations. We’ve written example sketches that allow you to read the distance, signal rate, and range status. Because STMicroelectronics has chosen not to release a complete datasheet we are forced to reverse engineer the interface from their example code and I2C data stream captures. If you’re into puzzles we could use your help to make the library better! -We’re far from done: The VL53L1X is a highly complex sensor with a multitude of options and configurations. We’ve written example sketches that allow you to read the distance, signal rate, and range status. Because ST has chosen not to release a complete datasheet we are forced to reverse engineer the interface from their example code and I2C data stream captures. If you’re into puzzles we could use your help to make the library better! - -We’ve found the precision of the sensor to be 1mm but the accuracy is around +/-5mm. +We’ve found the precision of VL53L1X sensor to be 1mm but the accuracy is around +/-5mm. SparkFun labored with love to create this code. Feel like supporting open source hardware? Buy a [breakout board](https://www.sparkfun.com/products/14722) from SparkFun! +*Note: The VL53L1X is the cousin of VL53L1X. Overall, the sensor functions the same except for a few differences in the specifications. We've also found the precision of VL53L4CD sensor to be 1mm but the accuracy is around +/-7mm (white target: 88%, indoor, no infrared).* + Repository Contents ------------------- @@ -25,12 +35,15 @@ Repository Contents Documentation -------------- -* **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-hookup-guide)** +* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. +* **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-hookup-guide)**- Basic tutorial for the VL53L1X and VL53L4CD -Product Versions +Products that use this Library -------------- -* **[SEN-14722](https://www.sparkfun.com/products/14722)** - SparkFun red version -* **[SPX-14667](https://www.sparkfun.com/products/14667)** - SparkX Version + +* **[SEN-18993](https://www.sparkfun.com/products/18993)** - SparkFun red version for VL53L4CD +* **[SEN-14722](https://www.sparkfun.com/products/14722)** - SparkFun red version for VL53L1X +* **[SPX-14667](https://www.sparkfun.com/products/14667)** - SparkX Version for VL53L1X License Information ------------------- From da0023513b5dbd7b3045ed3ff200010f1102d966 Mon Sep 17 00:00:00 2001 From: "Ho Yun \"Bobby" Date: Tue, 15 Feb 2022 19:45:02 -0700 Subject: [PATCH 10/19] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 41ad203..254fa83 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ SparkFun Qwiic 4m Distance Sensor with VL53L1X ======================================== [![Build Status](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/workflows/LibraryBuild/badge.svg)](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/actions) - @@ -24,7 +23,7 @@ We’ve found the precision of VL53L1X sensor to be 1mm but the accuracy is arou SparkFun labored with love to create this code. Feel like supporting open source hardware? Buy a [breakout board](https://www.sparkfun.com/products/14722) from SparkFun! -*Note: The VL53L1X is the cousin of VL53L1X. Overall, the sensor functions the same except for a few differences in the specifications. We've also found the precision of VL53L4CD sensor to be 1mm but the accuracy is around +/-7mm (white target: 88%, indoor, no infrared).* +*Note: The VL53L4CD is the cousin of VL53L1X. Overall, the sensor functions the same except for a few differences in the specifications. We've also found the precision of VL53L4CD sensor to be 1mm but the accuracy is around +/-7mm (white target: 88%, indoor, no infrared).* Repository Contents ------------------- From 736ce4b1a138795b02dfd221e04280ae0f10cb59 Mon Sep 17 00:00:00 2001 From: Elias Santistevan Date: Tue, 1 Mar 2022 10:43:36 -0700 Subject: [PATCH 11/19] Updates SparkFun written source files to include MIT license header --- src/SparkFun_VL53L1X.cpp | 22 +++++++++++++++------- src/SparkFun_VL53L1X.h | 22 +++++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 459602d..efaeb35 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -13,13 +13,21 @@ Development environment specifics: Arduino IDE 1.8.1 - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + ==== MIT License ==== + Copyright © 2022 SparkFun Electronics - You should have received a copy of the GNU General Public License - along with this program. If not, see . + Permission is hereby granted, free of charge, to any person obtaining a copy of this + software and associated documentation files (the “Software”), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ===================== */ #include @@ -404,4 +412,4 @@ bool SFEVL53L1X::getThresholdConfig(DetectionConfig *config) config->thresholdHigh = temp16; return true; -} \ No newline at end of file +} diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index 08b6ae6..aa219c4 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -13,13 +13,21 @@ Development environment specifics: Arduino IDE 1.8.1 - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + ==== MIT License ==== + Copyright © 2022 SparkFun Electronics - You should have received a copy of the GNU General Public License - along with this program. If not, see . + Permission is hereby granted, free of charge, to any person obtaining a copy of this + software and associated documentation files (the “Software”), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ===================== */ #pragma once @@ -134,4 +142,4 @@ class SFEVL53L1X int _interruptPin; int _i2cAddress = 0x52; VL53L1X* _device; -}; \ No newline at end of file +}; From 1624364a7f42e4ad87c711f6edc2bbb916bc1e5c Mon Sep 17 00:00:00 2001 From: "Ho Yun \"Bobby" Date: Tue, 1 Mar 2022 10:58:10 -0700 Subject: [PATCH 12/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 254fa83..ed3f5c2 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Repository Contents Documentation -------------- * **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. -* **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-hookup-guide)**- Basic tutorial for the VL53L1X and VL53L4CD +* **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-vl53l4cd-hookup-guide)**- Basic tutorial for the VL53L1X and VL53L4CD Products that use this Library -------------- From 87f8575f32a130b38366f9a2cc982f957d2035bb Mon Sep 17 00:00:00 2001 From: Elias Santistevan Date: Tue, 1 Mar 2022 13:41:46 -0700 Subject: [PATCH 13/19] Moves all of STMicroelectronics source files to their own subfolder * Updated source file pathing in the source files that needed to be changed * Updates examples that were unnecessarily including files that should probably just be included in SparkFun's source files * Moves BSD_3 License to the "st_src" subfolder to reflect the correct licensing for those source files * Adds MIT license to the main repository directory to reflect SparkFun's software contribution with the correct license * Updates the README to reflect the licensing updates --- LICENSE.md | 31 ++++++------------- README.md | 4 ++- .../Example1_ReadDistance.ino | 6 ---- .../Example7_Calibration.ino | 8 ----- src/SparkFun_VL53L1X.cpp | 2 -- src/SparkFun_VL53L1X.h | 8 +++-- src/{ => st_src}/ComponentObject.h | 0 src/st_src/LICENSE.md | 23 ++++++++++++++ src/{ => st_src}/RangeSensor.h | 2 +- src/{ => st_src}/vl53l1_error_codes.h | 0 src/{ => st_src}/vl53l1x_class.cpp | 0 src/{ => st_src}/vl53l1x_class.h | 0 12 files changed, 42 insertions(+), 42 deletions(-) rename src/{ => st_src}/ComponentObject.h (100%) create mode 100644 src/st_src/LICENSE.md rename src/{ => st_src}/RangeSensor.h (98%) rename src/{ => st_src}/vl53l1_error_codes.h (100%) rename src/{ => st_src}/vl53l1x_class.cpp (100%) rename src/{ => st_src}/vl53l1x_class.h (100%) diff --git a/LICENSE.md b/LICENSE.md index 5c9ff4a..1105cff 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,23 +1,12 @@ -COPYRIGHT(c) 2018 STMicroelectronics +Copyright © 2022 SparkFun Electronics -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. Neither the name of STMicroelectronics nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), +to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/README.md b/README.md index ed3f5c2..2721f22 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Products that use this Library License Information ------------------- -This product is _**open source**_! +SparkFun's source files are _**open source**_! Please review the LICENSE.md file for license information. @@ -57,4 +57,6 @@ Please use, reuse, and modify these files as you see fit. Please maintain attrib Distributed as-is; no warranty is given. +The source files included in the subfolder **st_src** are licensed differently. They are licensed under the BSD-3 license, check the License.md in +that subfolder for specifics. - Your friends at SparkFun. diff --git a/examples/Example1_ReadDistance/Example1_ReadDistance.ino b/examples/Example1_ReadDistance/Example1_ReadDistance.ino index 2af66ad..24a6c17 100644 --- a/examples/Example1_ReadDistance/Example1_ReadDistance.ino +++ b/examples/Example1_ReadDistance/Example1_ReadDistance.ino @@ -1,9 +1,3 @@ -#include -#include -#include -#include -#include - /* Reading distance from the laser based VL53L1X By: Nathan Seidle diff --git a/examples/Example7_Calibration/Example7_Calibration.ino b/examples/Example7_Calibration/Example7_Calibration.ino index c06f220..d960a5d 100644 --- a/examples/Example7_Calibration/Example7_Calibration.ino +++ b/examples/Example7_Calibration/Example7_Calibration.ino @@ -1,11 +1,3 @@ -#include - -#include -#include -#include -#include -#include - /* Calling distance offset calibration for the laser based VL53L1X By: Armin Joachimsmeyer diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index efaeb35..b540436 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -31,9 +31,7 @@ */ #include -#include "Arduino.h" #include "SparkFun_VL53L1X.h" -#include "vl53l1x_class.h" SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin) { diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index aa219c4..20fb682 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -34,9 +34,11 @@ #include "Arduino.h" #include "Wire.h" -#include "RangeSensor.h" -#include "vl53l1_error_codes.h" -#include "vl53l1x_class.h" +#include "st_src/RangeSensor.h" +#include "st_src/vl53l1_error_codes.h" +#include "st_src/vl53l1x_class.h" +#include "st_src/ComponentObject.h" +#include "st_src/RangeSensor.h" #define DISTANCE_SHORT 1 #define DISTANCE_LONG 2 diff --git a/src/ComponentObject.h b/src/st_src/ComponentObject.h similarity index 100% rename from src/ComponentObject.h rename to src/st_src/ComponentObject.h diff --git a/src/st_src/LICENSE.md b/src/st_src/LICENSE.md new file mode 100644 index 0000000..5c9ff4a --- /dev/null +++ b/src/st_src/LICENSE.md @@ -0,0 +1,23 @@ +COPYRIGHT(c) 2018 STMicroelectronics + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + 3. Neither the name of STMicroelectronics nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/RangeSensor.h b/src/st_src/RangeSensor.h similarity index 98% rename from src/RangeSensor.h rename to src/st_src/RangeSensor.h index 119112e..0643268 100644 --- a/src/RangeSensor.h +++ b/src/st_src/RangeSensor.h @@ -41,7 +41,7 @@ #define __RANGE_SENSOR_CLASS_H /* Includes ------------------------------------------------------------------*/ -#include +#include /* Classes ------------------------------------------------------------------*/ /** An abstract class for range sensors diff --git a/src/vl53l1_error_codes.h b/src/st_src/vl53l1_error_codes.h similarity index 100% rename from src/vl53l1_error_codes.h rename to src/st_src/vl53l1_error_codes.h diff --git a/src/vl53l1x_class.cpp b/src/st_src/vl53l1x_class.cpp similarity index 100% rename from src/vl53l1x_class.cpp rename to src/st_src/vl53l1x_class.cpp diff --git a/src/vl53l1x_class.h b/src/st_src/vl53l1x_class.h similarity index 100% rename from src/vl53l1x_class.h rename to src/st_src/vl53l1x_class.h From 94d0162af3de230dbcf354376d7cee68c53f32e0 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sun, 15 May 2022 17:23:08 +0100 Subject: [PATCH 14/19] Add alternate sensor ID 0xEAAA --- src/SparkFun_VL53L1X.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index b540436..34eaa65 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -60,7 +60,7 @@ bool SFEVL53L1X::checkID() { uint16_t sensorId; _device->VL53L1X_GetSensorId(&sensorId); - if ((sensorId == 0xEACC) || (sensorId == 0xEBAA)) + if ((sensorId == 0xEACC) || (sensorId == 0xEBAA) || (sensorId == 0xEAAA)) return true; return false; } From c4982b892e0a9d27fae0c69cc7d1ca953e1af586 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sun, 15 May 2022 17:38:03 +0100 Subject: [PATCH 15/19] Revert "Add alternate sensor ID 0xEAAA" This reverts commit 94d0162af3de230dbcf354376d7cee68c53f32e0. --- src/SparkFun_VL53L1X.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 34eaa65..b540436 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -60,7 +60,7 @@ bool SFEVL53L1X::checkID() { uint16_t sensorId; _device->VL53L1X_GetSensorId(&sensorId); - if ((sensorId == 0xEACC) || (sensorId == 0xEBAA) || (sensorId == 0xEAAA)) + if ((sensorId == 0xEACC) || (sensorId == 0xEBAA)) return true; return false; } From 2088a8909648bad374f29dccfc64bbf8016561e5 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 12 Oct 2022 14:25:56 +0100 Subject: [PATCH 16/19] Add begin(TwoWire &i2cPort) - requires VL53L1X::dev_i2c to be public --- library.properties | 2 +- src/SparkFun_VL53L1X.cpp | 40 ++++++++++++++++++++++++++++++++++++++ src/SparkFun_VL53L1X.h | 7 ++++++- src/st_src/vl53l1x_class.h | 5 ++++- 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/library.properties b/library.properties index c3e0e97..36652fc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun VL53L1X 4m Laser Distance Sensor -version=1.2.11 +version=1.2.12 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index b540436..38bb6d2 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -33,6 +33,27 @@ #include #include "SparkFun_VL53L1X.h" +SFEVL53L1X::SFEVL53L1X() +{ + _i2cPort = &Wire; + _shutdownPin = -1; + _interruptPin = -1; + _device = new VL53L1X(&Wire, -1, -1); +} +SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort) +{ + _i2cPort = &i2cPort; + _shutdownPin = -1; + _interruptPin = -1; + _device = new VL53L1X(&i2cPort, -1, -1); +} +SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin) +{ + _i2cPort = &i2cPort; + _shutdownPin = shutdownPin; + _interruptPin = -1; + _device = new VL53L1X(&i2cPort, shutdownPin, -1); +} SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin) { _i2cPort = &i2cPort; @@ -54,6 +75,25 @@ bool SFEVL53L1X::begin() return _device->VL53L1X_SensorInit(); } +bool SFEVL53L1X::begin(TwoWire &i2cPort) +{ + _i2cPort = &i2cPort; + _device->dev_i2c = &i2cPort; + + if (checkID() == false) + { + Serial.println("Check ID failed..."); + return (VL53L1_ERROR_PLATFORM_SPECIFIC_START); + } + + bool result = _device->VL53L1X_SensorInit() == 0; + + if (!result) + Serial.println("Init failed..."); + + return result; +} + /*Checks the ID of the device, returns true if ID is correct*/ bool SFEVL53L1X::checkID() diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index 20fb682..7ae3323 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -59,9 +59,14 @@ struct DetectionConfig class SFEVL53L1X { public: - SFEVL53L1X(TwoWire &i2cPort = Wire, int shutdownPin = -1, int interruptPin = -1); //Constructs our Distance sensor without an interrupt or shutdown pin + //Constructs our Distance sensor + SFEVL53L1X(); // Default to Wire. Set both pins to -1 (undefined). + SFEVL53L1X(TwoWire &i2cPort); // Set both pins to -1 (undefined). + SFEVL53L1X(TwoWire &i2cPort, int shutdownPin); // Set interrupt pin to -1 (undefined). + SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin); bool init(); //Deprecated version of begin bool begin(); //Initialization of sensor + bool begin(TwoWire &i2cPort); //Initialization of sensor bool checkID(); //Check the ID of the sensor, returns true if ID is correct void sensorOn(); //Toggles shutdown pin to turn sensor on and off void sensorOff(); //Toggles shutdown pin to turn sensor on and off diff --git a/src/st_src/vl53l1x_class.h b/src/st_src/vl53l1x_class.h index 458014b..0af5eea 100644 --- a/src/st_src/vl53l1x_class.h +++ b/src/st_src/vl53l1x_class.h @@ -553,10 +553,13 @@ class VL53L1X : public RangeSensor - protected: + public: /* IO Device */ TwoWire *dev_i2c; + + protected: + /* Digital out pin */ int gpio0; int gpio1Int; From 2a4660a4f6a37c2889c5fd4580f34f2f6b57869e Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 12 Oct 2022 14:52:49 +0100 Subject: [PATCH 17/19] Remove unnecessary overloads --- src/SparkFun_VL53L1X.cpp | 14 -------------- src/SparkFun_VL53L1X.h | 4 +--- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 38bb6d2..980d771 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -40,20 +40,6 @@ SFEVL53L1X::SFEVL53L1X() _interruptPin = -1; _device = new VL53L1X(&Wire, -1, -1); } -SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort) -{ - _i2cPort = &i2cPort; - _shutdownPin = -1; - _interruptPin = -1; - _device = new VL53L1X(&i2cPort, -1, -1); -} -SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin) -{ - _i2cPort = &i2cPort; - _shutdownPin = shutdownPin; - _interruptPin = -1; - _device = new VL53L1X(&i2cPort, shutdownPin, -1); -} SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin) { _i2cPort = &i2cPort; diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index 7ae3323..ef2dcc6 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -61,9 +61,7 @@ class SFEVL53L1X public: //Constructs our Distance sensor SFEVL53L1X(); // Default to Wire. Set both pins to -1 (undefined). - SFEVL53L1X(TwoWire &i2cPort); // Set both pins to -1 (undefined). - SFEVL53L1X(TwoWire &i2cPort, int shutdownPin); // Set interrupt pin to -1 (undefined). - SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin); + SFEVL53L1X(TwoWire &i2cPort, int shutdownPin = -1, int interruptPin = -1); bool init(); //Deprecated version of begin bool begin(); //Initialization of sensor bool begin(TwoWire &i2cPort); //Initialization of sensor From 832c0b0467cbde249a74d1d839424d919194f185 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 12 Oct 2022 16:46:00 +0100 Subject: [PATCH 18/19] Add destructor. Correct begin overload --- src/SparkFun_VL53L1X.cpp | 17 +++++------------ src/SparkFun_VL53L1X.h | 1 + 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/SparkFun_VL53L1X.cpp b/src/SparkFun_VL53L1X.cpp index 980d771..4ea1cb4 100644 --- a/src/SparkFun_VL53L1X.cpp +++ b/src/SparkFun_VL53L1X.cpp @@ -47,6 +47,10 @@ SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin) _interruptPin = interruptPin; _device = new VL53L1X(&i2cPort, shutdownPin, interruptPin); } +SFEVL53L1X::~SFEVL53L1X() +{ + delete (VL53L1X *)_device; +} bool SFEVL53L1X::init() { @@ -66,18 +70,7 @@ bool SFEVL53L1X::begin(TwoWire &i2cPort) _i2cPort = &i2cPort; _device->dev_i2c = &i2cPort; - if (checkID() == false) - { - Serial.println("Check ID failed..."); - return (VL53L1_ERROR_PLATFORM_SPECIFIC_START); - } - - bool result = _device->VL53L1X_SensorInit() == 0; - - if (!result) - Serial.println("Init failed..."); - - return result; + return begin(); } /*Checks the ID of the device, returns true if ID is correct*/ diff --git a/src/SparkFun_VL53L1X.h b/src/SparkFun_VL53L1X.h index ef2dcc6..fbb940a 100644 --- a/src/SparkFun_VL53L1X.h +++ b/src/SparkFun_VL53L1X.h @@ -62,6 +62,7 @@ class SFEVL53L1X //Constructs our Distance sensor SFEVL53L1X(); // Default to Wire. Set both pins to -1 (undefined). SFEVL53L1X(TwoWire &i2cPort, int shutdownPin = -1, int interruptPin = -1); + ~SFEVL53L1X(); bool init(); //Deprecated version of begin bool begin(); //Initialization of sensor bool begin(TwoWire &i2cPort); //Initialization of sensor From e88f55d6d82a4a8c519ec90a2660e6ec799b4579 Mon Sep 17 00:00:00 2001 From: SFEMark Date: Thu, 16 Nov 2023 15:59:12 -0700 Subject: [PATCH 19/19] Create add_issue_to_project.yml Adding .yml file for issue tracking in GH projects. --- .github/workflows/add_issue_to_project.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/add_issue_to_project.yml diff --git a/.github/workflows/add_issue_to_project.yml b/.github/workflows/add_issue_to_project.yml new file mode 100644 index 0000000..6b60cc3 --- /dev/null +++ b/.github/workflows/add_issue_to_project.yml @@ -0,0 +1,18 @@ +name: Add new issue to our main project + +on: + issues: + types: + - opened + +jobs: + add-to-project: + name: Add issue to project + runs-on: ubuntu-latest + steps: + - uses: actions/add-to-project@main + with: + # You can target a project in a different organization + # to the issue + project-url: https://github.com/orgs/sparkfun/projects/19 + github-token: ${{ secrets.DEFECT_ADD_TO_PROJECT }}