mirror of https://github.com/arendst/Tasmota.git
add vl53l0x
This commit is contained in:
parent
b18eee50e2
commit
1f17a407c9
|
@ -0,0 +1,24 @@
|
|||
language: python
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- "~/.platformio"
|
||||
|
||||
install:
|
||||
- pip install -U platformio
|
||||
|
||||
env:
|
||||
- BOARD=uno
|
||||
- BOARD=leonardo
|
||||
- BOARD=micro
|
||||
- BOARD=megaatmega2560
|
||||
- BOARD=due
|
||||
- BOARD=yun
|
||||
- BOARD=genuino101
|
||||
- BOARD=zero
|
||||
|
||||
script:
|
||||
- set -eo pipefail;
|
||||
for e in examples/*; do
|
||||
platformio ci --board=$BOARD --lib=. $e/*;
|
||||
done
|
|
@ -0,0 +1,71 @@
|
|||
Copyright (c) 2017 Pololu Corporation. For more information, see
|
||||
|
||||
https://www.pololu.com/
|
||||
https://forum.pololu.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
=================================================================
|
||||
|
||||
Most of the functionality of this library is based on the VL53L0X
|
||||
API provided by ST (STSW-IMG005), and some of the explanatory
|
||||
comments are quoted or paraphrased from the API source code, API
|
||||
user manual (UM2039), and the VL53L0X datasheet.
|
||||
|
||||
The following applies to source code reproduced or derived from
|
||||
the API:
|
||||
|
||||
-----------------------------------------------------------------
|
||||
|
||||
Copyright © 2016, STMicroelectronics International N.V. All
|
||||
rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
||||
|
||||
-----------------------------------------------------------------
|
|
@ -0,0 +1,164 @@
|
|||
# VL53L0X library for Arduino
|
||||
|
||||
Version: 1.0.2<br>
|
||||
Release date: 2017 Jun 27<br>
|
||||
[![Build Status](https://travis-ci.org/pololu/vl53l0x-arduino.svg?branch=master)](https://travis-ci.org/pololu/vl53l0x-arduino)<br>
|
||||
[www.pololu.com](https://www.pololu.com/)
|
||||
|
||||
## Summary
|
||||
|
||||
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.
|
||||
|
||||
## Supported platforms
|
||||
|
||||
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).
|
||||
|
||||
## Getting started
|
||||
|
||||
### Hardware
|
||||
|
||||
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.
|
||||
|
||||
Make the following connections between the Arduino and the VL53L0X board:
|
||||
|
||||
#### 5V Arduino boards
|
||||
|
||||
(including Arduino Uno, Leonardo, Mega; Pololu A-Star 32U4)
|
||||
|
||||
Arduino VL53L0X board
|
||||
------- -------------
|
||||
5V - VIN
|
||||
GND - GND
|
||||
SDA - SDA
|
||||
SCL - SCL
|
||||
|
||||
#### 3.3V Arduino boards
|
||||
|
||||
(including Arduino Due)
|
||||
|
||||
Arduino VL53L0X board
|
||||
------- -------------
|
||||
3V3 - VIN
|
||||
GND - GND
|
||||
SDA - SDA
|
||||
SCL - SCL
|
||||
|
||||
### Software
|
||||
|
||||
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:
|
||||
|
||||
1. In the Arduino IDE, open the "Sketch" menu, select "Include Library", then "Manage Libraries...".
|
||||
2. Search for "VL53L0X".
|
||||
3. Click the VL53L0X entry in the list.
|
||||
4. Click "Install".
|
||||
|
||||
If this does not work, you can manually install the library:
|
||||
|
||||
1. Download the [latest release archive from GitHub](https://github.com/pololu/vl53l0x-arduino/releases) and decompress it.
|
||||
2. Rename the folder "vl53l0x-arduino-master" to "VL53L0X".
|
||||
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.
|
||||
4. After installing the library, restart the Arduino IDE.
|
||||
|
||||
## Examples
|
||||
|
||||
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.
|
||||
|
||||
## ST's VL53L0X API and this library
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## Library reference
|
||||
|
||||
* `uint8_t last_status`<br>
|
||||
The status of the last I²C write transmission. See the [`Wire.endTransmission()` documentation](http://arduino.cc/en/Reference/WireEndTransmission) for return values.
|
||||
|
||||
* `VL53L0X(void)`<br>
|
||||
Constructor.
|
||||
|
||||
* `void setAddress(uint8_t new_addr)`<br>
|
||||
Changes the I²C slave device address of the VL53L0X to the given value (7-bit).
|
||||
|
||||
* `uint8_t getAddress(void)`<br>
|
||||
Returns the current I²C address.
|
||||
|
||||
* `bool init(bool io_2v8 = true)`<br>
|
||||
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.
|
||||
|
||||
* `void writeReg(uint8_t reg, uint8_t value)`<br>
|
||||
Writes an 8-bit sensor register with the given value.
|
||||
|
||||
Register address constants are defined by the regAddr enumeration type in VL53L0X.h.<br>
|
||||
Example use: `sensor.writeReg(VL53L0X::SYSRANGE_START, 0x01);`
|
||||
|
||||
* `void writeReg16Bit(uint8_t reg, uint16_t value)`<br>
|
||||
Writes a 16-bit sensor register with the given value.
|
||||
|
||||
* `void writeReg32Bit(uint8_t reg, uint32_t value)`<br>
|
||||
Writes a 32-bit sensor register with the given value.
|
||||
|
||||
* `uint8_t readReg(uint8_t reg)`<br>
|
||||
Reads an 8-bit sensor register and returns the value read.
|
||||
|
||||
* `uint16_t readReg16Bit(uint8_t reg)`<br>
|
||||
Reads a 16-bit sensor register and returns the value read.
|
||||
|
||||
* `uint32_t readReg32Bit(uint8_t reg)`<br>
|
||||
Reads a 32-bit sensor register and returns the value read.
|
||||
|
||||
* `void writeMulti(uint8_t reg, uint8_t const * src, uint8_t count)`<br>
|
||||
Writes an arbitrary number of bytes from the given array to the sensor, starting at the given register.
|
||||
|
||||
* `void readMulti(uint8_t reg, uint8_t * dst, uint8_t count)`<br>
|
||||
Reads an arbitrary number of bytes from the sensor, starting at the given register, into the given array.
|
||||
|
||||
* `bool setSignalRateLimit(float limit_Mcps)`<br>
|
||||
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.
|
||||
|
||||
* `float getSignalRateLimit(void)`<br>
|
||||
Returns the current return signal rate limit in MCPS.
|
||||
|
||||
* `bool setMeasurementTimingBudget(uint32_t budget_us)`<br>
|
||||
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.
|
||||
|
||||
* `uint32_t getMeasurementTimingBudget(void)`<br>
|
||||
Returns the current measurement timing budget in microseconds.
|
||||
|
||||
* `bool setVcselPulsePeriod(vcselPeriodType type, uint8_t period_pclks)`
|
||||
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):
|
||||
|
||||
Pre: 12 to 18 (initialized to 14 by default)<br>
|
||||
Final: 8 to 14 (initialized to 10 by default)
|
||||
|
||||
The return value is a boolean indicating whether the requested period was valid.
|
||||
|
||||
* `uint8_t getVcselPulsePeriod(vcselPeriodType type)`<br>
|
||||
Returns the current VCSEL pulse period for the given period type.
|
||||
|
||||
* `void startContinuous(uint32_t period_ms = 0)`<br>
|
||||
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.
|
||||
|
||||
* `void stopContinuous(void)`<br>
|
||||
Stops continuous mode.
|
||||
|
||||
* `uint16_t readRangeContinuousMillimeters(void)`<br>
|
||||
Returns a range reading in millimeters when continuous mode is active.
|
||||
|
||||
* `uint16_t readRangeSingleMillimeters(void)`<br>
|
||||
Performs a single-shot ranging measurement and returns the reading in millimeters.
|
||||
|
||||
* `void setTimeout(uint16_t timeout)`<br>
|
||||
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.
|
||||
|
||||
* `uint16_t getTimeout(void)`<br>
|
||||
Returns the current timeout period setting.
|
||||
|
||||
* `bool timeoutOccurred(void)`<br>
|
||||
Indicates whether a read timeout has occurred since the last call to `timeoutOccurred()`.
|
||||
|
||||
## Version history
|
||||
|
||||
* 1.0.2 (2017 Jun 27): Fixed a typo in a register modification in `getSpadInfo()` (thanks @tridge).
|
||||
* 1.0.1 (2016 Dec 08): Fixed type error in `readReg32Bit()`.
|
||||
* 1.0.0 (2016 Aug 12): Original release.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,176 @@
|
|||
#ifndef VL53L0X_h
|
||||
#define VL53L0X_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class VL53L0X
|
||||
{
|
||||
public:
|
||||
// register addresses from API vl53l0x_device.h (ordered as listed there)
|
||||
enum regAddr
|
||||
{
|
||||
SYSRANGE_START = 0x00,
|
||||
|
||||
SYSTEM_THRESH_HIGH = 0x0C,
|
||||
SYSTEM_THRESH_LOW = 0x0E,
|
||||
|
||||
SYSTEM_SEQUENCE_CONFIG = 0x01,
|
||||
SYSTEM_RANGE_CONFIG = 0x09,
|
||||
SYSTEM_INTERMEASUREMENT_PERIOD = 0x04,
|
||||
|
||||
SYSTEM_INTERRUPT_CONFIG_GPIO = 0x0A,
|
||||
|
||||
GPIO_HV_MUX_ACTIVE_HIGH = 0x84,
|
||||
|
||||
SYSTEM_INTERRUPT_CLEAR = 0x0B,
|
||||
|
||||
RESULT_INTERRUPT_STATUS = 0x13,
|
||||
RESULT_RANGE_STATUS = 0x14,
|
||||
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN = 0xBC,
|
||||
RESULT_CORE_RANGING_TOTAL_EVENTS_RTN = 0xC0,
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF = 0xD0,
|
||||
RESULT_CORE_RANGING_TOTAL_EVENTS_REF = 0xD4,
|
||||
RESULT_PEAK_SIGNAL_RATE_REF = 0xB6,
|
||||
|
||||
ALGO_PART_TO_PART_RANGE_OFFSET_MM = 0x28,
|
||||
|
||||
I2C_SLAVE_DEVICE_ADDRESS = 0x8A,
|
||||
|
||||
MSRC_CONFIG_CONTROL = 0x60,
|
||||
|
||||
PRE_RANGE_CONFIG_MIN_SNR = 0x27,
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_LOW = 0x56,
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_HIGH = 0x57,
|
||||
PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT = 0x64,
|
||||
|
||||
FINAL_RANGE_CONFIG_MIN_SNR = 0x67,
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_LOW = 0x47,
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_HIGH = 0x48,
|
||||
FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT = 0x44,
|
||||
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_HI = 0x61,
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_LO = 0x62,
|
||||
|
||||
PRE_RANGE_CONFIG_VCSEL_PERIOD = 0x50,
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x51,
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x52,
|
||||
|
||||
SYSTEM_HISTOGRAM_BIN = 0x81,
|
||||
HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT = 0x33,
|
||||
HISTOGRAM_CONFIG_READOUT_CTRL = 0x55,
|
||||
|
||||
FINAL_RANGE_CONFIG_VCSEL_PERIOD = 0x70,
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x71,
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x72,
|
||||
CROSSTALK_COMPENSATION_PEAK_RATE_MCPS = 0x20,
|
||||
|
||||
MSRC_CONFIG_TIMEOUT_MACROP = 0x46,
|
||||
|
||||
SOFT_RESET_GO2_SOFT_RESET_N = 0xBF,
|
||||
IDENTIFICATION_MODEL_ID = 0xC0,
|
||||
IDENTIFICATION_REVISION_ID = 0xC2,
|
||||
|
||||
OSC_CALIBRATE_VAL = 0xF8,
|
||||
|
||||
GLOBAL_CONFIG_VCSEL_WIDTH = 0x32,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_0 = 0xB0,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_1 = 0xB1,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_2 = 0xB2,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_3 = 0xB3,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_4 = 0xB4,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_5 = 0xB5,
|
||||
|
||||
GLOBAL_CONFIG_REF_EN_START_SELECT = 0xB6,
|
||||
DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD = 0x4E,
|
||||
DYNAMIC_SPAD_REF_EN_START_OFFSET = 0x4F,
|
||||
POWER_MANAGEMENT_GO1_POWER_FORCE = 0x80,
|
||||
|
||||
VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV = 0x89,
|
||||
|
||||
ALGO_PHASECAL_LIM = 0x30,
|
||||
ALGO_PHASECAL_CONFIG_TIMEOUT = 0x30,
|
||||
};
|
||||
|
||||
enum vcselPeriodType { VcselPeriodPreRange, VcselPeriodFinalRange };
|
||||
|
||||
uint8_t last_status; // status of last I2C transmission
|
||||
|
||||
VL53L0X(void);
|
||||
|
||||
void setAddress(uint8_t new_addr);
|
||||
inline uint8_t getAddress(void) { return address; }
|
||||
|
||||
bool init(bool io_2v8 = true);
|
||||
|
||||
void writeReg(uint8_t reg, uint8_t value);
|
||||
void writeReg16Bit(uint8_t reg, uint16_t value);
|
||||
void writeReg32Bit(uint8_t reg, uint32_t value);
|
||||
uint8_t readReg(uint8_t reg);
|
||||
uint16_t readReg16Bit(uint8_t reg);
|
||||
uint32_t readReg32Bit(uint8_t reg);
|
||||
|
||||
void writeMulti(uint8_t reg, uint8_t const * src, uint8_t count);
|
||||
void readMulti(uint8_t reg, uint8_t * dst, uint8_t count);
|
||||
|
||||
bool setSignalRateLimit(float limit_Mcps);
|
||||
float getSignalRateLimit(void);
|
||||
|
||||
bool setMeasurementTimingBudget(uint32_t budget_us);
|
||||
uint32_t getMeasurementTimingBudget(void);
|
||||
|
||||
bool setVcselPulsePeriod(vcselPeriodType type, uint8_t period_pclks);
|
||||
uint8_t getVcselPulsePeriod(vcselPeriodType type);
|
||||
|
||||
void startContinuous(uint32_t period_ms = 0);
|
||||
void stopContinuous(void);
|
||||
uint16_t readRangeContinuousMillimeters(void);
|
||||
uint16_t readRangeSingleMillimeters(void);
|
||||
|
||||
inline void setTimeout(uint16_t timeout) { io_timeout = timeout; }
|
||||
inline uint16_t getTimeout(void) { return io_timeout; }
|
||||
bool timeoutOccurred(void);
|
||||
|
||||
private:
|
||||
// TCC: Target CentreCheck
|
||||
// MSRC: Minimum Signal Rate Check
|
||||
// DSS: Dynamic Spad Selection
|
||||
|
||||
struct SequenceStepEnables
|
||||
{
|
||||
boolean tcc, msrc, dss, pre_range, final_range;
|
||||
};
|
||||
|
||||
struct SequenceStepTimeouts
|
||||
{
|
||||
uint16_t pre_range_vcsel_period_pclks, final_range_vcsel_period_pclks;
|
||||
|
||||
uint16_t msrc_dss_tcc_mclks, pre_range_mclks, final_range_mclks;
|
||||
uint32_t msrc_dss_tcc_us, pre_range_us, final_range_us;
|
||||
};
|
||||
|
||||
uint8_t address;
|
||||
uint16_t io_timeout;
|
||||
bool did_timeout;
|
||||
uint16_t timeout_start_ms;
|
||||
|
||||
uint8_t stop_variable; // read by init and used when starting measurement; is StopVariable field of VL53L0X_DevData_t structure in API
|
||||
uint32_t measurement_timing_budget_us;
|
||||
|
||||
bool getSpadInfo(uint8_t * count, bool * type_is_aperture);
|
||||
|
||||
void getSequenceStepEnables(SequenceStepEnables * enables);
|
||||
void getSequenceStepTimeouts(SequenceStepEnables const * enables, SequenceStepTimeouts * timeouts);
|
||||
|
||||
bool performSingleRefCalibration(uint8_t vhv_init_byte);
|
||||
|
||||
static uint16_t decodeTimeout(uint16_t value);
|
||||
static uint16_t encodeTimeout(uint16_t timeout_mclks);
|
||||
static uint32_t timeoutMclksToMicroseconds(uint16_t timeout_period_mclks, uint8_t vcsel_period_pclks);
|
||||
static uint32_t timeoutMicrosecondsToMclks(uint32_t timeout_period_us, uint8_t vcsel_period_pclks);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/* This example shows how to use continuous mode to take
|
||||
range measurements with the VL53L0X. It is based on
|
||||
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
|
||||
|
||||
The range readings are in units of mm. */
|
||||
|
||||
#include <Wire.h>
|
||||
#include <VL53L0X.h>
|
||||
|
||||
VL53L0X sensor;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Wire.begin();
|
||||
|
||||
sensor.init();
|
||||
sensor.setTimeout(500);
|
||||
|
||||
// Start continuous back-to-back mode (take readings as
|
||||
// fast as possible). To use continuous timed mode
|
||||
// instead, provide a desired inter-measurement period in
|
||||
// ms (e.g. sensor.startContinuous(100)).
|
||||
sensor.startContinuous();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(sensor.readRangeContinuousMillimeters());
|
||||
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
|
||||
|
||||
Serial.println();
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* This example shows how to get single-shot range
|
||||
measurements from the VL53L0X. The sensor can optionally be
|
||||
configured with different ranging profiles, as described in
|
||||
the VL53L0X API user manual, to get better performance for
|
||||
a certain application. This code is based on the four
|
||||
"SingleRanging" examples in the VL53L0X API.
|
||||
|
||||
The range readings are in units of mm. */
|
||||
|
||||
#include <Wire.h>
|
||||
#include <VL53L0X.h>
|
||||
|
||||
VL53L0X sensor;
|
||||
|
||||
|
||||
// Uncomment this line to use long range mode. This
|
||||
// increases the sensitivity of the sensor and extends its
|
||||
// potential range, but increases the likelihood of getting
|
||||
// an inaccurate reading because of reflections from objects
|
||||
// other than the intended target. It works best in dark
|
||||
// conditions.
|
||||
|
||||
//#define LONG_RANGE
|
||||
|
||||
|
||||
// Uncomment ONE of these two lines to get
|
||||
// - higher speed at the cost of lower accuracy OR
|
||||
// - higher accuracy at the cost of lower speed
|
||||
|
||||
//#define HIGH_SPEED
|
||||
//#define HIGH_ACCURACY
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Wire.begin();
|
||||
|
||||
sensor.init();
|
||||
sensor.setTimeout(500);
|
||||
|
||||
#if defined LONG_RANGE
|
||||
// lower the return signal rate limit (default is 0.25 MCPS)
|
||||
sensor.setSignalRateLimit(0.1);
|
||||
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
|
||||
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
|
||||
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
|
||||
#endif
|
||||
|
||||
#if defined HIGH_SPEED
|
||||
// reduce timing budget to 20 ms (default is about 33 ms)
|
||||
sensor.setMeasurementTimingBudget(20000);
|
||||
#elif defined HIGH_ACCURACY
|
||||
// increase timing budget to 200 ms
|
||||
sensor.setMeasurementTimingBudget(200000);
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(sensor.readRangeSingleMillimeters());
|
||||
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
|
||||
|
||||
Serial.println();
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
VL53L0X KEYWORD1
|
||||
|
||||
setAddress KEYWORD2
|
||||
getAddress KEYWORD2
|
||||
init KEYWORD2
|
||||
writeReg KEYWORD2
|
||||
writeReg16Bit KEYWORD2
|
||||
writeReg32Bit KEYWORD2
|
||||
readReg KEYWORD2
|
||||
readReg16Bit KEYWORD2
|
||||
readReg32Bit KEYWORD2
|
||||
writeMulti KEYWORD2
|
||||
readMulti KEYWORD2
|
||||
setSignalRateLimit KEYWORD2
|
||||
getSignalRateLimit KEYWORD2
|
||||
setMeasurementTimingBudget KEYWORD2
|
||||
getMeasurementTimingBudget KEYWORD2
|
||||
setVcselPulsePeriod KEYWORD2
|
||||
getVcselPulsePeriod KEYWORD2
|
||||
startContinuous KEYWORD2
|
||||
stopContinuous KEYWORD2
|
||||
readRangeContinuousMillimeters KEYWORD2
|
||||
readRangeSingleMillimeters KEYWORD2
|
||||
setTimeout KEYWORD2
|
||||
getTimeout KEYWORD2
|
||||
timeoutOccurred KEYWORD2
|
||||
|
||||
SYSRANGE_START LITERAL1
|
||||
SYSTEM_THRESH_HIGH LITERAL1
|
||||
SYSTEM_THRESH_LOW LITERAL1
|
||||
SYSTEM_SEQUENCE_CONFIG LITERAL1
|
||||
SYSTEM_RANGE_CONFIG LITERAL1
|
||||
SYSTEM_INTERMEASUREMENT_PERIOD LITERAL1
|
||||
SYSTEM_INTERRUPT_CONFIG_GPIO LITERAL1
|
||||
GPIO_HV_MUX_ACTIVE_HIGH LITERAL1
|
||||
SYSTEM_INTERRUPT_CLEAR LITERAL1
|
||||
RESULT_INTERRUPT_STATUS LITERAL1
|
||||
RESULT_RANGE_STATUS LITERAL1
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN LITERAL1
|
||||
RESULT_CORE_RANGING_TOTAL_EVENTS_RTN LITERAL1
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF LITERAL1
|
||||
RESULT_CORE_RANGING_TOTAL_EVENTS_REF LITERAL1
|
||||
RESULT_PEAK_SIGNAL_RATE_REF LITERAL1
|
||||
ALGO_PART_TO_PART_RANGE_OFFSET_MM LITERAL1
|
||||
I2C_SLAVE_DEVICE_ADDRESS LITERAL1
|
||||
MSRC_CONFIG_CONTROL LITERAL1
|
||||
PRE_RANGE_CONFIG_MIN_SNR LITERAL1
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_LOW LITERAL1
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_HIGH LITERAL1
|
||||
PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT LITERAL1
|
||||
FINAL_RANGE_CONFIG_MIN_SNR LITERAL1
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_LOW LITERAL1
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_HIGH LITERAL1
|
||||
FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT LITERAL1
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_HI LITERAL1
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_LO LITERAL1
|
||||
PRE_RANGE_CONFIG_VCSEL_PERIOD LITERAL1
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI LITERAL1
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO LITERAL1
|
||||
SYSTEM_HISTOGRAM_BIN LITERAL1
|
||||
HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT LITERAL1
|
||||
HISTOGRAM_CONFIG_READOUT_CTRL LITERAL1
|
||||
FINAL_RANGE_CONFIG_VCSEL_PERIOD LITERAL1
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI LITERAL1
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO LITERAL1
|
||||
CROSSTALK_COMPENSATION_PEAK_RATE_MCPS LITERAL1
|
||||
MSRC_CONFIG_TIMEOUT_MACROP LITERAL1
|
||||
SOFT_RESET_GO2_SOFT_RESET_N LITERAL1
|
||||
IDENTIFICATION_MODEL_ID LITERAL1
|
||||
IDENTIFICATION_REVISION_ID LITERAL1
|
||||
OSC_CALIBRATE_VAL LITERAL1
|
||||
GLOBAL_CONFIG_VCSEL_WIDTH LITERAL1
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_0 LITERAL1
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_1 LITERAL1
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_2 LITERAL1
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_3 LITERAL1
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_4 LITERAL1
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_5 LITERAL1
|
||||
GLOBAL_CONFIG_REF_EN_START_SELECT LITERAL1
|
||||
DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD LITERAL1
|
||||
DYNAMIC_SPAD_REF_EN_START_OFFSET LITERAL1
|
||||
POWER_MANAGEMENT_GO1_POWER_FORCE LITERAL1
|
||||
VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV LITERAL1
|
||||
ALGO_PHASECAL_LIM LITERAL1
|
||||
ALGO_PHASECAL_CONFIG_TIMEOUT LITERAL1
|
||||
|
||||
VcselPeriodPreRange LITERAL1
|
||||
VcselPeriodFinalRange LITERAL1
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
name=VL53L0X
|
||||
version=1.0.2
|
||||
author=Pololu
|
||||
maintainer=Pololu <inbox@pololu.com>
|
||||
sentence=VL53L0X distance sensor library
|
||||
paragraph=This is a library for the Arduino IDE that helps interface with ST's VL53L0X distance sensor.
|
||||
category=Sensors
|
||||
url=https://github.com/pololu/vl53l0x-arduino
|
||||
architectures=*
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
xsns_99_vl53l0x.ino - VL53L0X
|
||||
|
||||
Copyright (C) 2018 Theo Arends and Gerhard Mutz
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_I2C
|
||||
#ifdef USE_VL53L0X
|
||||
|
||||
#include <Wire.h>
|
||||
#include "VL53L0X.h"
|
||||
VL53L0X sensor;
|
||||
|
||||
uint8_t vl53l0x_ready = 0;
|
||||
uint16_t vl53l0x_distance;
|
||||
uint16_t Vl53l0_buffer[5];
|
||||
uint8_t Vl53l0_index;
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void Vl53l0Detect()
|
||||
{
|
||||
|
||||
if (!I2cDevice(0x29)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vl53l0x_ready) {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("VL53L1X is ready"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (sensor.init()==true) {
|
||||
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "VL53L0X", sensor.getAddress());
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
sensor.setTimeout(500);
|
||||
|
||||
// Start continuous back-to-back mode (take readings as
|
||||
// fast as possible). To use continuous timed mode
|
||||
// instead, provide a desired inter-measurement period in
|
||||
// ms (e.g. sensor.startContinuous(100)).
|
||||
sensor.startContinuous();
|
||||
vl53l0x_ready = 1;
|
||||
|
||||
Vl53l0_index=0;
|
||||
|
||||
}
|
||||
|
||||
#define D_UNIT_MILLIMETER "mm"
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
const char HTTP_SNS_VL53L0X[] PROGMEM =
|
||||
"{s}VL53L0X " D_DISTANCE "{m}%d" D_UNIT_MILLIMETER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
#define USE_VL_MEDIAN
|
||||
|
||||
void Vl53l0Every_250MSecond() {
|
||||
uint16_t tbuff[5],tmp;
|
||||
uint8_t flag;
|
||||
|
||||
if (!vl53l0x_ready) return;
|
||||
|
||||
// every 200 ms
|
||||
uint16_t dist = sensor.readRangeContinuousMillimeters();
|
||||
if (dist==0 || dist>2000) {
|
||||
dist=9999;
|
||||
}
|
||||
|
||||
#ifdef USE_VL_MEDIAN
|
||||
// store in ring buffer
|
||||
Vl53l0_buffer[Vl53l0_index]=dist;
|
||||
Vl53l0_index++;
|
||||
if (Vl53l0_index>=5) Vl53l0_index=0;
|
||||
|
||||
// sort list and take median
|
||||
memmove(tbuff,Vl53l0_buffer,sizeof(tbuff));
|
||||
for (byte ocnt=0; ocnt<5; ocnt++) {
|
||||
flag=0;
|
||||
for (byte count=0; count<4; count++) {
|
||||
if (tbuff[count]>tbuff[count+1]) {
|
||||
tmp=tbuff[count];
|
||||
tbuff[count]=tbuff[count+1];
|
||||
tbuff[count+1]=tmp;
|
||||
flag=1;
|
||||
}
|
||||
}
|
||||
if (!flag) break;
|
||||
}
|
||||
vl53l0x_distance=tbuff[2];
|
||||
#else
|
||||
vl53l0x_distance=dist;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Vl53l0Show(boolean json)
|
||||
{
|
||||
if (!vl53l0x_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (json) {
|
||||
ResponseAppend_P(PSTR(",\"VL53L0X\":{\"" D_JSON_DISTANCE "\":%d}"), vl53l0x_distance);
|
||||
#ifdef USE_WEBSERVER
|
||||
} else {
|
||||
WSContentSend_PD(HTTP_SNS_VL53L0X, vl53l0x_distance);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define XSNS_45
|
||||
|
||||
bool Xsns45(byte function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (i2c_flg) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
Vl53l0Detect();
|
||||
break;
|
||||
case FUNC_EVERY_250_MSECOND:
|
||||
Vl53l0Every_250MSecond();
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
Vl53l0Show(1);
|
||||
break;
|
||||
#ifdef USE_WEBSERVER
|
||||
case FUNC_WEB_SENSOR:
|
||||
Vl53l0Show(0);
|
||||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // USE_VL53L0X
|
||||
#endif // USE_I2C
|
Loading…
Reference in New Issue