Skip to content

Commit c38da08

Browse files
authored
Merge pull request #908 from adafruit/add-vcnl4030
Add VCNL4030
2 parents 20a01a4 + 0d5dc5d commit c38da08

7 files changed

Lines changed: 152 additions & 3 deletions

File tree

.agents/skills/SKILLS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check subfolders for skills in this repo.

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=Adafruit WipperSnapper
2-
version=1.0.0-beta.126
2+
version=1.0.0-beta.127
33
author=Adafruit
44
maintainer=Adafruit <adafruitio@adafruit.com>
55
sentence=Arduino application for Adafruit.io WipperSnapper
66
paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPA06_003, Adafruit STCC4, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit APDS9999, Adafruit AS5600 Library, Adafruit AS7331 Library, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit BMP5xx Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Adafruit SGP41, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, 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, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit QMC5883P Library, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit MAX44009, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306, Adafruit EPD, Adafruit ST7735 and ST7789 Library
10+
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPA06_003, Adafruit STCC4, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit APDS9999, Adafruit AS5600 Library, Adafruit AS7331 Library, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit BMP5xx Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Adafruit SGP41, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, 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, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit QMC5883P Library, Adafruit VCNL4020 Library, Adafruit VCNL4030, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit MAX44009, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306, Adafruit EPD, Adafruit ST7735 and ST7789 Library

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ lib_deps =
5151
adafruit/Adafruit SPA06_003
5252
adafruit/Adafruit STCC4
5353
adafruit/Adafruit VCNL4020 Library
54+
adafruit/Adafruit VCNL4030
5455
adafruit/Adafruit VCNL4040
5556
adafruit/Adafruit VCNL4200 Library
5657
adafruit/Adafruit MCP3421

src/Wippersnapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
#endif
168168

169169
#define WS_VERSION \
170-
"1.0.0-beta.126" ///< WipperSnapper app. version (semver-formatted)
170+
"1.0.0-beta.127" ///< WipperSnapper app. version (semver-formatted)
171171

