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
70  rangingTest(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
79  printRangeStatus(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) { return false; }
136 
137  boolean configSensor(VL53L0X_Sense_config_t vl_config);
138 
139  // Export some wrappers to internal setting functions
140  // that are used by the above helper function to allow
141  // more complete control.
142  boolean setMeasurementTimingBudgetMicroSeconds(uint32_t budget_us);
144 
145  boolean setVcselPulsePeriod(VL53L0X_VcselPeriod VcselPeriodType,
146  uint8_t VCSELPulsePeriod);
147 
148  uint8_t getVcselPulsePeriod(VL53L0X_VcselPeriod VcselPeriodType);
149 
150  boolean setLimitCheckEnable(uint16_t LimitCheckId, uint8_t LimitCheckEnable);
151  uint8_t getLimitCheckEnable(uint16_t LimitCheckId);
152  boolean setLimitCheckValue(uint16_t LimitCheckId,
153  FixPoint1616_t LimitCheckValue);
154  FixPoint1616_t getLimitCheckValue(uint16_t LimitCheckId);
155 
156 private:
157  VL53L0X_Dev_t MyDevice;
158  VL53L0X_Dev_t *pMyDevice = &MyDevice;
159  VL53L0X_DeviceInfo_t DeviceInfo;
160 
161  uint8_t _rangeStatus;
162 };
163 
164 #endif
boolean setVcselPulsePeriod(VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriod)
Sets the VCSEL pulse period.
Definition: Adafruit_VL53L0X.cpp:885
boolean setAddress(uint8_t newAddr)
Change the I2C address of the sensor.
Definition: Adafruit_VL53L0X.cpp:194
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:628
boolean startRange(void)
Start a range operation.
Definition: Adafruit_VL53L0X.cpp:723
boolean startRangeContinuous(uint16_t period_ms=50)
Start a continuous range operation.
Definition: Adafruit_VL53L0X.cpp:791
boolean isRangeComplete(void)
Checks to see if a range operation has completed.
Definition: Adafruit_VL53L0X.cpp:744
uint16_t readRangeResult(void)
Return the range in mm for the last operation.
Definition: Adafruit_VL53L0X.cpp:770
VL53L0X_Error setDeviceMode(VL53L0X_DeviceModes DeviceMode, boolean debug=false)
Set a new device mode.
Definition: Adafruit_VL53L0X.cpp:448
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:695
boolean setMeasurementTimingBudgetMicroSeconds(uint32_t budget_us)
Wrapper to ST library code to budget how long a measurement should take.
Definition: Adafruit_VL53L0X.cpp:856
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:57
void stopRangeContinuous(void)
Stop a continuous ranging operation.
Definition: Adafruit_VL53L0X.cpp:815
VL53L0X_Error getInterruptThresholds(FixPoint1616_t *pThresholdLow, FixPoint1616_t *pThresholdHigh, boolean debug=false)
Get high and low Interrupt thresholds.
Definition: Adafruit_VL53L0X.cpp:500
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:471
uint32_t getMeasurementTimingBudgetMicroSeconds(void)
Wrapper to ST library code to budget how long a measurement should take.
Definition: Adafruit_VL53L0X.cpp:868
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:572
VL53L0X_Error getSingleRangingMeasurement(VL53L0X_RangingMeasurementData_t *pRangingMeasurementData, boolean debug=false)
get a ranging measurement from the device
Definition: Adafruit_VL53L0X.cpp:328
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:757
VL53L0X_Error rangingTest(VL53L0X_RangingMeasurementData_t *pRangingMeasurementData, boolean debug=false)
get a ranging measurement from the device
Definition: Adafruit_VL53L0X.h:70
VL53L0X_Error startMeasurement(boolean debug=false)
Start the ranging measurement from the device.
Definition: Adafruit_VL53L0X.cpp:371
#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:392
uint8_t readRangeStatus(void)
Request ranging success/error message (retrieve after ranging)
Definition: Adafruit_VL53L0X.cpp:714
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:600
VL53L0X_Error getLimitCheckCurrent(uint8_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent, boolean debug=false)
Stop ranging measurement from the device.
Definition: Adafruit_VL53L0X.cpp:415
FixPoint1616_t getLimitCheckValue(uint16_t LimitCheckId)
Get a specific limit check value.
Definition: Adafruit_VL53L0X.cpp:968
VL53L0X_Error getDeviceMode(VL53L0X_DeviceModes *pDeviceMode, boolean debug=false)
Get current new device mode.
Definition: Adafruit_VL53L0X.cpp:528
VL53L0X_Error clearInterruptMask(boolean debug=false)
Clear system interrupt condition.
Definition: Adafruit_VL53L0X.cpp:549
void printRangeStatus(VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
print a ranging measurement out via Serial.print in a human-readable format
Definition: Adafruit_VL53L0X.cpp:667
uint8_t getLimitCheckEnable(uint16_t LimitCheckId)
Get specific limit check enable state.
Definition: Adafruit_VL53L0X.cpp:935
boolean setLimitCheckEnable(uint16_t LimitCheckId, uint8_t LimitCheckEnable)
Enable/Disable a specific limit check.
Definition: Adafruit_VL53L0X.cpp:920
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:222