Skip to content

Commit dac7ebb

Browse files
authored
Merge pull request #560 from tyeth/main-addvl53l1x
Add Vl53l1x
2 parents 6af43d5 + 4dabe3a commit dac7ebb

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork
10+
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork

platformio.ini

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ lib_deps =
4949
adafruit/Adafruit TMP117
5050
adafruit/Adafruit TSL2591 Library
5151
adafruit/Adafruit_VL53L0X
52+
adafruit/Adafruit VL53L1X
5253
adafruit/Adafruit_VL6180X
5354
adafruit/Adafruit PM25 AQI Sensor
5455
adafruit/Adafruit VEML7700 Library

src/components/i2c/WipperSnapper_I2C.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
669669
_vl53l0x->configureDriver(msgDeviceInitReq);
670670
drivers.push_back(_vl53l0x);
671671
WS_DEBUG_PRINTLN("VL53L0X Initialized Successfully!");
672+
} else if (strcmp("vl53l1x", msgDeviceInitReq->i2c_device_name) == 0) {
673+
_vl53l1x = new WipperSnapper_I2C_Driver_VL53L1X(this->_i2c, i2cAddress);
674+
if (!_vl53l1x->begin()) {
675+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize VL53L1X!");
676+
_busStatusResponse =
677+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
678+
return false;
679+
}
680+
_vl53l1x->configureDriver(msgDeviceInitReq);
681+
drivers.push_back(_vl53l1x);
682+
WS_DEBUG_PRINTLN("VL53L1X Initialized Successfully!");
672683
} else if (strcmp("vl6180x", msgDeviceInitReq->i2c_device_name) == 0) {
673684
_vl6180x = new WipperSnapper_I2C_Driver_VL6180X(this->_i2c, i2cAddress);
674685
if (!_vl6180x->begin()) {

src/components/i2c/WipperSnapper_I2C.h

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "drivers/WipperSnapper_I2C_Driver_VCNL4040.h"
6363
#include "drivers/WipperSnapper_I2C_Driver_VEML7700.h"
6464
#include "drivers/WipperSnapper_I2C_Driver_VL53L0X.h"
65+
#include "drivers/WipperSnapper_I2C_Driver_VL53L1X.h"
6566
#include "drivers/WipperSnapper_I2C_Driver_VL6180X.h"
6667

6768
#define I2C_TIMEOUT_MS 50 ///< Default I2C timeout, in milliseconds.
@@ -151,6 +152,7 @@ class WipperSnapper_Component_I2C {
151152
WipperSnapper_I2C_Driver_LPS3XHW *_lps3xhw = nullptr;
152153
WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor *_ss = nullptr;
153154
WipperSnapper_I2C_Driver_VL53L0X *_vl53l0x = nullptr;
155+
WipperSnapper_I2C_Driver_VL53L1X *_vl53l1x = nullptr;
154156
WipperSnapper_I2C_Driver_VL6180X *_vl6180x = nullptr;
155157
WipperSnapper_I2C_Driver_MAX17048 *_max17048 = nullptr;
156158
WipperSnapper_I2C_Driver_ADT7410 *_adt7410 = nullptr;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_VL53L1X.h
3+
*
4+
* Device driver for the VL53L1X ToF sensor.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) 2022 afp316 https://github.com/afp316
11+
* Modified Tyeth Gundry 2023 for Adafruit Industries.
12+
*
13+
* MIT license, all text here must be included in any redistribution.
14+
*
15+
*/
16+
#ifndef WipperSnapper_I2C_Driver_VL53L1X_H
17+
#define WipperSnapper_I2C_Driver_VL53L1X_H
18+
19+
#include "WipperSnapper_I2C_Driver.h"
20+
#include <Adafruit_VL53L1X.h>
21+
22+
/**************************************************************************/
23+
/*!
24+
@brief Class that provides a driver interface for a VL53L1X sensor.
25+
*/
26+
/**************************************************************************/
27+
class WipperSnapper_I2C_Driver_VL53L1X : public WipperSnapper_I2C_Driver {
28+
public:
29+
/*******************************************************************************/
30+
/*!
31+
@brief Constructor for a VL53L1X sensor.
32+
@param i2c
33+
The I2C interface.
34+
@param sensorAddress
35+
7-bit device address.
36+
*/
37+
/*******************************************************************************/
38+
WipperSnapper_I2C_Driver_VL53L1X(TwoWire *i2c, uint16_t sensorAddress)
39+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
40+
_i2c = i2c;
41+
_sensorAddress = sensorAddress;
42+
}
43+
44+
/*******************************************************************************/
45+
/*!
46+
@brief Destructor for an VL53L1X sensor.
47+
*/
48+
/*******************************************************************************/
49+
~WipperSnapper_I2C_Driver_VL53L1X() {
50+
// Called when a VL53L1X component is deleted.
51+
delete _VL53L1X;
52+
}
53+
54+
/*******************************************************************************/
55+
/*!
56+
@brief Initializes the VL53L1X sensor and begins I2C.
57+
@returns True if initialized successfully, False otherwise.
58+
*/
59+
/*******************************************************************************/
60+
bool begin() {
61+
_VL53L1X = new Adafruit_VL53L1X();
62+
if (_VL53L1X->begin((uint8_t)_sensorAddress, _i2c, false)) {
63+
_VL53L1X->startRanging();
64+
_VL53L1X->setTimingBudget(500); // distance mode is long(2) by default
65+
return true;
66+
}
67+
return false;
68+
}
69+
70+
/*******************************************************************************/
71+
/*!
72+
@brief Gets the VL53L1X's current proximity.
73+
@param proximityEvent
74+
Pointer to an Adafruit_Sensor event.
75+
@returns True if the proximity was obtained successfully, False
76+
otherwise.
77+
*/
78+
/*******************************************************************************/
79+
bool getEventProximity(sensors_event_t *proximityEvent) {
80+
if (!_VL53L1X->dataReady()) {
81+
return false;
82+
}
83+
int16_t proximityMM = _VL53L1X->distance();
84+
if (proximityMM == -1) {
85+
WS_DEBUG_PRINT("VL53L1X: Invalid proximity value:");
86+
WS_DEBUG_PRINTLN(proximityMM);
87+
WS_DEBUG_PRINT("VL53L1X status: ");
88+
WS_DEBUG_PRINTLN(_VL53L1X->vl_status);
89+
proximityEvent->data[0] = NAN;
90+
} else {
91+
proximityEvent->data[0] = proximityMM;
92+
_VL53L1X->clearInterrupt();
93+
}
94+
return true;
95+
}
96+
97+
protected:
98+
Adafruit_VL53L1X *_VL53L1X; ///< Pointer to VL53L1X temperature sensor object
99+
};
100+
101+
#endif // WipperSnapper_I2C_Driver_VL53L1X

0 commit comments

Comments
 (0)