├── .github
├── ISSUE_TEMPLATE
│ ├── bug-report-or-feature-request.md
│ └── config.yml
└── workflows
│ └── ci.yaml
├── .gitignore
├── .gitlab-ci.yml
├── LICENSE.txt
├── README.md
├── VL53L0X.cpp
├── VL53L0X.h
├── examples
├── Continuous
│ └── Continuous.ino
└── Single
│ └── Single.ino
├── keywords.txt
└── library.properties
/.github/ISSUE_TEMPLATE/bug-report-or-feature-request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report or feature request
3 | about: Did you find a specific bug in the code for this project? Do you want to request
4 | a new feature? Please open an issue!
5 | title: ''
6 | labels: ''
7 | assignees: ''
8 |
9 | ---
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: Pololu Forum
4 | url: https://forum.pololu.com/
5 | about: Do you need help getting started? Can't get this code to work at all? Having problems with electronics? Please post on our forum!
6 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: "CI"
2 | on:
3 | pull_request:
4 | push:
5 | jobs:
6 | ci:
7 | runs-on: ubuntu-20.04
8 | steps:
9 | - name: Checkout this repository
10 | uses: actions/checkout@v2.3.4
11 | - name: Cache for arduino-ci
12 | uses: actions/cache@v2.1.3
13 | with:
14 | path: |
15 | ~/.arduino15
16 | key: ${{ runner.os }}-arduino
17 | - name: Install nix
18 | uses: cachix/install-nix-action@v12
19 | - run: nix-shell -I nixpkgs=channel:nixpkgs-unstable -p arduino-ci --run "arduino-ci"
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /docs/
2 | /out/
3 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | image: $CI_REGISTRY_IMAGE/nixos/nix:2.3.6
2 |
3 | stages:
4 | - ci
5 |
6 | ci:
7 | stage: ci
8 | tags:
9 | - nix
10 | script:
11 | - nix-shell -I nixpkgs=channel:nixpkgs-unstable -p arduino-ci --run "arduino-ci"
12 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2017-2022 Pololu Corporation. For more information, see
2 |
3 | https://www.pololu.com/
4 | https://forum.pololu.com/
5 |
6 | Permission is hereby granted, free of charge, to any person
7 | obtaining a copy of this software and associated documentation
8 | files (the "Software"), to deal in the Software without
9 | restriction, including without limitation the rights to use,
10 | copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the
12 | Software is furnished to do so, subject to the following
13 | conditions:
14 |
15 | The above copyright notice and this permission notice shall be
16 | included in all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | OTHER DEALINGS IN THE SOFTWARE.
26 |
27 | =================================================================
28 |
29 | Most of the functionality of this library is based on the VL53L0X
30 | API provided by ST (STSW-IMG005), and some of the explanatory
31 | comments are quoted or paraphrased from the API source code, API
32 | user manual (UM2039), and the VL53L0X datasheet.
33 |
34 | The following applies to source code reproduced or derived from
35 | the API:
36 |
37 | -----------------------------------------------------------------
38 |
39 | Copyright © 2016, STMicroelectronics International N.V. All
40 | rights reserved.
41 |
42 | Redistribution and use in source and binary forms, with or
43 | without modification, are permitted provided that the following
44 | conditions are met:
45 | * Redistributions of source code must retain the above copyright
46 | notice, this list of conditions and the following disclaimer.
47 | * Redistributions in binary form must reproduce the above
48 | copyright notice, this list of conditions and the following
49 | disclaimer in the documentation and/or other materials provided
50 | with the distribution.
51 | * Neither the name of STMicroelectronics nor the
52 | names of its contributors may be used to endorse or promote
53 | products derived from this software without specific prior
54 | written permission.
55 |
56 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
57 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
58 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
59 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
60 | NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
61 | IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE
62 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
64 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
65 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
66 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
68 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
69 | DAMAGE.
70 |
71 | -----------------------------------------------------------------
72 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VL53L0X library for Arduino
2 | [www.pololu.com](https://www.pololu.com/)
3 |
4 | ## Summary
5 |
6 | This is a library for the Arduino IDE that helps interface with ST's [VL53L0X time-of-flight distance sensor](https://www.pololu.com/product/2490). The library makes it simple to configure the sensor and read range data from it via I²C.
7 |
8 | ## Supported platforms
9 |
10 | This library is designed to work with the Arduino IDE versions 1.6.x or later; we have not tested it with earlier versions. This library should support any Arduino-compatible board, including the [Pololu A-Star 32U4 controllers](https://www.pololu.com/category/149/a-star-programmable-controllers).
11 |
12 | ## Getting started
13 |
14 | ### Hardware
15 |
16 | A [VL53L0X carrier](https://www.pololu.com/product/2490) can be purchased from Pololu's website. Before continuing, careful reading of the [product page](https://www.pololu.com/product/2490) as well as the VL53L0X datasheet is recommended.
17 |
18 | Make the following connections between the Arduino and the VL53L0X board:
19 |
20 | #### 5V Arduino boards
21 |
22 | (including Arduino Uno, Leonardo, Mega; Pololu A-Star 32U4)
23 |
24 | Arduino VL53L0X board
25 | ------- -------------
26 | 5V - VIN
27 | GND - GND
28 | SDA - SDA
29 | SCL - SCL
30 |
31 | #### 3.3V Arduino boards
32 |
33 | (including Arduino Due)
34 |
35 | Arduino VL53L0X board
36 | ------- -------------
37 | 3V3 - VIN
38 | GND - GND
39 | SDA - SDA
40 | SCL - SCL
41 |
42 | ### Software
43 |
44 | If you are using version 1.6.2 or later of the [Arduino software (IDE)](http://www.arduino.cc/en/Main/Software), you can use the Library Manager to install this library:
45 |
46 | 1. In the Arduino IDE, open the "Sketch" menu, select "Include Library", then "Manage Libraries...".
47 | 2. Search for "VL53L0X".
48 | 3. Click the VL53L0X entry in the list.
49 | 4. Click "Install".
50 |
51 | If this does not work, you can manually install the library:
52 |
53 | 1. Download the [latest release archive from GitHub](https://github.com/pololu/vl53l0x-arduino/releases) and decompress it.
54 | 2. Rename the folder "vl53l0x-arduino-master" to "VL53L0X".
55 | 3. Move the "VL53L0X" folder into the "libraries" directory inside your Arduino sketchbook directory. You can view your sketchbook location by opening the "File" menu and selecting "Preferences" in the Arduino IDE. If there is not already a "libraries" folder in that location, you should make the folder yourself.
56 | 4. After installing the library, restart the Arduino IDE.
57 |
58 | ## Examples
59 |
60 | Several example sketches are available that show how to use the library. You can access them from the Arduino IDE by opening the "File" menu, selecting "Examples", and then selecting "VL53L0X". If you cannot find these examples, the library was probably installed incorrectly and you should retry the installation instructions above.
61 |
62 | ## ST's VL53L0X API and this library
63 |
64 | Most of the functionality of this library is based on the [VL53L0X API](http://www.st.com/content/st_com/en/products/embedded-software/proximity-sensors-software/stsw-img005.html) provided by ST (STSW-IMG005), and some of the explanatory comments in the code are quoted or paraphrased from the API source code, API user manual (UM2039), and the VL53L0X datasheet. For more explanation about the library code and how it was derived from the API, see the comments in VL53L0X.cpp.
65 |
66 | This library is intended to provide a quicker and easier way to get started using the VL53L0X with an Arduino-compatible controller, in contrast to customizing and compiling ST's API for the Arduino. The library has a more streamlined interface, as well as smaller storage and memory footprints. However, it does not implement some of the more advanced functionality available in the API (for example, calibrating the sensor to work well under a cover glass), and it has less robust error checking. For advanced applications, especially when storage and memory are less of an issue, consider using the VL53L0X API directly.
67 |
68 | ## Library reference
69 |
70 | * `uint8_t last_status`
71 | The status of the last I²C write transmission. See the [`Wire.endTransmission()` documentation](http://arduino.cc/en/Reference/WireEndTransmission) for return values.
72 |
73 | * `VL53L0X()`
74 | Constructor.
75 |
76 | * `void setBus(TwoWire * bus)`
77 | Configures this object to use the specified I²C bus. `bus` should be a pointer to a `TwoWire` object; the default bus is `Wire`, which is typically the first or only I²C bus on an Arduino. If your Arduino has more than one I²C bus and you have the VL53L0X connected to the second bus, which is typically called `Wire1`, you can call `sensor.setBus(&Wire1);`.
78 |
79 | * `TwoWire * getBus()`
80 | Returns a pointer to the I²C bus this object is using.
81 |
82 | * `void setAddress(uint8_t new_addr)`
83 | Changes the I²C slave device address of the VL53L0X to the given value (7-bit).
84 |
85 | * `uint8_t getAddress()`
86 | Returns the I²C address this object is using.
87 |
88 | * `bool init(bool io_2v8 = true)`
89 | Iniitializes and configures the sensor. If the optional argument `io_2v8` is true (the default if not specified), the sensor is configured for 2V8 mode (2.8 V I/O); if false, the sensor is left in 1V8 mode. The return value is a boolean indicating whether the initialization completed successfully.
90 |
91 | * `void writeReg(uint8_t reg, uint8_t value)`
92 | Writes an 8-bit sensor register with the given value.
93 |
94 | Register address constants are defined by the regAddr enumeration type in VL53L0X.h.
95 | Example use: `sensor.writeReg(VL53L0X::SYSRANGE_START, 0x01);`
96 |
97 | * `void writeReg16Bit(uint8_t reg, uint16_t value)`
98 | Writes a 16-bit sensor register with the given value.
99 |
100 | * `void writeReg32Bit(uint8_t reg, uint32_t value)`
101 | Writes a 32-bit sensor register with the given value.
102 |
103 | * `uint8_t readReg(uint8_t reg)`
104 | Reads an 8-bit sensor register and returns the value read.
105 |
106 | * `uint16_t readReg16Bit(uint8_t reg)`
107 | Reads a 16-bit sensor register and returns the value read.
108 |
109 | * `uint32_t readReg32Bit(uint8_t reg)`
110 | Reads a 32-bit sensor register and returns the value read.
111 |
112 | * `void writeMulti(uint8_t reg, uint8_t const * src, uint8_t count)`
113 | Writes an arbitrary number of bytes from the given array to the sensor, starting at the given register.
114 |
115 | * `void readMulti(uint8_t reg, uint8_t * dst, uint8_t count)`
116 | Reads an arbitrary number of bytes from the sensor, starting at the given register, into the given array.
117 |
118 | * `bool setSignalRateLimit(float limit_Mcps)`
119 | Sets the return signal rate limit to the given value in units of MCPS (mega counts per second). This is the minimum amplitude of the signal reflected from the target and received by the sensor necessary for it to report a valid reading. Setting a lower limit increases the potential range of the sensor but also increases the likelihood of getting an inaccurate reading because of reflections from objects other than the intended target. This limit is initialized to 0.25 MCPS by default. The return value is a boolean indicating whether the requested limit was valid.
120 |
121 | * `float getSignalRateLimit()`
122 | Returns the current return signal rate limit in MCPS.
123 |
124 | * `bool setMeasurementTimingBudget(uint32_t budget_us)`
125 | Sets the measurement timing budget to the given value in microseconds. This is the time allowed for one range measurement; a longer timing budget allows for more accurate measurements. The default budget is about 33000 microseconds, or 33 ms; the minimum is 20 ms. The return value is a boolean indicating whether the requested budget was valid.
126 |
127 | * `uint32_t getMeasurementTimingBudget()`
128 | Returns the current measurement timing budget in microseconds.
129 |
130 | * `bool setVcselPulsePeriod(vcselPeriodType type, uint8_t period_pclks)`
131 | Sets the VCSEL (vertical cavity surface emitting laser) pulse period for the given period type (`VL53L0X::VcselPeriodPreRange` or `VL53L0X::VcselPeriodFinalRange`) to the given value (in PCLKs). Longer periods increase the potential range of the sensor. Valid values are (even numbers only):
132 |
133 | Pre: 12 to 18 (initialized to 14 by default)
134 | Final: 8 to 14 (initialized to 10 by default)
135 |
136 | The return value is a boolean indicating whether the requested period was valid.
137 |
138 | * `uint8_t getVcselPulsePeriod(vcselPeriodType type)`
139 | Returns the current VCSEL pulse period for the given period type.
140 |
141 | * `void startContinuous(uint32_t period_ms = 0)`
142 | Starts continuous ranging measurements. If the optional argument `period_ms` is 0 (the default if not specified), continuous back-to-back mode is used (the sensor takes measurements as often as possible); if it is nonzero, continuous timed mode is used, with the specified inter-measurement period in milliseconds determining how often the sensor takes a measurement.
143 |
144 | * `void stopContinuous()`
145 | Stops continuous mode.
146 |
147 | * `uint16_t readRangeContinuousMillimeters()`
148 | Returns a range reading in millimeters when continuous mode is active.
149 |
150 | * `uint16_t readRangeSingleMillimeters()`
151 | Performs a single-shot ranging measurement and returns the reading in millimeters.
152 |
153 | * `void setTimeout(uint16_t timeout)`
154 | Sets a timeout period in milliseconds after which read operations will abort if the sensor is not ready. A value of 0 disables the timeout.
155 |
156 | * `uint16_t getTimeout()`
157 | Returns the current timeout period setting.
158 |
159 | * `bool timeoutOccurred()`
160 | Indicates whether a read timeout has occurred since the last call to `timeoutOccurred()`.
161 |
162 | ## Version history
163 |
164 | * 1.3.1 (2022-04-05): Explicitly cast `Wire.write()` arguments to `uint8_t`. Removed 20ms hard limit for timing budget to match API 1.0.4.
165 | * 1.3.0 (2020-09-24): Added support for alternative I²C buses (thanks KurtE).
166 | * 1.2.0 (2019-10-31): Incorporated some updates from ST's VL53L0X API version 1.0.2 (this library was originally based on API version 1.0.0).
167 | * 1.1.0 (2019-10-29): Improved `init()` and added a check for its return value in examples; fixed a few other issues.
168 | * 1.0.2 (2017-06-27): Fixed a typo in a register modification in `getSpadInfo()` (thanks @tridge).
169 | * 1.0.1 (2016-12-08): Fixed type error in `readReg32Bit()`.
170 | * 1.0.0 (2016-08-12): Original release.
171 |
--------------------------------------------------------------------------------
/VL53L0X.cpp:
--------------------------------------------------------------------------------
1 | // Most of the functionality of this library is based on the VL53L0X API
2 | // provided by ST (STSW-IMG005), and some of the explanatory comments are quoted
3 | // or paraphrased from the API source code, API user manual (UM2039), and the
4 | // VL53L0X datasheet.
5 |
6 | #include "VL53L0X.h"
7 | #include
8 |
9 | // Defines /////////////////////////////////////////////////////////////////////
10 |
11 | // The Arduino two-wire interface uses a 7-bit number for the address,
12 | // and sets the last bit correctly based on reads and writes
13 | #define ADDRESS_DEFAULT 0b0101001
14 |
15 | // Record the current time to check an upcoming timeout against
16 | #define startTimeout() (timeout_start_ms = millis())
17 |
18 | // Check if timeout is enabled (set to nonzero value) and has expired
19 | #define checkTimeoutExpired() (io_timeout > 0 && ((uint16_t)(millis() - timeout_start_ms) > io_timeout))
20 |
21 | // Decode VCSEL (vertical cavity surface emitting laser) pulse period in PCLKs
22 | // from register value
23 | // based on VL53L0X_decode_vcsel_period()
24 | #define decodeVcselPeriod(reg_val) (((reg_val) + 1) << 1)
25 |
26 | // Encode VCSEL pulse period register value from period in PCLKs
27 | // based on VL53L0X_encode_vcsel_period()
28 | #define encodeVcselPeriod(period_pclks) (((period_pclks) >> 1) - 1)
29 |
30 | // Calculate macro period in *nanoseconds* from VCSEL period in PCLKs
31 | // based on VL53L0X_calc_macro_period_ps()
32 | // PLL_period_ps = 1655; macro_period_vclks = 2304
33 | #define calcMacroPeriod(vcsel_period_pclks) ((((uint32_t)2304 * (vcsel_period_pclks) * 1655) + 500) / 1000)
34 |
35 | // Constructors ////////////////////////////////////////////////////////////////
36 |
37 | VL53L0X::VL53L0X()
38 | : bus(&Wire)
39 | , address(ADDRESS_DEFAULT)
40 | , io_timeout(0) // no timeout
41 | , did_timeout(false)
42 | {
43 | }
44 |
45 | // Public Methods //////////////////////////////////////////////////////////////
46 |
47 | void VL53L0X::setAddress(uint8_t new_addr)
48 | {
49 | writeReg(I2C_SLAVE_DEVICE_ADDRESS, new_addr & 0x7F);
50 | address = new_addr;
51 | }
52 |
53 | // Initialize sensor using sequence based on VL53L0X_DataInit(),
54 | // VL53L0X_StaticInit(), and VL53L0X_PerformRefCalibration().
55 | // This function does not perform reference SPAD calibration
56 | // (VL53L0X_PerformRefSpadManagement()), since the API user manual says that it
57 | // is performed by ST on the bare modules; it seems like that should work well
58 | // enough unless a cover glass is added.
59 | // If io_2v8 (optional) is true or not given, the sensor is configured for 2V8
60 | // mode.
61 | bool VL53L0X::init(bool io_2v8)
62 | {
63 | // check model ID register (value specified in datasheet)
64 | if (readReg(IDENTIFICATION_MODEL_ID) != 0xEE) { return false; }
65 |
66 | // VL53L0X_DataInit() begin
67 |
68 | // sensor uses 1V8 mode for I/O by default; switch to 2V8 mode if necessary
69 | if (io_2v8)
70 | {
71 | writeReg(VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV,
72 | readReg(VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV) | 0x01); // set bit 0
73 | }
74 |
75 | // "Set I2C standard mode"
76 | writeReg(0x88, 0x00);
77 |
78 | writeReg(0x80, 0x01);
79 | writeReg(0xFF, 0x01);
80 | writeReg(0x00, 0x00);
81 | stop_variable = readReg(0x91);
82 | writeReg(0x00, 0x01);
83 | writeReg(0xFF, 0x00);
84 | writeReg(0x80, 0x00);
85 |
86 | // disable SIGNAL_RATE_MSRC (bit 1) and SIGNAL_RATE_PRE_RANGE (bit 4) limit checks
87 | writeReg(MSRC_CONFIG_CONTROL, readReg(MSRC_CONFIG_CONTROL) | 0x12);
88 |
89 | // set final range signal rate limit to 0.25 MCPS (million counts per second)
90 | setSignalRateLimit(0.25);
91 |
92 | writeReg(SYSTEM_SEQUENCE_CONFIG, 0xFF);
93 |
94 | // VL53L0X_DataInit() end
95 |
96 | // VL53L0X_StaticInit() begin
97 |
98 | uint8_t spad_count;
99 | bool spad_type_is_aperture;
100 | if (!getSpadInfo(&spad_count, &spad_type_is_aperture)) { return false; }
101 |
102 | // The SPAD map (RefGoodSpadMap) is read by VL53L0X_get_info_from_device() in
103 | // the API, but the same data seems to be more easily readable from
104 | // GLOBAL_CONFIG_SPAD_ENABLES_REF_0 through _6, so read it from there
105 | uint8_t ref_spad_map[6];
106 | readMulti(GLOBAL_CONFIG_SPAD_ENABLES_REF_0, ref_spad_map, 6);
107 |
108 | // -- VL53L0X_set_reference_spads() begin (assume NVM values are valid)
109 |
110 | writeReg(0xFF, 0x01);
111 | writeReg(DYNAMIC_SPAD_REF_EN_START_OFFSET, 0x00);
112 | writeReg(DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD, 0x2C);
113 | writeReg(0xFF, 0x00);
114 | writeReg(GLOBAL_CONFIG_REF_EN_START_SELECT, 0xB4);
115 |
116 | uint8_t first_spad_to_enable = spad_type_is_aperture ? 12 : 0; // 12 is the first aperture spad
117 | uint8_t spads_enabled = 0;
118 |
119 | for (uint8_t i = 0; i < 48; i++)
120 | {
121 | if (i < first_spad_to_enable || spads_enabled == spad_count)
122 | {
123 | // This bit is lower than the first one that should be enabled, or
124 | // (reference_spad_count) bits have already been enabled, so zero this bit
125 | ref_spad_map[i / 8] &= ~(1 << (i % 8));
126 | }
127 | else if ((ref_spad_map[i / 8] >> (i % 8)) & 0x1)
128 | {
129 | spads_enabled++;
130 | }
131 | }
132 |
133 | writeMulti(GLOBAL_CONFIG_SPAD_ENABLES_REF_0, ref_spad_map, 6);
134 |
135 | // -- VL53L0X_set_reference_spads() end
136 |
137 | // -- VL53L0X_load_tuning_settings() begin
138 | // DefaultTuningSettings from vl53l0x_tuning.h
139 |
140 | writeReg(0xFF, 0x01);
141 | writeReg(0x00, 0x00);
142 |
143 | writeReg(0xFF, 0x00);
144 | writeReg(0x09, 0x00);
145 | writeReg(0x10, 0x00);
146 | writeReg(0x11, 0x00);
147 |
148 | writeReg(0x24, 0x01);
149 | writeReg(0x25, 0xFF);
150 | writeReg(0x75, 0x00);
151 |
152 | writeReg(0xFF, 0x01);
153 | writeReg(0x4E, 0x2C);
154 | writeReg(0x48, 0x00);
155 | writeReg(0x30, 0x20);
156 |
157 | writeReg(0xFF, 0x00);
158 | writeReg(0x30, 0x09);
159 | writeReg(0x54, 0x00);
160 | writeReg(0x31, 0x04);
161 | writeReg(0x32, 0x03);
162 | writeReg(0x40, 0x83);
163 | writeReg(0x46, 0x25);
164 | writeReg(0x60, 0x00);
165 | writeReg(0x27, 0x00);
166 | writeReg(0x50, 0x06);
167 | writeReg(0x51, 0x00);
168 | writeReg(0x52, 0x96);
169 | writeReg(0x56, 0x08);
170 | writeReg(0x57, 0x30);
171 | writeReg(0x61, 0x00);
172 | writeReg(0x62, 0x00);
173 | writeReg(0x64, 0x00);
174 | writeReg(0x65, 0x00);
175 | writeReg(0x66, 0xA0);
176 |
177 | writeReg(0xFF, 0x01);
178 | writeReg(0x22, 0x32);
179 | writeReg(0x47, 0x14);
180 | writeReg(0x49, 0xFF);
181 | writeReg(0x4A, 0x00);
182 |
183 | writeReg(0xFF, 0x00);
184 | writeReg(0x7A, 0x0A);
185 | writeReg(0x7B, 0x00);
186 | writeReg(0x78, 0x21);
187 |
188 | writeReg(0xFF, 0x01);
189 | writeReg(0x23, 0x34);
190 | writeReg(0x42, 0x00);
191 | writeReg(0x44, 0xFF);
192 | writeReg(0x45, 0x26);
193 | writeReg(0x46, 0x05);
194 | writeReg(0x40, 0x40);
195 | writeReg(0x0E, 0x06);
196 | writeReg(0x20, 0x1A);
197 | writeReg(0x43, 0x40);
198 |
199 | writeReg(0xFF, 0x00);
200 | writeReg(0x34, 0x03);
201 | writeReg(0x35, 0x44);
202 |
203 | writeReg(0xFF, 0x01);
204 | writeReg(0x31, 0x04);
205 | writeReg(0x4B, 0x09);
206 | writeReg(0x4C, 0x05);
207 | writeReg(0x4D, 0x04);
208 |
209 | writeReg(0xFF, 0x00);
210 | writeReg(0x44, 0x00);
211 | writeReg(0x45, 0x20);
212 | writeReg(0x47, 0x08);
213 | writeReg(0x48, 0x28);
214 | writeReg(0x67, 0x00);
215 | writeReg(0x70, 0x04);
216 | writeReg(0x71, 0x01);
217 | writeReg(0x72, 0xFE);
218 | writeReg(0x76, 0x00);
219 | writeReg(0x77, 0x00);
220 |
221 | writeReg(0xFF, 0x01);
222 | writeReg(0x0D, 0x01);
223 |
224 | writeReg(0xFF, 0x00);
225 | writeReg(0x80, 0x01);
226 | writeReg(0x01, 0xF8);
227 |
228 | writeReg(0xFF, 0x01);
229 | writeReg(0x8E, 0x01);
230 | writeReg(0x00, 0x01);
231 | writeReg(0xFF, 0x00);
232 | writeReg(0x80, 0x00);
233 |
234 | // -- VL53L0X_load_tuning_settings() end
235 |
236 | // "Set interrupt config to new sample ready"
237 | // -- VL53L0X_SetGpioConfig() begin
238 |
239 | writeReg(SYSTEM_INTERRUPT_CONFIG_GPIO, 0x04);
240 | writeReg(GPIO_HV_MUX_ACTIVE_HIGH, readReg(GPIO_HV_MUX_ACTIVE_HIGH) & ~0x10); // active low
241 | writeReg(SYSTEM_INTERRUPT_CLEAR, 0x01);
242 |
243 | // -- VL53L0X_SetGpioConfig() end
244 |
245 | measurement_timing_budget_us = getMeasurementTimingBudget();
246 |
247 | // "Disable MSRC and TCC by default"
248 | // MSRC = Minimum Signal Rate Check
249 | // TCC = Target CentreCheck
250 | // -- VL53L0X_SetSequenceStepEnable() begin
251 |
252 | writeReg(SYSTEM_SEQUENCE_CONFIG, 0xE8);
253 |
254 | // -- VL53L0X_SetSequenceStepEnable() end
255 |
256 | // "Recalculate timing budget"
257 | setMeasurementTimingBudget(measurement_timing_budget_us);
258 |
259 | // VL53L0X_StaticInit() end
260 |
261 | // VL53L0X_PerformRefCalibration() begin (VL53L0X_perform_ref_calibration())
262 |
263 | // -- VL53L0X_perform_vhv_calibration() begin
264 |
265 | writeReg(SYSTEM_SEQUENCE_CONFIG, 0x01);
266 | if (!performSingleRefCalibration(0x40)) { return false; }
267 |
268 | // -- VL53L0X_perform_vhv_calibration() end
269 |
270 | // -- VL53L0X_perform_phase_calibration() begin
271 |
272 | writeReg(SYSTEM_SEQUENCE_CONFIG, 0x02);
273 | if (!performSingleRefCalibration(0x00)) { return false; }
274 |
275 | // -- VL53L0X_perform_phase_calibration() end
276 |
277 | // "restore the previous Sequence Config"
278 | writeReg(SYSTEM_SEQUENCE_CONFIG, 0xE8);
279 |
280 | // VL53L0X_PerformRefCalibration() end
281 |
282 | return true;
283 | }
284 |
285 | // Write an 8-bit register
286 | void VL53L0X::writeReg(uint8_t reg, uint8_t value)
287 | {
288 | bus->beginTransmission(address);
289 | bus->write(reg);
290 | bus->write(value);
291 | last_status = bus->endTransmission();
292 | }
293 |
294 | // Write a 16-bit register
295 | void VL53L0X::writeReg16Bit(uint8_t reg, uint16_t value)
296 | {
297 | bus->beginTransmission(address);
298 | bus->write(reg);
299 | bus->write((uint8_t)(value >> 8)); // value high byte
300 | bus->write((uint8_t)(value)); // value low byte
301 | last_status = bus->endTransmission();
302 | }
303 |
304 | // Write a 32-bit register
305 | void VL53L0X::writeReg32Bit(uint8_t reg, uint32_t value)
306 | {
307 | bus->beginTransmission(address);
308 | bus->write(reg);
309 | bus->write((uint8_t)(value >> 24)); // value highest byte
310 | bus->write((uint8_t)(value >> 16));
311 | bus->write((uint8_t)(value >> 8));
312 | bus->write((uint8_t)(value)); // value lowest byte
313 | last_status = bus->endTransmission();
314 | }
315 |
316 | // Read an 8-bit register
317 | uint8_t VL53L0X::readReg(uint8_t reg)
318 | {
319 | uint8_t value;
320 |
321 | bus->beginTransmission(address);
322 | bus->write(reg);
323 | last_status = bus->endTransmission();
324 |
325 | bus->requestFrom(address, (uint8_t)1);
326 | value = bus->read();
327 |
328 | return value;
329 | }
330 |
331 | // Read a 16-bit register
332 | uint16_t VL53L0X::readReg16Bit(uint8_t reg)
333 | {
334 | uint16_t value;
335 |
336 | bus->beginTransmission(address);
337 | bus->write(reg);
338 | last_status = bus->endTransmission();
339 |
340 | bus->requestFrom(address, (uint8_t)2);
341 | value = (uint16_t)bus->read() << 8; // value high byte
342 | value |= bus->read(); // value low byte
343 |
344 | return value;
345 | }
346 |
347 | // Read a 32-bit register
348 | uint32_t VL53L0X::readReg32Bit(uint8_t reg)
349 | {
350 | uint32_t value;
351 |
352 | bus->beginTransmission(address);
353 | bus->write(reg);
354 | last_status = bus->endTransmission();
355 |
356 | bus->requestFrom(address, (uint8_t)4);
357 | value = (uint32_t)bus->read() << 24; // value highest byte
358 | value |= (uint32_t)bus->read() << 16;
359 | value |= (uint16_t)bus->read() << 8;
360 | value |= bus->read(); // value lowest byte
361 |
362 | return value;
363 | }
364 |
365 | // Write an arbitrary number of bytes from the given array to the sensor,
366 | // starting at the given register
367 | void VL53L0X::writeMulti(uint8_t reg, uint8_t const * src, uint8_t count)
368 | {
369 | bus->beginTransmission(address);
370 | bus->write(reg);
371 |
372 | while (count-- > 0)
373 | {
374 | bus->write(*(src++));
375 | }
376 |
377 | last_status = bus->endTransmission();
378 | }
379 |
380 | // Read an arbitrary number of bytes from the sensor, starting at the given
381 | // register, into the given array
382 | void VL53L0X::readMulti(uint8_t reg, uint8_t * dst, uint8_t count)
383 | {
384 | bus->beginTransmission(address);
385 | bus->write(reg);
386 | last_status = bus->endTransmission();
387 |
388 | bus->requestFrom(address, count);
389 |
390 | while (count-- > 0)
391 | {
392 | *(dst++) = bus->read();
393 | }
394 | }
395 |
396 | // Set the return signal rate limit check value in units of MCPS (mega counts
397 | // per second). "This represents the amplitude of the signal reflected from the
398 | // target and detected by the device"; setting this limit presumably determines
399 | // the minimum measurement necessary for the sensor to report a valid reading.
400 | // Setting a lower limit increases the potential range of the sensor but also
401 | // seems to increase the likelihood of getting an inaccurate reading because of
402 | // unwanted reflections from objects other than the intended target.
403 | // Defaults to 0.25 MCPS as initialized by the ST API and this library.
404 | bool VL53L0X::setSignalRateLimit(float limit_Mcps)
405 | {
406 | if (limit_Mcps < 0 || limit_Mcps > 511.99) { return false; }
407 |
408 | // Q9.7 fixed point format (9 integer bits, 7 fractional bits)
409 | writeReg16Bit(FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT, limit_Mcps * (1 << 7));
410 | return true;
411 | }
412 |
413 | // Get the return signal rate limit check value in MCPS
414 | float VL53L0X::getSignalRateLimit()
415 | {
416 | return (float)readReg16Bit(FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT) / (1 << 7);
417 | }
418 |
419 | // Set the measurement timing budget in microseconds, which is the time allowed
420 | // for one measurement; the ST API and this library take care of splitting the
421 | // timing budget among the sub-steps in the ranging sequence. A longer timing
422 | // budget allows for more accurate measurements. Increasing the budget by a
423 | // factor of N decreases the range measurement standard deviation by a factor of
424 | // sqrt(N). Defaults to about 33 milliseconds; the minimum is 20 ms.
425 | // based on VL53L0X_set_measurement_timing_budget_micro_seconds()
426 | bool VL53L0X::setMeasurementTimingBudget(uint32_t budget_us)
427 | {
428 | SequenceStepEnables enables;
429 | SequenceStepTimeouts timeouts;
430 |
431 | uint16_t const StartOverhead = 1910;
432 | uint16_t const EndOverhead = 960;
433 | uint16_t const MsrcOverhead = 660;
434 | uint16_t const TccOverhead = 590;
435 | uint16_t const DssOverhead = 690;
436 | uint16_t const PreRangeOverhead = 660;
437 | uint16_t const FinalRangeOverhead = 550;
438 |
439 | uint32_t used_budget_us = StartOverhead + EndOverhead;
440 |
441 | getSequenceStepEnables(&enables);
442 | getSequenceStepTimeouts(&enables, &timeouts);
443 |
444 | if (enables.tcc)
445 | {
446 | used_budget_us += (timeouts.msrc_dss_tcc_us + TccOverhead);
447 | }
448 |
449 | if (enables.dss)
450 | {
451 | used_budget_us += 2 * (timeouts.msrc_dss_tcc_us + DssOverhead);
452 | }
453 | else if (enables.msrc)
454 | {
455 | used_budget_us += (timeouts.msrc_dss_tcc_us + MsrcOverhead);
456 | }
457 |
458 | if (enables.pre_range)
459 | {
460 | used_budget_us += (timeouts.pre_range_us + PreRangeOverhead);
461 | }
462 |
463 | if (enables.final_range)
464 | {
465 | used_budget_us += FinalRangeOverhead;
466 |
467 | // "Note that the final range timeout is determined by the timing
468 | // budget and the sum of all other timeouts within the sequence.
469 | // If there is no room for the final range timeout, then an error
470 | // will be set. Otherwise the remaining time will be applied to
471 | // the final range."
472 |
473 | if (used_budget_us > budget_us)
474 | {
475 | // "Requested timeout too big."
476 | return false;
477 | }
478 |
479 | uint32_t final_range_timeout_us = budget_us - used_budget_us;
480 |
481 | // set_sequence_step_timeout() begin
482 | // (SequenceStepId == VL53L0X_SEQUENCESTEP_FINAL_RANGE)
483 |
484 | // "For the final range timeout, the pre-range timeout
485 | // must be added. To do this both final and pre-range
486 | // timeouts must be expressed in macro periods MClks
487 | // because they have different vcsel periods."
488 |
489 | uint32_t final_range_timeout_mclks =
490 | timeoutMicrosecondsToMclks(final_range_timeout_us,
491 | timeouts.final_range_vcsel_period_pclks);
492 |
493 | if (enables.pre_range)
494 | {
495 | final_range_timeout_mclks += timeouts.pre_range_mclks;
496 | }
497 |
498 | writeReg16Bit(FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
499 | encodeTimeout(final_range_timeout_mclks));
500 |
501 | // set_sequence_step_timeout() end
502 |
503 | measurement_timing_budget_us = budget_us; // store for internal reuse
504 | }
505 | return true;
506 | }
507 |
508 | // Get the measurement timing budget in microseconds
509 | // based on VL53L0X_get_measurement_timing_budget_micro_seconds()
510 | // in us
511 | uint32_t VL53L0X::getMeasurementTimingBudget()
512 | {
513 | SequenceStepEnables enables;
514 | SequenceStepTimeouts timeouts;
515 |
516 | uint16_t const StartOverhead = 1910;
517 | uint16_t const EndOverhead = 960;
518 | uint16_t const MsrcOverhead = 660;
519 | uint16_t const TccOverhead = 590;
520 | uint16_t const DssOverhead = 690;
521 | uint16_t const PreRangeOverhead = 660;
522 | uint16_t const FinalRangeOverhead = 550;
523 |
524 | // "Start and end overhead times always present"
525 | uint32_t budget_us = StartOverhead + EndOverhead;
526 |
527 | getSequenceStepEnables(&enables);
528 | getSequenceStepTimeouts(&enables, &timeouts);
529 |
530 | if (enables.tcc)
531 | {
532 | budget_us += (timeouts.msrc_dss_tcc_us + TccOverhead);
533 | }
534 |
535 | if (enables.dss)
536 | {
537 | budget_us += 2 * (timeouts.msrc_dss_tcc_us + DssOverhead);
538 | }
539 | else if (enables.msrc)
540 | {
541 | budget_us += (timeouts.msrc_dss_tcc_us + MsrcOverhead);
542 | }
543 |
544 | if (enables.pre_range)
545 | {
546 | budget_us += (timeouts.pre_range_us + PreRangeOverhead);
547 | }
548 |
549 | if (enables.final_range)
550 | {
551 | budget_us += (timeouts.final_range_us + FinalRangeOverhead);
552 | }
553 |
554 | measurement_timing_budget_us = budget_us; // store for internal reuse
555 | return budget_us;
556 | }
557 |
558 | // Set the VCSEL (vertical cavity surface emitting laser) pulse period for the
559 | // given period type (pre-range or final range) to the given value in PCLKs.
560 | // Longer periods seem to increase the potential range of the sensor.
561 | // Valid values are (even numbers only):
562 | // pre: 12 to 18 (initialized default: 14)
563 | // final: 8 to 14 (initialized default: 10)
564 | // based on VL53L0X_set_vcsel_pulse_period()
565 | bool VL53L0X::setVcselPulsePeriod(vcselPeriodType type, uint8_t period_pclks)
566 | {
567 | uint8_t vcsel_period_reg = encodeVcselPeriod(period_pclks);
568 |
569 | SequenceStepEnables enables;
570 | SequenceStepTimeouts timeouts;
571 |
572 | getSequenceStepEnables(&enables);
573 | getSequenceStepTimeouts(&enables, &timeouts);
574 |
575 | // "Apply specific settings for the requested clock period"
576 | // "Re-calculate and apply timeouts, in macro periods"
577 |
578 | // "When the VCSEL period for the pre or final range is changed,
579 | // the corresponding timeout must be read from the device using
580 | // the current VCSEL period, then the new VCSEL period can be
581 | // applied. The timeout then must be written back to the device
582 | // using the new VCSEL period.
583 | //
584 | // For the MSRC timeout, the same applies - this timeout being
585 | // dependant on the pre-range vcsel period."
586 |
587 |
588 | if (type == VcselPeriodPreRange)
589 | {
590 | // "Set phase check limits"
591 | switch (period_pclks)
592 | {
593 | case 12:
594 | writeReg(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x18);
595 | break;
596 |
597 | case 14:
598 | writeReg(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x30);
599 | break;
600 |
601 | case 16:
602 | writeReg(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x40);
603 | break;
604 |
605 | case 18:
606 | writeReg(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x50);
607 | break;
608 |
609 | default:
610 | // invalid period
611 | return false;
612 | }
613 | writeReg(PRE_RANGE_CONFIG_VALID_PHASE_LOW, 0x08);
614 |
615 | // apply new VCSEL period
616 | writeReg(PRE_RANGE_CONFIG_VCSEL_PERIOD, vcsel_period_reg);
617 |
618 | // update timeouts
619 |
620 | // set_sequence_step_timeout() begin
621 | // (SequenceStepId == VL53L0X_SEQUENCESTEP_PRE_RANGE)
622 |
623 | uint16_t new_pre_range_timeout_mclks =
624 | timeoutMicrosecondsToMclks(timeouts.pre_range_us, period_pclks);
625 |
626 | writeReg16Bit(PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
627 | encodeTimeout(new_pre_range_timeout_mclks));
628 |
629 | // set_sequence_step_timeout() end
630 |
631 | // set_sequence_step_timeout() begin
632 | // (SequenceStepId == VL53L0X_SEQUENCESTEP_MSRC)
633 |
634 | uint16_t new_msrc_timeout_mclks =
635 | timeoutMicrosecondsToMclks(timeouts.msrc_dss_tcc_us, period_pclks);
636 |
637 | writeReg(MSRC_CONFIG_TIMEOUT_MACROP,
638 | (new_msrc_timeout_mclks > 256) ? 255 : (new_msrc_timeout_mclks - 1));
639 |
640 | // set_sequence_step_timeout() end
641 | }
642 | else if (type == VcselPeriodFinalRange)
643 | {
644 | switch (period_pclks)
645 | {
646 | case 8:
647 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x10);
648 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08);
649 | writeReg(GLOBAL_CONFIG_VCSEL_WIDTH, 0x02);
650 | writeReg(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x0C);
651 | writeReg(0xFF, 0x01);
652 | writeReg(ALGO_PHASECAL_LIM, 0x30);
653 | writeReg(0xFF, 0x00);
654 | break;
655 |
656 | case 10:
657 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x28);
658 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08);
659 | writeReg(GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
660 | writeReg(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x09);
661 | writeReg(0xFF, 0x01);
662 | writeReg(ALGO_PHASECAL_LIM, 0x20);
663 | writeReg(0xFF, 0x00);
664 | break;
665 |
666 | case 12:
667 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x38);
668 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08);
669 | writeReg(GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
670 | writeReg(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x08);
671 | writeReg(0xFF, 0x01);
672 | writeReg(ALGO_PHASECAL_LIM, 0x20);
673 | writeReg(0xFF, 0x00);
674 | break;
675 |
676 | case 14:
677 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x48);
678 | writeReg(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08);
679 | writeReg(GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
680 | writeReg(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x07);
681 | writeReg(0xFF, 0x01);
682 | writeReg(ALGO_PHASECAL_LIM, 0x20);
683 | writeReg(0xFF, 0x00);
684 | break;
685 |
686 | default:
687 | // invalid period
688 | return false;
689 | }
690 |
691 | // apply new VCSEL period
692 | writeReg(FINAL_RANGE_CONFIG_VCSEL_PERIOD, vcsel_period_reg);
693 |
694 | // update timeouts
695 |
696 | // set_sequence_step_timeout() begin
697 | // (SequenceStepId == VL53L0X_SEQUENCESTEP_FINAL_RANGE)
698 |
699 | // "For the final range timeout, the pre-range timeout
700 | // must be added. To do this both final and pre-range
701 | // timeouts must be expressed in macro periods MClks
702 | // because they have different vcsel periods."
703 |
704 | uint16_t new_final_range_timeout_mclks =
705 | timeoutMicrosecondsToMclks(timeouts.final_range_us, period_pclks);
706 |
707 | if (enables.pre_range)
708 | {
709 | new_final_range_timeout_mclks += timeouts.pre_range_mclks;
710 | }
711 |
712 | writeReg16Bit(FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
713 | encodeTimeout(new_final_range_timeout_mclks));
714 |
715 | // set_sequence_step_timeout end
716 | }
717 | else
718 | {
719 | // invalid type
720 | return false;
721 | }
722 |
723 | // "Finally, the timing budget must be re-applied"
724 |
725 | setMeasurementTimingBudget(measurement_timing_budget_us);
726 |
727 | // "Perform the phase calibration. This is needed after changing on vcsel period."
728 | // VL53L0X_perform_phase_calibration() begin
729 |
730 | uint8_t sequence_config = readReg(SYSTEM_SEQUENCE_CONFIG);
731 | writeReg(SYSTEM_SEQUENCE_CONFIG, 0x02);
732 | performSingleRefCalibration(0x0);
733 | writeReg(SYSTEM_SEQUENCE_CONFIG, sequence_config);
734 |
735 | // VL53L0X_perform_phase_calibration() end
736 |
737 | return true;
738 | }
739 |
740 | // Get the VCSEL pulse period in PCLKs for the given period type.
741 | // based on VL53L0X_get_vcsel_pulse_period()
742 | uint8_t VL53L0X::getVcselPulsePeriod(vcselPeriodType type)
743 | {
744 | if (type == VcselPeriodPreRange)
745 | {
746 | return decodeVcselPeriod(readReg(PRE_RANGE_CONFIG_VCSEL_PERIOD));
747 | }
748 | else if (type == VcselPeriodFinalRange)
749 | {
750 | return decodeVcselPeriod(readReg(FINAL_RANGE_CONFIG_VCSEL_PERIOD));
751 | }
752 | else { return 255; }
753 | }
754 |
755 | // Start continuous ranging measurements. If period_ms (optional) is 0 or not
756 | // given, continuous back-to-back mode is used (the sensor takes measurements as
757 | // often as possible); otherwise, continuous timed mode is used, with the given
758 | // inter-measurement period in milliseconds determining how often the sensor
759 | // takes a measurement.
760 | // based on VL53L0X_StartMeasurement()
761 | void VL53L0X::startContinuous(uint32_t period_ms)
762 | {
763 | writeReg(0x80, 0x01);
764 | writeReg(0xFF, 0x01);
765 | writeReg(0x00, 0x00);
766 | writeReg(0x91, stop_variable);
767 | writeReg(0x00, 0x01);
768 | writeReg(0xFF, 0x00);
769 | writeReg(0x80, 0x00);
770 |
771 | if (period_ms != 0)
772 | {
773 | // continuous timed mode
774 |
775 | // VL53L0X_SetInterMeasurementPeriodMilliSeconds() begin
776 |
777 | uint16_t osc_calibrate_val = readReg16Bit(OSC_CALIBRATE_VAL);
778 |
779 | if (osc_calibrate_val != 0)
780 | {
781 | period_ms *= osc_calibrate_val;
782 | }
783 |
784 | writeReg32Bit(SYSTEM_INTERMEASUREMENT_PERIOD, period_ms);
785 |
786 | // VL53L0X_SetInterMeasurementPeriodMilliSeconds() end
787 |
788 | writeReg(SYSRANGE_START, 0x04); // VL53L0X_REG_SYSRANGE_MODE_TIMED
789 | }
790 | else
791 | {
792 | // continuous back-to-back mode
793 | writeReg(SYSRANGE_START, 0x02); // VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK
794 | }
795 | }
796 |
797 | // Stop continuous measurements
798 | // based on VL53L0X_StopMeasurement()
799 | void VL53L0X::stopContinuous()
800 | {
801 | writeReg(SYSRANGE_START, 0x01); // VL53L0X_REG_SYSRANGE_MODE_SINGLESHOT
802 |
803 | writeReg(0xFF, 0x01);
804 | writeReg(0x00, 0x00);
805 | writeReg(0x91, 0x00);
806 | writeReg(0x00, 0x01);
807 | writeReg(0xFF, 0x00);
808 | }
809 |
810 | // Returns a range reading in millimeters when continuous mode is active
811 | // (readRangeSingleMillimeters() also calls this function after starting a
812 | // single-shot range measurement)
813 | uint16_t VL53L0X::readRangeContinuousMillimeters()
814 | {
815 | startTimeout();
816 | while ((readReg(RESULT_INTERRUPT_STATUS) & 0x07) == 0)
817 | {
818 | if (checkTimeoutExpired())
819 | {
820 | did_timeout = true;
821 | return 65535;
822 | }
823 | }
824 |
825 | // assumptions: Linearity Corrective Gain is 1000 (default);
826 | // fractional ranging is not enabled
827 | uint16_t range = readReg16Bit(RESULT_RANGE_STATUS + 10);
828 |
829 | writeReg(SYSTEM_INTERRUPT_CLEAR, 0x01);
830 |
831 | return range;
832 | }
833 |
834 | // Performs a single-shot range measurement and returns the reading in
835 | // millimeters
836 | // based on VL53L0X_PerformSingleRangingMeasurement()
837 | uint16_t VL53L0X::readRangeSingleMillimeters()
838 | {
839 | writeReg(0x80, 0x01);
840 | writeReg(0xFF, 0x01);
841 | writeReg(0x00, 0x00);
842 | writeReg(0x91, stop_variable);
843 | writeReg(0x00, 0x01);
844 | writeReg(0xFF, 0x00);
845 | writeReg(0x80, 0x00);
846 |
847 | writeReg(SYSRANGE_START, 0x01);
848 |
849 | // "Wait until start bit has been cleared"
850 | startTimeout();
851 | while (readReg(SYSRANGE_START) & 0x01)
852 | {
853 | if (checkTimeoutExpired())
854 | {
855 | did_timeout = true;
856 | return 65535;
857 | }
858 | }
859 |
860 | return readRangeContinuousMillimeters();
861 | }
862 |
863 | // Did a timeout occur in one of the read functions since the last call to
864 | // timeoutOccurred()?
865 | bool VL53L0X::timeoutOccurred()
866 | {
867 | bool tmp = did_timeout;
868 | did_timeout = false;
869 | return tmp;
870 | }
871 |
872 | // Private Methods /////////////////////////////////////////////////////////////
873 |
874 | // Get reference SPAD (single photon avalanche diode) count and type
875 | // based on VL53L0X_get_info_from_device(),
876 | // but only gets reference SPAD count and type
877 | bool VL53L0X::getSpadInfo(uint8_t * count, bool * type_is_aperture)
878 | {
879 | uint8_t tmp;
880 |
881 | writeReg(0x80, 0x01);
882 | writeReg(0xFF, 0x01);
883 | writeReg(0x00, 0x00);
884 |
885 | writeReg(0xFF, 0x06);
886 | writeReg(0x83, readReg(0x83) | 0x04);
887 | writeReg(0xFF, 0x07);
888 | writeReg(0x81, 0x01);
889 |
890 | writeReg(0x80, 0x01);
891 |
892 | writeReg(0x94, 0x6b);
893 | writeReg(0x83, 0x00);
894 | startTimeout();
895 | while (readReg(0x83) == 0x00)
896 | {
897 | if (checkTimeoutExpired()) { return false; }
898 | }
899 | writeReg(0x83, 0x01);
900 | tmp = readReg(0x92);
901 |
902 | *count = tmp & 0x7f;
903 | *type_is_aperture = (tmp >> 7) & 0x01;
904 |
905 | writeReg(0x81, 0x00);
906 | writeReg(0xFF, 0x06);
907 | writeReg(0x83, readReg(0x83) & ~0x04);
908 | writeReg(0xFF, 0x01);
909 | writeReg(0x00, 0x01);
910 |
911 | writeReg(0xFF, 0x00);
912 | writeReg(0x80, 0x00);
913 |
914 | return true;
915 | }
916 |
917 | // Get sequence step enables
918 | // based on VL53L0X_GetSequenceStepEnables()
919 | void VL53L0X::getSequenceStepEnables(SequenceStepEnables * enables)
920 | {
921 | uint8_t sequence_config = readReg(SYSTEM_SEQUENCE_CONFIG);
922 |
923 | enables->tcc = (sequence_config >> 4) & 0x1;
924 | enables->dss = (sequence_config >> 3) & 0x1;
925 | enables->msrc = (sequence_config >> 2) & 0x1;
926 | enables->pre_range = (sequence_config >> 6) & 0x1;
927 | enables->final_range = (sequence_config >> 7) & 0x1;
928 | }
929 |
930 | // Get sequence step timeouts
931 | // based on get_sequence_step_timeout(),
932 | // but gets all timeouts instead of just the requested one, and also stores
933 | // intermediate values
934 | void VL53L0X::getSequenceStepTimeouts(SequenceStepEnables const * enables, SequenceStepTimeouts * timeouts)
935 | {
936 | timeouts->pre_range_vcsel_period_pclks = getVcselPulsePeriod(VcselPeriodPreRange);
937 |
938 | timeouts->msrc_dss_tcc_mclks = readReg(MSRC_CONFIG_TIMEOUT_MACROP) + 1;
939 | timeouts->msrc_dss_tcc_us =
940 | timeoutMclksToMicroseconds(timeouts->msrc_dss_tcc_mclks,
941 | timeouts->pre_range_vcsel_period_pclks);
942 |
943 | timeouts->pre_range_mclks =
944 | decodeTimeout(readReg16Bit(PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI));
945 | timeouts->pre_range_us =
946 | timeoutMclksToMicroseconds(timeouts->pre_range_mclks,
947 | timeouts->pre_range_vcsel_period_pclks);
948 |
949 | timeouts->final_range_vcsel_period_pclks = getVcselPulsePeriod(VcselPeriodFinalRange);
950 |
951 | timeouts->final_range_mclks =
952 | decodeTimeout(readReg16Bit(FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI));
953 |
954 | if (enables->pre_range)
955 | {
956 | timeouts->final_range_mclks -= timeouts->pre_range_mclks;
957 | }
958 |
959 | timeouts->final_range_us =
960 | timeoutMclksToMicroseconds(timeouts->final_range_mclks,
961 | timeouts->final_range_vcsel_period_pclks);
962 | }
963 |
964 | // Decode sequence step timeout in MCLKs from register value
965 | // based on VL53L0X_decode_timeout()
966 | // Note: the original function returned a uint32_t, but the return value is
967 | // always stored in a uint16_t.
968 | uint16_t VL53L0X::decodeTimeout(uint16_t reg_val)
969 | {
970 | // format: "(LSByte * 2^MSByte) + 1"
971 | return (uint16_t)((reg_val & 0x00FF) <<
972 | (uint16_t)((reg_val & 0xFF00) >> 8)) + 1;
973 | }
974 |
975 | // Encode sequence step timeout register value from timeout in MCLKs
976 | // based on VL53L0X_encode_timeout()
977 | uint16_t VL53L0X::encodeTimeout(uint32_t timeout_mclks)
978 | {
979 | // format: "(LSByte * 2^MSByte) + 1"
980 |
981 | uint32_t ls_byte = 0;
982 | uint16_t ms_byte = 0;
983 |
984 | if (timeout_mclks > 0)
985 | {
986 | ls_byte = timeout_mclks - 1;
987 |
988 | while ((ls_byte & 0xFFFFFF00) > 0)
989 | {
990 | ls_byte >>= 1;
991 | ms_byte++;
992 | }
993 |
994 | return (ms_byte << 8) | (ls_byte & 0xFF);
995 | }
996 | else { return 0; }
997 | }
998 |
999 | // Convert sequence step timeout from MCLKs to microseconds with given VCSEL period in PCLKs
1000 | // based on VL53L0X_calc_timeout_us()
1001 | uint32_t VL53L0X::timeoutMclksToMicroseconds(uint16_t timeout_period_mclks, uint8_t vcsel_period_pclks)
1002 | {
1003 | uint32_t macro_period_ns = calcMacroPeriod(vcsel_period_pclks);
1004 |
1005 | return ((timeout_period_mclks * macro_period_ns) + 500) / 1000;
1006 | }
1007 |
1008 | // Convert sequence step timeout from microseconds to MCLKs with given VCSEL period in PCLKs
1009 | // based on VL53L0X_calc_timeout_mclks()
1010 | uint32_t VL53L0X::timeoutMicrosecondsToMclks(uint32_t timeout_period_us, uint8_t vcsel_period_pclks)
1011 | {
1012 | uint32_t macro_period_ns = calcMacroPeriod(vcsel_period_pclks);
1013 |
1014 | return (((timeout_period_us * 1000) + (macro_period_ns / 2)) / macro_period_ns);
1015 | }
1016 |
1017 |
1018 | // based on VL53L0X_perform_single_ref_calibration()
1019 | bool VL53L0X::performSingleRefCalibration(uint8_t vhv_init_byte)
1020 | {
1021 | writeReg(SYSRANGE_START, 0x01 | vhv_init_byte); // VL53L0X_REG_SYSRANGE_MODE_START_STOP
1022 |
1023 | startTimeout();
1024 | while ((readReg(RESULT_INTERRUPT_STATUS) & 0x07) == 0)
1025 | {
1026 | if (checkTimeoutExpired()) { return false; }
1027 | }
1028 |
1029 | writeReg(SYSTEM_INTERRUPT_CLEAR, 0x01);
1030 |
1031 | writeReg(SYSRANGE_START, 0x00);
1032 |
1033 | return true;
1034 | }
1035 |
--------------------------------------------------------------------------------
/VL53L0X.h:
--------------------------------------------------------------------------------
1 | #ifndef VL53L0X_h
2 | #define VL53L0X_h
3 |
4 | #include
5 | #include
6 |
7 | class VL53L0X
8 | {
9 | public:
10 | // register addresses from API vl53l0x_device.h (ordered as listed there)
11 | enum regAddr
12 | {
13 | SYSRANGE_START = 0x00,
14 |
15 | SYSTEM_THRESH_HIGH = 0x0C,
16 | SYSTEM_THRESH_LOW = 0x0E,
17 |
18 | SYSTEM_SEQUENCE_CONFIG = 0x01,
19 | SYSTEM_RANGE_CONFIG = 0x09,
20 | SYSTEM_INTERMEASUREMENT_PERIOD = 0x04,
21 |
22 | SYSTEM_INTERRUPT_CONFIG_GPIO = 0x0A,
23 |
24 | GPIO_HV_MUX_ACTIVE_HIGH = 0x84,
25 |
26 | SYSTEM_INTERRUPT_CLEAR = 0x0B,
27 |
28 | RESULT_INTERRUPT_STATUS = 0x13,
29 | RESULT_RANGE_STATUS = 0x14,
30 |
31 | RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN = 0xBC,
32 | RESULT_CORE_RANGING_TOTAL_EVENTS_RTN = 0xC0,
33 | RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF = 0xD0,
34 | RESULT_CORE_RANGING_TOTAL_EVENTS_REF = 0xD4,
35 | RESULT_PEAK_SIGNAL_RATE_REF = 0xB6,
36 |
37 | ALGO_PART_TO_PART_RANGE_OFFSET_MM = 0x28,
38 |
39 | I2C_SLAVE_DEVICE_ADDRESS = 0x8A,
40 |
41 | MSRC_CONFIG_CONTROL = 0x60,
42 |
43 | PRE_RANGE_CONFIG_MIN_SNR = 0x27,
44 | PRE_RANGE_CONFIG_VALID_PHASE_LOW = 0x56,
45 | PRE_RANGE_CONFIG_VALID_PHASE_HIGH = 0x57,
46 | PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT = 0x64,
47 |
48 | FINAL_RANGE_CONFIG_MIN_SNR = 0x67,
49 | FINAL_RANGE_CONFIG_VALID_PHASE_LOW = 0x47,
50 | FINAL_RANGE_CONFIG_VALID_PHASE_HIGH = 0x48,
51 | FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT = 0x44,
52 |
53 | PRE_RANGE_CONFIG_SIGMA_THRESH_HI = 0x61,
54 | PRE_RANGE_CONFIG_SIGMA_THRESH_LO = 0x62,
55 |
56 | PRE_RANGE_CONFIG_VCSEL_PERIOD = 0x50,
57 | PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x51,
58 | PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x52,
59 |
60 | SYSTEM_HISTOGRAM_BIN = 0x81,
61 | HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT = 0x33,
62 | HISTOGRAM_CONFIG_READOUT_CTRL = 0x55,
63 |
64 | FINAL_RANGE_CONFIG_VCSEL_PERIOD = 0x70,
65 | FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x71,
66 | FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x72,
67 | CROSSTALK_COMPENSATION_PEAK_RATE_MCPS = 0x20,
68 |
69 | MSRC_CONFIG_TIMEOUT_MACROP = 0x46,
70 |
71 | SOFT_RESET_GO2_SOFT_RESET_N = 0xBF,
72 | IDENTIFICATION_MODEL_ID = 0xC0,
73 | IDENTIFICATION_REVISION_ID = 0xC2,
74 |
75 | OSC_CALIBRATE_VAL = 0xF8,
76 |
77 | GLOBAL_CONFIG_VCSEL_WIDTH = 0x32,
78 | GLOBAL_CONFIG_SPAD_ENABLES_REF_0 = 0xB0,
79 | GLOBAL_CONFIG_SPAD_ENABLES_REF_1 = 0xB1,
80 | GLOBAL_CONFIG_SPAD_ENABLES_REF_2 = 0xB2,
81 | GLOBAL_CONFIG_SPAD_ENABLES_REF_3 = 0xB3,
82 | GLOBAL_CONFIG_SPAD_ENABLES_REF_4 = 0xB4,
83 | GLOBAL_CONFIG_SPAD_ENABLES_REF_5 = 0xB5,
84 |
85 | GLOBAL_CONFIG_REF_EN_START_SELECT = 0xB6,
86 | DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD = 0x4E,
87 | DYNAMIC_SPAD_REF_EN_START_OFFSET = 0x4F,
88 | POWER_MANAGEMENT_GO1_POWER_FORCE = 0x80,
89 |
90 | VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV = 0x89,
91 |
92 | ALGO_PHASECAL_LIM = 0x30,
93 | ALGO_PHASECAL_CONFIG_TIMEOUT = 0x30,
94 | };
95 |
96 | enum vcselPeriodType { VcselPeriodPreRange, VcselPeriodFinalRange };
97 |
98 | uint8_t last_status; // status of last I2C transmission
99 |
100 | VL53L0X();
101 |
102 | void setBus(TwoWire * bus) { this->bus = bus; }
103 | TwoWire * getBus() { return bus; }
104 |
105 | void setAddress(uint8_t new_addr);
106 | inline uint8_t getAddress() { return address; }
107 |
108 | bool init(bool io_2v8 = true);
109 |
110 | void writeReg(uint8_t reg, uint8_t value);
111 | void writeReg16Bit(uint8_t reg, uint16_t value);
112 | void writeReg32Bit(uint8_t reg, uint32_t value);
113 | uint8_t readReg(uint8_t reg);
114 | uint16_t readReg16Bit(uint8_t reg);
115 | uint32_t readReg32Bit(uint8_t reg);
116 |
117 | void writeMulti(uint8_t reg, uint8_t const * src, uint8_t count);
118 | void readMulti(uint8_t reg, uint8_t * dst, uint8_t count);
119 |
120 | bool setSignalRateLimit(float limit_Mcps);
121 | float getSignalRateLimit();
122 |
123 | bool setMeasurementTimingBudget(uint32_t budget_us);
124 | uint32_t getMeasurementTimingBudget();
125 |
126 | bool setVcselPulsePeriod(vcselPeriodType type, uint8_t period_pclks);
127 | uint8_t getVcselPulsePeriod(vcselPeriodType type);
128 |
129 | void startContinuous(uint32_t period_ms = 0);
130 | void stopContinuous();
131 | uint16_t readRangeContinuousMillimeters();
132 | uint16_t readRangeSingleMillimeters();
133 |
134 | inline void setTimeout(uint16_t timeout) { io_timeout = timeout; }
135 | inline uint16_t getTimeout() { return io_timeout; }
136 | bool timeoutOccurred();
137 |
138 | private:
139 | // TCC: Target CentreCheck
140 | // MSRC: Minimum Signal Rate Check
141 | // DSS: Dynamic Spad Selection
142 |
143 | struct SequenceStepEnables
144 | {
145 | boolean tcc, msrc, dss, pre_range, final_range;
146 | };
147 |
148 | struct SequenceStepTimeouts
149 | {
150 | uint16_t pre_range_vcsel_period_pclks, final_range_vcsel_period_pclks;
151 |
152 | uint16_t msrc_dss_tcc_mclks, pre_range_mclks, final_range_mclks;
153 | uint32_t msrc_dss_tcc_us, pre_range_us, final_range_us;
154 | };
155 |
156 | TwoWire * bus;
157 | uint8_t address;
158 | uint16_t io_timeout;
159 | bool did_timeout;
160 | uint16_t timeout_start_ms;
161 |
162 | uint8_t stop_variable; // read by init and used when starting measurement; is StopVariable field of VL53L0X_DevData_t structure in API
163 | uint32_t measurement_timing_budget_us;
164 |
165 | bool getSpadInfo(uint8_t * count, bool * type_is_aperture);
166 |
167 | void getSequenceStepEnables(SequenceStepEnables * enables);
168 | void getSequenceStepTimeouts(SequenceStepEnables const * enables, SequenceStepTimeouts * timeouts);
169 |
170 | bool performSingleRefCalibration(uint8_t vhv_init_byte);
171 |
172 | static uint16_t decodeTimeout(uint16_t value);
173 | static uint16_t encodeTimeout(uint32_t timeout_mclks);
174 | static uint32_t timeoutMclksToMicroseconds(uint16_t timeout_period_mclks, uint8_t vcsel_period_pclks);
175 | static uint32_t timeoutMicrosecondsToMclks(uint32_t timeout_period_us, uint8_t vcsel_period_pclks);
176 | };
177 |
178 | #endif
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/examples/Continuous/Continuous.ino:
--------------------------------------------------------------------------------
1 | /* This example shows how to use continuous mode to take
2 | range measurements with the VL53L0X. It is based on
3 | vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
4 |
5 | The range readings are in units of mm. */
6 |
7 | #include
8 | #include
9 |
10 | VL53L0X sensor;
11 |
12 | void setup()
13 | {
14 | Serial.begin(9600);
15 | Wire.begin();
16 |
17 | sensor.setTimeout(500);
18 | if (!sensor.init())
19 | {
20 | Serial.println("Failed to detect and initialize sensor!");
21 | while (1) {}
22 | }
23 |
24 | // Start continuous back-to-back mode (take readings as
25 | // fast as possible). To use continuous timed mode
26 | // instead, provide a desired inter-measurement period in
27 | // ms (e.g. sensor.startContinuous(100)).
28 | sensor.startContinuous();
29 | }
30 |
31 | void loop()
32 | {
33 | Serial.print(sensor.readRangeContinuousMillimeters());
34 | if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
35 |
36 | Serial.println();
37 | }
38 |
--------------------------------------------------------------------------------
/examples/Single/Single.ino:
--------------------------------------------------------------------------------
1 | /* This example shows how to get single-shot range
2 | measurements from the VL53L0X. The sensor can optionally be
3 | configured with different ranging profiles, as described in
4 | the VL53L0X API user manual, to get better performance for
5 | a certain application. This code is based on the four
6 | "SingleRanging" examples in the VL53L0X API.
7 |
8 | The range readings are in units of mm. */
9 |
10 | #include
11 | #include
12 |
13 | VL53L0X sensor;
14 |
15 |
16 | // Uncomment this line to use long range mode. This
17 | // increases the sensitivity of the sensor and extends its
18 | // potential range, but increases the likelihood of getting
19 | // an inaccurate reading because of reflections from objects
20 | // other than the intended target. It works best in dark
21 | // conditions.
22 |
23 | //#define LONG_RANGE
24 |
25 |
26 | // Uncomment ONE of these two lines to get
27 | // - higher speed at the cost of lower accuracy OR
28 | // - higher accuracy at the cost of lower speed
29 |
30 | //#define HIGH_SPEED
31 | //#define HIGH_ACCURACY
32 |
33 |
34 | void setup()
35 | {
36 | Serial.begin(9600);
37 | Wire.begin();
38 |
39 | sensor.setTimeout(500);
40 | if (!sensor.init())
41 | {
42 | Serial.println("Failed to detect and initialize sensor!");
43 | while (1) {}
44 | }
45 |
46 | #if defined LONG_RANGE
47 | // lower the return signal rate limit (default is 0.25 MCPS)
48 | sensor.setSignalRateLimit(0.1);
49 | // increase laser pulse periods (defaults are 14 and 10 PCLKs)
50 | sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
51 | sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
52 | #endif
53 |
54 | #if defined HIGH_SPEED
55 | // reduce timing budget to 20 ms (default is about 33 ms)
56 | sensor.setMeasurementTimingBudget(20000);
57 | #elif defined HIGH_ACCURACY
58 | // increase timing budget to 200 ms
59 | sensor.setMeasurementTimingBudget(200000);
60 | #endif
61 | }
62 |
63 | void loop()
64 | {
65 | Serial.print(sensor.readRangeSingleMillimeters());
66 | if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
67 |
68 | Serial.println();
69 | }
70 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | VL53L0X KEYWORD1
2 |
3 | setAddress KEYWORD2
4 | getAddress KEYWORD2
5 | init KEYWORD2
6 | writeReg KEYWORD2
7 | writeReg16Bit KEYWORD2
8 | writeReg32Bit KEYWORD2
9 | readReg KEYWORD2
10 | readReg16Bit KEYWORD2
11 | readReg32Bit KEYWORD2
12 | writeMulti KEYWORD2
13 | readMulti KEYWORD2
14 | setSignalRateLimit KEYWORD2
15 | getSignalRateLimit KEYWORD2
16 | setMeasurementTimingBudget KEYWORD2
17 | getMeasurementTimingBudget KEYWORD2
18 | setVcselPulsePeriod KEYWORD2
19 | getVcselPulsePeriod KEYWORD2
20 | startContinuous KEYWORD2
21 | stopContinuous KEYWORD2
22 | readRangeContinuousMillimeters KEYWORD2
23 | readRangeSingleMillimeters KEYWORD2
24 | setTimeout KEYWORD2
25 | getTimeout KEYWORD2
26 | timeoutOccurred KEYWORD2
27 |
28 | SYSRANGE_START LITERAL1
29 | SYSTEM_THRESH_HIGH LITERAL1
30 | SYSTEM_THRESH_LOW LITERAL1
31 | SYSTEM_SEQUENCE_CONFIG LITERAL1
32 | SYSTEM_RANGE_CONFIG LITERAL1
33 | SYSTEM_INTERMEASUREMENT_PERIOD LITERAL1
34 | SYSTEM_INTERRUPT_CONFIG_GPIO LITERAL1
35 | GPIO_HV_MUX_ACTIVE_HIGH LITERAL1
36 | SYSTEM_INTERRUPT_CLEAR LITERAL1
37 | RESULT_INTERRUPT_STATUS LITERAL1
38 | RESULT_RANGE_STATUS LITERAL1
39 | RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN LITERAL1
40 | RESULT_CORE_RANGING_TOTAL_EVENTS_RTN LITERAL1
41 | RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF LITERAL1
42 | RESULT_CORE_RANGING_TOTAL_EVENTS_REF LITERAL1
43 | RESULT_PEAK_SIGNAL_RATE_REF LITERAL1
44 | ALGO_PART_TO_PART_RANGE_OFFSET_MM LITERAL1
45 | I2C_SLAVE_DEVICE_ADDRESS LITERAL1
46 | MSRC_CONFIG_CONTROL LITERAL1
47 | PRE_RANGE_CONFIG_MIN_SNR LITERAL1
48 | PRE_RANGE_CONFIG_VALID_PHASE_LOW LITERAL1
49 | PRE_RANGE_CONFIG_VALID_PHASE_HIGH LITERAL1
50 | PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT LITERAL1
51 | FINAL_RANGE_CONFIG_MIN_SNR LITERAL1
52 | FINAL_RANGE_CONFIG_VALID_PHASE_LOW LITERAL1
53 | FINAL_RANGE_CONFIG_VALID_PHASE_HIGH LITERAL1
54 | FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT LITERAL1
55 | PRE_RANGE_CONFIG_SIGMA_THRESH_HI LITERAL1
56 | PRE_RANGE_CONFIG_SIGMA_THRESH_LO LITERAL1
57 | PRE_RANGE_CONFIG_VCSEL_PERIOD LITERAL1
58 | PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI LITERAL1
59 | PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO LITERAL1
60 | SYSTEM_HISTOGRAM_BIN LITERAL1
61 | HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT LITERAL1
62 | HISTOGRAM_CONFIG_READOUT_CTRL LITERAL1
63 | FINAL_RANGE_CONFIG_VCSEL_PERIOD LITERAL1
64 | FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI LITERAL1
65 | FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO LITERAL1
66 | CROSSTALK_COMPENSATION_PEAK_RATE_MCPS LITERAL1
67 | MSRC_CONFIG_TIMEOUT_MACROP LITERAL1
68 | SOFT_RESET_GO2_SOFT_RESET_N LITERAL1
69 | IDENTIFICATION_MODEL_ID LITERAL1
70 | IDENTIFICATION_REVISION_ID LITERAL1
71 | OSC_CALIBRATE_VAL LITERAL1
72 | GLOBAL_CONFIG_VCSEL_WIDTH LITERAL1
73 | GLOBAL_CONFIG_SPAD_ENABLES_REF_0 LITERAL1
74 | GLOBAL_CONFIG_SPAD_ENABLES_REF_1 LITERAL1
75 | GLOBAL_CONFIG_SPAD_ENABLES_REF_2 LITERAL1
76 | GLOBAL_CONFIG_SPAD_ENABLES_REF_3 LITERAL1
77 | GLOBAL_CONFIG_SPAD_ENABLES_REF_4 LITERAL1
78 | GLOBAL_CONFIG_SPAD_ENABLES_REF_5 LITERAL1
79 | GLOBAL_CONFIG_REF_EN_START_SELECT LITERAL1
80 | DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD LITERAL1
81 | DYNAMIC_SPAD_REF_EN_START_OFFSET LITERAL1
82 | POWER_MANAGEMENT_GO1_POWER_FORCE LITERAL1
83 | VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV LITERAL1
84 | ALGO_PHASECAL_LIM LITERAL1
85 | ALGO_PHASECAL_CONFIG_TIMEOUT LITERAL1
86 |
87 | VcselPeriodPreRange LITERAL1
88 | VcselPeriodFinalRange LITERAL1
89 |
90 |
91 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=VL53L0X
2 | version=1.3.1
3 | author=Pololu
4 | maintainer=Pololu
5 | sentence=VL53L0X distance sensor library
6 | paragraph=This is a library for the Arduino IDE that helps interface with ST's VL53L0X distance sensor.
7 | category=Sensors
8 | url=https://github.com/pololu/vl53l0x-arduino
9 | architectures=*
10 |
--------------------------------------------------------------------------------