172172
// Reserved Adafruit IO MQTT topics
173173
#define TOPIC_IO_THROTTLE "/throttle" ///< Adafruit IO Throttle MQTT Topic

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
712712
_vcnl4020->configureDriver(msgDeviceInitReq);
713713
drivers.push_back(_vcnl4020);
714714
WS_DEBUG_PRINTLN("VCNL4020 Initialized Successfully!");
715+
} else if (strcmp("vcnl4030", msgDeviceInitReq->i2c_device_name) == 0) {
716+
_vcnl4030 = new WipperSnapper_I2C_Driver_VCNL4030(this->_i2c, i2cAddress);
717+
if (!_vcnl4030->begin()) {
718+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize VCNL4030!");
719+
_busStatusResponse =
720+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
721+
return false;
722+
}
723+
_vcnl4030->configureDriver(msgDeviceInitReq);
724+
drivers.push_back(_vcnl4030);
725+
WS_DEBUG_PRINTLN("VCNL4030 Initialized Successfully!");
715726
} else if (strcmp("vcnl4040", msgDeviceInitReq->i2c_device_name) == 0) {
716727
_vcnl4040 = new WipperSnapper_I2C_Driver_VCNL4040(this->_i2c, i2cAddress);
717728
if (!_vcnl4040->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#include "drivers/WipperSnapper_I2C_Driver_TMP119.h"
8888
#include "drivers/WipperSnapper_I2C_Driver_TSL2591.h"
8989
#include "drivers/WipperSnapper_I2C_Driver_VCNL4020.h"
90+
#include "drivers/WipperSnapper_I2C_Driver_VCNL4030.h"
9091
#include "drivers/WipperSnapper_I2C_Driver_VCNL4040.h"
9192
#include "drivers/WipperSnapper_I2C_Driver_VCNL4200.h"
9293
#include "drivers/WipperSnapper_I2C_Driver_VEML7700.h"
@@ -206,6 +207,7 @@ class WipperSnapper_Component_I2C {
206207
WipperSnapper_I2C_Driver_TMP119 *_tmp119 = nullptr;
207208
WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
208209
WipperSnapper_I2C_Driver_VCNL4020 *_vcnl4020 = nullptr;
210+
WipperSnapper_I2C_Driver_VCNL4030 *_vcnl4030 = nullptr;
209211
WipperSnapper_I2C_Driver_VCNL4040 *_vcnl4040 = nullptr;
210212
WipperSnapper_I2C_Driver_VCNL4200 *_vcnl4200 = nullptr;
211213
WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_VCNL4030.h
3+
*
4+
* Device driver for the VCNL4030 proximity + ambient light 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) Tyeth Gundry 2026 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WipperSnapper_I2C_Driver_VCNL4030_H
16+
#define WipperSnapper_I2C_Driver_VCNL4030_H
17+
18+
#include "WipperSnapper_I2C_Driver.h"
19+
#include <Adafruit_VCNL4030.h>
20+
21+
/**************************************************************************/
22+
/*!
23+
@brief Class that provides a driver interface for a VCNL4030 sensor.
24+
*/
25+
/**************************************************************************/
26+
class WipperSnapper_I2C_Driver_VCNL4030 : public WipperSnapper_I2C_Driver {
27+
public:
28+
/*******************************************************************************/
29+
/*!
30+
@brief Constructor for a VCNL4030 sensor.
31+
@param i2c
32+
The I2C interface.
33+
@param sensorAddress
34+
The 7-bit I2C address of the sensor.
35+
*/
36+
/*******************************************************************************/
37+
WipperSnapper_I2C_Driver_VCNL4030(TwoWire *i2c, uint16_t sensorAddress)
38+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
39+
_i2c = i2c;
40+
_sensorAddress = sensorAddress;
41+
}
42+
43+
/*******************************************************************************/
44+
/*!
45+
@brief Destructor for an VCNL4030 sensor.
46+
*/
47+
/*******************************************************************************/
48+
~WipperSnapper_I2C_Driver_VCNL4030() { delete _vcnl4030; }
49+
50+
/*******************************************************************************/
51+
/*!
52+
@brief Initializes the VCNL4030 sensor and begins I2C.
53+
@returns True if initialized successfully, False otherwise.
54+
*/
55+
/*******************************************************************************/
56+
bool begin() {
57+
if (_vcnl4030) {
58+
delete _vcnl4030;
59+
}
60+
_vcnl4030 = new Adafruit_VCNL4030();
61+
if (!_vcnl4030->begin(_sensorAddress, _i2c))
62+
return false;
63+
64+
// Enable and configure sensors, compound result catches any failure
65+
bool result = _vcnl4030->enableALS(true);
66+
result = _vcnl4030->enableProx(true) && result;
67+
result = _vcnl4030->setProxLEDCurrent(VCNL4030_PROX_LED_200MA) && result;
68+
result = _vcnl4030->setProxDuty(VCNL4030_PROX_DUTY_40) && result;
69+
result = _vcnl4030->setProxIntegrationTime(VCNL4030_PROX_IT_8T) && result;
70+
result = _vcnl4030->setProxResolution16Bit(true) && result;
71+
result = _vcnl4030->setALSIntegrationTime(VCNL4030_ALS_IT_100MS) && result;
72+
73+
return result;
74+
}
75+
76+
/*******************************************************************************/
77+
/*!
78+
@brief Reads the VCNL4030 sensor data and caches the results.
79+
@returns True if the sensor was read successfully, False otherwise.
80+
*/
81+
/*******************************************************************************/
82+
bool ReadSensorData() {
83+
unsigned long now = millis();
84+
if (_lastRead != 0 && (now - _lastRead < ONE_SECOND_IN_MILLIS))
85+
return true;
86+
87+
_cachedLight.light = _vcnl4030->readLux();
88+
_cachedProximity.data[0] = (float)_vcnl4030->readProximity();
89+
_lastRead = now;
90+
return true;
91+
}
92+
93+
/*******************************************************************************/
94+
/*!
95+
@brief Gets the VCNL4030's current light reading in lux.
96+
@param lightEvent
97+
Pointer to an Adafruit_Sensor event.
98+
@returns True if the light reading was obtained successfully, False
99+
otherwise.
100+
*/
101+
/*******************************************************************************/
102+
bool getEventLight(sensors_event_t *lightEvent) {
103+
if (!ReadSensorData())
104+
return false;
105+
106+
*lightEvent = _cachedLight;
107+
return true;
108+
}
109+
110+
/*******************************************************************************/
111+
/*!
112+
@brief Gets the VCNL4030's current proximity reading.
113+
@param proximityEvent
114+
Pointer to an Adafruit_Sensor event.
115+
@returns True if the proximity was obtained successfully, False
116+
otherwise.
117+
*/
118+
/*******************************************************************************/
119+
bool getEventProximity(sensors_event_t *proximityEvent) {
120+
if (!ReadSensorData())
121+
return false;
122+
123+
*proximityEvent = _cachedProximity;
124+
return true;
125+
}
126+
127+
protected:
128+
Adafruit_VCNL4030 *_vcnl4030 = nullptr; ///< Pointer to VCNL4030 sensor object
129+
unsigned long _lastRead = 0; ///< Last sensor read time
130+
sensors_event_t _cachedLight = {0}; ///< Cached light reading
131+
sensors_event_t _cachedProximity = {0}; ///< Cached proximity reading
132+
};
133+
134+
#endif // WipperSnapper_I2C_Driver_VCNL4030_H

0 commit comments

Comments
 (0)