Adafruit Library
Adafruit_VL53L0X.h
Go to the documentation of this file.
1 
22 #ifndef ADAFRUIT_VL53L0X_H
23 #define ADAFRUIT_VL53L0X_H
24 
25 #if (ARDUINO >= 100)
26 #include "Arduino.h"
27 #else
28 #include "WProgram.h"
29 #endif
30 
31 #include "Wire.h"
32 #include "vl53l0x_api.h"
33 
34 #define VL53L0X_I2C_ADDR 0x29
35 
36 /**************************************************************************/
41 /**************************************************************************/
43  public:
45  typedef enum {
46  VL53L0X_SENSE_DEFAULT = 0,
47  VL53L0X_SENSE_LONG_RANGE,
48  VL53L0X_SENSE_HIGH_SPEED,
49  VL53L0X_SENSE_HIGH_ACCURACY
51 
52  boolean begin(uint8_t i2c_addr = VL53L0X_I2C_ADDR, boolean debug = false,
53  TwoWire* i2c = &Wire,
54  VL53L0X_Sense_config_t vl_config = VL53L0X_SENSE_DEFAULT);
55  boolean setAddress(uint8_t newAddr);
56 
57  // uint8_t getAddress(void); // not currently implemented
58 
59  /**************************************************************************/
68  /**************************************************************************/
69  VL53L0X_Error rangingTest(
70  VL53L0X_RangingMeasurementData_t* pRangingMeasurementData,
71  boolean debug = false) {
72  return getSingleRangingMeasurement(pRangingMeasurementData, debug);
73  };
74 
75  VL53L0X_Error getSingleRangingMeasurement(
76  VL53L0X_RangingMeasurementData_t* pRangingMeasurementData,
77  boolean debug = false);
78  void printRangeStatus(
79  VL53L0X_RangingMeasurementData_t* pRangingMeasurementData);
80 
81  VL53L0X_Error getRangingMeasurement(
82  VL53L0X_RangingMeasurementData_t* pRangingMeasurementData,
83  boolean debug = false);
84  VL53L0X_Error startMeasurement(boolean debug = false);
85  VL53L0X_Error stopMeasurement(boolean debug = false);
86  VL53L0X_Error getLimitCheckCurrent(uint8_t LimitCheckId,
87  FixPoint1616_t* pLimitCheckCurrent,
88  boolean debug = false);
89  VL53L0X_Error getDeviceMode(VL53L0X_DeviceModes* pDeviceMode,
90  boolean debug = false);
91  VL53L0X_Error setDeviceMode(VL53L0X_DeviceModes DeviceMode,
92  boolean debug = false);
93 
94  VL53L0X_Error setInterruptThresholds(FixPoint1616_t ThresholdLow,
95  FixPoint1616_t ThresholdHigh,
96  boolean debug = false);
97  VL53L0X_Error getInterruptThresholds(FixPoint1616_t* pThresholdLow,
98  FixPoint1616_t* pThresholdHigh,
99  boolean debug = false);
100  VL53L0X_Error clearInterruptMask(boolean debug = false);
101 
102  VL53L0X_Error getGpioConfig(VL53L0X_DeviceModes* pDeviceMode,
103  VL53L0X_GpioFunctionality* pFunctionality,
104  VL53L0X_InterruptPolarity* pPolarity,
105  boolean debug = false);
106  VL53L0X_Error setGpioConfig(VL53L0X_DeviceModes DeviceMode,
107  VL53L0X_GpioFunctionality Functionality,
108  VL53L0X_InterruptPolarity Polarity,
109  boolean debug = false);
110 
111  VL53L0X_Error Status =
112  VL53L0X_ERROR_NONE;
113  // Add similar methods as Adafruit_VL6180X class adapted to range of device
115  uint16_t readRange(void);
116  // float readLux(uint8_t gain);
117  uint8_t readRangeStatus(void);
118 
119  boolean startRange(void);
120  boolean isRangeComplete(void);
121  boolean waitRangeComplete(void);
122  uint16_t readRangeResult(void);
123 
124  boolean startRangeContinuous(uint16_t period_ms = 50);
125  void stopRangeContinuous(void);
126 
127  // void setTimeout(uint16_t timeout) { io_timeout = timeout; }
128  // uint16_t getTimeout(void) { return io_timeout; }
129  /**************************************************************************/
134  /**************************************************************************/
135  boolean timeoutOccurred(void) {
136  return false;
137  }
138 
139  boolean configSensor(VL53L0X_Sense_config_t vl_config);
140 
141  // Export some wrappers to internal setting functions
142  // that are used by the above helper function to allow
143  // more complete control.
144  boolean setMeasurementTimingBudgetMicroSeconds(uint32_t budget_us);
146 
147  boolean setVcselPulsePeriod(VL53L0X_VcselPeriod VcselPeriodType,
148  uint8_t VCSELPulsePeriod);
149 
150  uint8_t getVcselPulsePeriod(VL53L0X_VcselPeriod VcselPeriodType);
151 
152  boolean setLimitCheckEnable(uint16_t LimitCheckId, uint8_t LimitCheckEnable);
153  uint8_t getLimitCheckEnable(uint16_t LimitCheckId);
154  boolean setLimitCheckValue(uint16_t LimitCheckId,
155  FixPoint1616_t LimitCheckValue);
156  FixPoint1616_t getLimitCheckValue(uint16_t LimitCheckId);
157 
158  private:
159  VL53L0X_Dev_t MyDevice;
160  VL53L0X_Dev_t* pMyDevice = &MyDevice;
161  VL53L0X_DeviceInfo_t DeviceInfo;
162 
163  uint8_t _rangeStatus;
164 };
165 
166 #endif
boolean setVcselPulsePeriod(VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriod)
Sets the VCSEL pulse period.
Definition: Adafruit_VL53L0X.cpp:886
boolean setAddress(uint8_t newAddr)
Change the I2C address of the sensor.
Definition: Adafruit_VL53L0X.cpp:195
boolean setLimitCheckValue(uint16_t LimitCheckId, FixPoint1616_t LimitCheckValue)
Set a specific limit check value.
Definition: Adafruit_VL53L0X.cpp:953
VL53L0X_Error getRangingMeasurement(VL53L0X_RangingMeasurementData_t *pRangingMeasurementData, boolean debug=false)
get a ranging measurement from the device
Definition: Adafruit_VL53L0X.cpp:630
boolean startRange(void)
Start a range operation.
Definition: Adafruit_VL53L0X.cpp:727
boolean startRangeContinuous(uint16_t period_ms=50)
Start a continuous range operation.
Definition: Adafruit_VL53L0X.cpp:794
boolean isRangeComplete(void)
Checks to see if a range operation has completed.
Definition: Adafruit_VL53L0X.cpp:747
uint16_t readRangeResult(void)
Return the range in mm for the last operation.
Definition: Adafruit_VL53L0X.cpp:773
VL53L0X_Error setDeviceMode(VL53L0X_DeviceModes DeviceMode, boolean debug=false)
Set a new device mode.
Definition: Adafruit_VL53L0X.cpp:451
uint16_t readRange(void)
Single shot ranging. Be sure to check the return of readRangeStatus to before using the return value!...
Definition: Adafruit_VL53L0X.cpp:697
boolean setMeasurementTimingBudgetMicroSeconds(uint32_t budget_us)
Wrapper to ST library code to budget how long a measurement should take.
Definition: Adafruit_VL53L0X.cpp:857
boolean timeoutOccurred(void)
timeout status
Definition: Adafruit_VL53L0X.h:135
uint8_t getVcselPulsePeriod(VL53L0X_VcselPeriod VcselPeriodType)
Gets the VCSEL pulse period.
Definition: Adafruit_VL53L0X.cpp:901
boolean begin(uint8_t i2c_addr=VL53L0X_I2C_ADDR, boolean debug=false, TwoWire *i2c=&Wire, VL53L0X_Sense_config_t vl_config=VL53L0X_SENSE_DEFAULT)
Setups the I2C interface and hardware.
Definition: Adafruit_VL53L0X.cpp:58
void stopRangeContinuous(void)
Stop a continuous ranging operation.
Definition: Adafruit_VL53L0X.cpp:818
VL53L0X_Error getInterruptThresholds(FixPoint1616_t *pThresholdLow, FixPoint1616_t *pThresholdHigh, boolean debug=false)
Get high and low Interrupt thresholds.
Definition: Adafruit_VL53L0X.cpp:502
Class that stores state and functions for interacting with VL53L0X time-of-flight sensor chips...
Definition: Adafruit_VL53L0X.h:42
VL53L0X_Error setInterruptThresholds(FixPoint1616_t ThresholdLow, FixPoint1616_t ThresholdHigh, boolean debug=false)
Set low and high Interrupt thresholds.
Definition: Adafruit_VL53L0X.cpp:474
uint32_t getMeasurementTimingBudgetMicroSeconds(void)
Wrapper to ST library code to budget how long a measurement should take.
Definition: Adafruit_VL53L0X.cpp:870
VL53L0X_Error setGpioConfig(VL53L0X_DeviceModes DeviceMode, VL53L0X_GpioFunctionality Functionality, VL53L0X_InterruptPolarity Polarity, boolean debug=false)
Set the configuration of GPIO pin 0.
Definition: Adafruit_VL53L0X.cpp:574
VL53L0X_Error getSingleRangingMeasurement(VL53L0X_RangingMeasurementData_t *pRangingMeasurementData, boolean debug=false)
get a ranging measurement from the device
Definition: Adafruit_VL53L0X.cpp:331
VL53L0X_Error Status
Definition: Adafruit_VL53L0X.h:111
VL53L0X_Sense_config_t
Definition: Adafruit_VL53L0X.h:45
boolean waitRangeComplete(void)
Wait until Range operation has completed.
Definition: Adafruit_VL53L0X.cpp:760
VL53L0X_Error rangingTest(VL53L0X_RangingMeasurementData_t *pRangingMeasurementData, boolean debug=false)
get a ranging measurement from the device
Definition: Adafruit_VL53L0X.h:69
VL53L0X_Error startMeasurement(boolean debug=false)
Start the ranging measurement from the device.
Definition: Adafruit_VL53L0X.cpp:374
#define VL53L0X_I2C_ADDR
Default sensor I2C address.
Definition: Adafruit_VL53L0X.h:34
VL53L0X_Error stopMeasurement(boolean debug=false)
Stop ranging measurement from the device.
Definition: Adafruit_VL53L0X.cpp:395
uint8_t readRangeStatus(void)
Request ranging success/error message (retrieve after ranging)
Definition: Adafruit_VL53L0X.cpp:716
VL53L0X_Error getGpioConfig(VL53L0X_DeviceModes *pDeviceMode, VL53L0X_GpioFunctionality *pFunctionality, VL53L0X_InterruptPolarity *pPolarity, boolean debug=false)
Get current configuration for GPIO pin 0.
Definition: Adafruit_VL53L0X.cpp:602
VL53L0X_Error getLimitCheckCurrent(uint8_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent, boolean debug=false)
Stop ranging measurement from the device.
Definition: Adafruit_VL53L0X.cpp:418
FixPoint1616_t getLimitCheckValue(uint16_t LimitCheckId)
Get a specific limit check value.
Definition: Adafruit_VL53L0X.cpp:967
VL53L0X_Error getDeviceMode(VL53L0X_DeviceModes *pDeviceMode, boolean debug=false)
Get current new device mode.
Definition: Adafruit_VL53L0X.cpp:530
VL53L0X_Error clearInterruptMask(boolean debug=false)
Clear system interrupt condition.
Definition: Adafruit_VL53L0X.cpp:551
void printRangeStatus(VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
print a ranging measurement out via Serial.print in a human-readable format
Definition: Adafruit_VL53L0X.cpp:669
uint8_t getLimitCheckEnable(uint16_t LimitCheckId)
Get specific limit check enable state.
Definition: Adafruit_VL53L0X.cpp:936
boolean setLimitCheckEnable(uint16_t LimitCheckId, uint8_t LimitCheckEnable)
Enable/Disable a specific limit check.
Definition: Adafruit_VL53L0X.cpp:921
boolean configSensor(VL53L0X_Sense_config_t vl_config)
Configure the sensor for one of the ways the example ST sketches configure the sensors for different ...
Definition: Adafruit_VL53L0X.cpp:223