Skip to content

Commit

Permalink
fixing issues withtypes, updating examples to use begin
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyEngland521 committed Jan 7, 2019
1 parent e35acdf commit 8cefa5b
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 116 deletions.
4 changes: 3 additions & 1 deletion examples/Example1_ReadDistance/Example1_ReadDistance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Reading distance from the laser based VL53L1X
By: Nathan Seidle
Revised by: Andy England
SparkFun Electronics
Date: April 4th, 2018
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Expand All @@ -20,7 +21,9 @@
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
Expand All @@ -44,6 +47,8 @@ void loop(void)

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

distanceSensor.stopRanging();

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

Expand Down
5 changes: 4 additions & 1 deletion examples/Example3_StatusAndRate/Example3_StatusAndRate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

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

Serial.print("Distance(mm): ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
Expand All @@ -39,8 +41,8 @@ void setup(void)
void loop(void)
{
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement

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

Serial.print("Distance(mm): ");
Serial.print(distance);
Expand Down
15 changes: 6 additions & 9 deletions examples/Example5_LCDDemo/Example5_LCDDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
#include <Wire.h>
#include "SparkFun_VL53L1X.h"
#include <SoftwareSerial.h>

//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

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

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

Expand Down Expand Up @@ -82,13 +83,9 @@ void loop(void)

//Write configuration block of 135 bytes to setup a measurement
distanceSensor.startRanging();

//Poll for completion of measurement. Takes 40-50ms.
while (distanceSensor.checkForDataReady() == false)
delay(5);

int distanceMM = distanceSensor.getDistance();

distanceSensor.stopRanging();

lastReading = millis();

history[historySpot] = distanceMM;
Expand Down
98 changes: 53 additions & 45 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -1,61 +1,69 @@
#######################################
# Syntax Coloring Map
# Syntax Coloring Map For ST_FlightSense_Sensor_Shields
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

VL53L1X KEYWORD1
SFEVL53L1X KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

init KEYWORD2
begin KEYWORD2
startRanging KEYWORD2
checkForDataReady KEYWORD2
setTimingBudgetInMs KEYWORD2
getTimingBudgetInMs KEYWORD2
setDistanceModeLong KEYWORD2
setDistanceModeShort KEYWORD2
getDistanceMode KEYWORD2
setIntermeasurementPeriod KEYWORD2
getIntermeasurementPeriod KEYWORD2
checkBootState KEYWORD2
getSensorID KEYWORD2
getDistance KEYWORD2
getSignalPerSpad KEYWORD2
getAmbientPerSpad KEYWORD2
getSignalRate KEYWORD2
getSpadNb KEYWORD2
getAmbientRate KEYWORD2
getRangeStatus KEYWORD2
setOffset KEYWORD2
getOffset KEYWORD2
setXTalk KEYWORD2
getXTalk KEYWORD2
setDistanceThreshold KEYWORD2
getDistanceThresholdWindow KEYWORD2
getDistanceThresholdLow KEYWORD2
getDistanceThresholdHigh KEYWORD2
setROI KEYWORD2
getROIX KEYWORD2
getROIY KEYWORD2
setSignalThreshold KEYWORD2
getSignalThreshold KEYWORD2
setSigmaThreshold KEYWORD2
getSigmaThreshold KEYWORD2
startTemperatureUpdate KEYWORD2
calibrateOffset KEYWORD2
calibrateXTalk KEYWORD2

readRegister KEYWORD2
readRegister16 KEYWORD2
writeRegister KEYWORD2
writeRegister16 KEYWORD2
init KEYWORD2
begin KEYWORD2
checkID KEYWORD2
sensorOn KEYWORD2
sensorOff KEYWORD2
getSoftwareVersion KEYWORD2
setI2CAddress KEYWORD2
getI2CAddress KEYWORD2
clearInterrupt KEYWORD2
setInterruptPolarityHigh KEYWORD2
setInterruptPolarityLow KEYWORD2
getInterruptPolarity KEYWORD2
startRanging KEYWORD2
stopRanging KEYWORD2
checkForDataReady KEYWORD2
setTimingBudgetInMs KEYWORD2
getTimingBudgetInMs KEYWORD2
setDistanceModeLong KEYWORD2
setDistanceModeShort KEYWORD2
getDistanceMode KEYWORD2
setIntermeasurementPeriod KEYWORD2
getIntermeasurementPeriod KEYWORD2
checkBootState KEYWORD2
getSensorID KEYWORD2
getDistance KEYWORD2
getSignalPerSpad KEYWORD2
getAmbientPerSpad KEYWORD2
getSignalRate KEYWORD2
getSpadNb KEYWORD2
getAmbientRate KEYWORD2
getRangeStatus KEYWORD2
setOffset KEYWORD2
getOffset KEYWORD2
setXTalk KEYWORD2
getXTalk KEYWORD2
setDistanceThreshold KEYWORD2
getDistanceThresholdWindow KEYWORD2
getDistanceThresholdLow KEYWORD2
getDistanceThresholdHig KEYWORD2
setROI KEYWORD2
getROIX KEYWORD2
getROIY KEYWORD2
setSignalThreshold KEYWORD2
getSignalThreshold KEYWORD2
setSigmaThreshold KEYWORD2
getSigmaThreshold KEYWORD2
startTemperatureUpdate KEYWORD2
calibrateOffset KEYWORD2
calibrateXTalk KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################


4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=SparkFun VL53L1X 4m Laser Distance Sensor
version=1.1.1
version=1.1.2
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X
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
category=Sensors
url=https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library
architectures=*
architectures=*
9 changes: 5 additions & 4 deletions src/SparkFun_VL53L1X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void SFEVL53L1X::setOffset(int16_t offset)

int16_t SFEVL53L1X::getOffset()
{
int16_t temp;
uint16_t temp;
_device->VL53L1X_GetOffset(&temp);
return temp;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ uint16_t SFEVL53L1X::getDistanceThresholdHigh()

void SFEVL53L1X::setROI(uint16_t x, uint16_t y)
{
_device->VL53L1X_SetROI(x, y);
_device->VL53L1X_SetROI(x, x);
}

uint16_t SFEVL53L1X::getROIX()
Expand Down Expand Up @@ -331,5 +331,6 @@ void SFEVL53L1X::calibrateOffset(uint16_t targetDistanceInMm)

void SFEVL53L1X::calibrateXTalk(uint16_t targetDistanceInMm)
{
_device->VL53L1X_CalibrateXtalk(targetDistanceInMm, getXTalk());
};
int16_t xTalk = getXTalk();
_device->VL53L1X_CalibrateXtalk(targetDistanceInMm, xTalk);
};
105 changes: 54 additions & 51 deletions src/SparkFun_VL53L1X.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,60 @@
class SFEVL53L1X
{
public:
SFEVL53L1X(TwoWire &i2cPort = Wire, int shutdownPin = -1, int interruptPin = -1);
bool init();
bool checkID();
void sensorOn();
void sensorOff(); //virtual void VL53L1_Off(void)
VL53L1X_Version_t getSoftwareVersion();//VL53L1X_ERROR VL53L1X_GetSWVersion(VL53L1X_Version_t *pVersion);
void setI2CAddress(uint8_t addr);//VL53L1X_ERROR VL53L1X_SetI2CAddress(uint8_t new_address);
int getI2CAddress();
void clearInterrupt();//VL53L1X_ERROR VL53L1X_ClearInterrupt();
void setInterruptPolarityHigh();//VL53L1X_ERROR VL53L1X_SetInterruptPolarity(uint8_t IntPol);
void setInterruptPolarityLow();
uint8_t getInterruptPolarity();//VL53L1X_ERROR VL53L1X_GetInterruptPolarity(uint8_t *pIntPol);
void startRanging();//Begins taking measurements
void stopRanging();//Stops taking measurements
bool checkForDataReady();//VL53L1X_ERROR VL53L1X_CheckForDataReady(uint8_t *isDataReady);
void setTimingBudgetInMs(uint16_t timingBudget);//VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs(uint16_t TimingBudgetInMs);
uint16_t getTimingBudgetInMs();//VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs(uint16_t *pTimingBudgetInMs);
void setDistanceModeLong();//VL53L1X_ERROR VL53L1X_SetDistanceMode(uint16_t DistanceMode);
void setDistanceModeShort();//VL53L1X_ERROR VL53L1X_GetDistanceMode(uint16_t *pDistanceMode);
uint8_t getDistanceMode();
void setIntermeasurementPeriod(uint16_t intermeasurement);//VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs(uint16_t InterMeasurementInMs);
uint16_t getIntermeasurementPeriod();//VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs(uint16_t * pIM);
bool checkBootState();//VL53L1X_ERROR VL53L1X_BootState(uint8_t *state);
uint16_t getSensorID();//VL53L1X_ERROR VL53L1X_GetSensorId(uint16_t *id);
uint16_t getDistance();//Returns distance
uint16_t getSignalPerSpad();//VL53L1X_ERROR VL53L1X_GetSignalPerSpad(uint16_t *signalPerSp);
uint16_t getAmbientPerSpad();//VL53L1X_ERROR VL53L1X_GetAmbientPerSpad(uint16_t *amb);
uint16_t getSignalRate();//VL53L1X_ERROR VL53L1X_GetSignalRate(uint16_t *signalRate);
uint16_t getSpadNb();//VL53L1X_ERROR VL53L1X_GetSpadNb(uint16_t *spNb);
uint16_t getAmbientRate();//VL53L1X_ERROR VL53L1X_GetAmbientRate(uint16_t *ambRate);
uint8_t getRangeStatus();//VL53L1X_ERROR VL53L1X_GetRangeStatus(uint8_t *rangeStatus);
void setOffset(int16_t offset);//VL53L1X_ERROR VL53L1X_SetOffset(int16_t OffsetValue);
int16_t getOffset();//VL53L1X_ERROR VL53L1X_GetOffset(int16_t *Offset);
void setXTalk(uint16_t xTalk);//VL53L1X_ERROR VL53L1X_SetXtalk(uint16_t XtalkValue);
uint16_t getXTalk();//VL53L1X_ERROR VL53L1X_GetXtalk(uint16_t *Xtalk);
void setDistanceThreshold(uint16_t lowThresh, uint16_t hiThresh, uint8_t window);//VL53L1X_ERROR VL53L1X_SetDistanceThreshold(uint16_t ThreshLow,
// uint16_t ThreshHigh, uint8_t Window,
// uint8_t IntOnNoTarget);
uint16_t getDistanceThresholdWindow();//VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow(uint16_t *window);
uint16_t getDistanceThresholdLow();//VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow(uint16_t *low);
uint16_t getDistanceThresholdHigh();//VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh(uint16_t *high);
void setROI(uint16_t x, uint16_t y);//VL53L1X_ERROR VL53L1X_SetROI(uint16_t X, uint16_t Y);
uint16_t getROIX();//VL53L1X_ERROR VL53L1X_GetROI_XY(uint16_t *ROI_X, uint16_t *ROI_Y);
uint16_t getROIY();
void setSignalThreshold(uint16_t signalThreshold);//VL53L1X_ERROR VL53L1X_SetSignalThreshold(uint16_t signal);
uint16_t getSignalThreshold();//VL53L1X_ERROR VL53L1X_GetSignalThreshold(uint16_t *signal);
void setSigmaThreshold(uint16_t sigmaThreshold);//VL53L1X_ERROR VL53L1X_SetSigmaThreshold(uint16_t sigma);
uint16_t getSigmaThreshold();//VL53L1X_ERROR VL53L1X_GetSigmaThreshold(uint16_t *signal);
void startTemperatureUpdate();//VL53L1X_ERROR VL53L1X_StartTemperatureUpdate();
void calibrateOffset(uint16_t targetDistanceInMm);//int8_t VL53L1X_CalibrateOffset(uint16_t TargetDistInMm, int16_t *offset);
void calibrateXTalk(uint16_t targetDistanceInMm);//int8_t VL53L1X_CalibrateXtalk(uint16_t TargetDistInMm, uint16_t *xtalk);
SFEVL53L1X(TwoWire &i2cPort = Wire, int shutdownPin = -1, int interruptPin = -1); //Constructs our Distance sensor without an interrupt or shutdown pin
bool init(); //Deprecated version of begin
bool begin(); //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
VL53L1X_Version_t getSoftwareVersion(); //Get's the current ST software version
void setI2CAddress(uint8_t addr); //Set the I2C address
int getI2CAddress(); //Get the I2C address
void clearInterrupt(); // Clear the interrupt flag
void setInterruptPolarityHigh(); //Set the polarity of an active interrupt to High
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 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
uint16_t getTimingBudgetInMs(); //Get the timing budget for a measurement
void setDistanceModeLong(); //Set to 4M range
void setDistanceModeShort(); //Set to 1.3M range
uint8_t getDistanceMode(); //Get the distance mode, returns 1 for short and 2 for long
void setIntermeasurementPeriod(uint16_t intermeasurement); //Set time between measurements in ms
uint16_t getIntermeasurementPeriod(); //Get time between measurements in ms
bool checkBootState(); //Check if the VL53L1X has been initialized
uint16_t getSensorID(); //Get the sensor ID
uint16_t getDistance(); //Returns distance
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.
uint16_t getAmbientPerSpad(); //Returns the ambient noise when not measuring a signal in kcps/SPAD.
uint16_t getSignalRate(); //Returns the signal rate in kcps. All SPADs combined.
uint16_t getSpadNb(); //Returns the current number of enabled SPADs
uint16_t getAmbientRate(); // Returns the total ambinet rate in kcps. All SPADs combined.
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
void setOffset(int16_t offset); //Manually set an offset in mm
int16_t getOffset(); //Get the current offset in mm
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.
uint16_t getXTalk(); //Returns the current crosstalk value in cps.
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.
//0: Interrupt triggered on measured distance below lowThresh.
//1: Interrupt triggered on measured distance above hiThresh.
//2: Interrupt triggered on measured distance outside of bounds.
//3: Interrupt triggered on measured distance inside of bounds.
uint16_t getDistanceThresholdWindow(); //Returns distance threshold window option
uint16_t getDistanceThresholdLow(); //Returns lower bound in mm.
uint16_t getDistanceThresholdHigh(); //Returns upper bound in mm
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.
uint16_t getROIX(); //Returns the width of the ROI in SPADs
uint16_t getROIY(); //Returns the height of the ROI in SPADs
void setSignalThreshold(uint16_t signalThreshold); //Programs the necessary threshold to trigger a measurement. Default is 1024 kcps.
uint16_t getSignalThreshold(); //Returns the signal threshold in kcps
void setSigmaThreshold(uint16_t sigmaThreshold); //Programs a new sigma threshold in mm. (default=15 mm)
uint16_t getSigmaThreshold(); //Returns the current sigma threshold.
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.
private:
TwoWire *_i2cPort;
int _shutdownPin;
Expand Down

0 comments on commit 8cefa5b

Please sign in to comment.