Skip to content

Commit 34cd2bd

Browse files
committed
Add VCNL4200
1 parent 16bc28a commit 34cd2bd

File tree

5 files changed

+122
-1
lines changed

5 files changed

+122
-1
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
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 HDC302x, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, 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, STM32duino VL53L4CD, STM32duino VL53L4CX, 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 HDC302x, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, 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, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, 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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ lib_deps =
4343
adafruit/Adafruit Si7021 Library
4444
adafruit/Adafruit VCNL4020 Library
4545
adafruit/Adafruit VCNL4040
46+
adafruit/Adafruit VCNL4200 Library
4647
adafruit/Adafruit MCP3421
4748
adafruit/Adafruit MCP9808 Library
4849
adafruit/Adafruit MCP9600 Library

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
553553
_vcnl4040->configureDriver(msgDeviceInitReq);
554554
drivers.push_back(_vcnl4040);
555555
WS_DEBUG_PRINTLN("VCNL4040 Initialized Successfully!");
556+
} else if (strcmp("vcnl4200", msgDeviceInitReq->i2c_device_name) == 0) {
557+
_vcnl4200 = new WipperSnapper_I2C_Driver_VCNL4200(this->_i2c, i2cAddress);
558+
if (!_vcnl4200->begin()) {
559+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize VCNL4200!");
560+
_busStatusResponse =
561+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
562+
return false;
563+
}
564+
_vcnl4200->configureDriver(msgDeviceInitReq);
565+
drivers.push_back(_vcnl4200);
566+
WS_DEBUG_PRINTLN("VCNL4200 Initialized Successfully!");
556567
} else if (strcmp("veml7700", msgDeviceInitReq->i2c_device_name) == 0) {
557568
_veml7700 = new WipperSnapper_I2C_Driver_VEML7700(this->_i2c, i2cAddress);
558569
if (!_veml7700->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "drivers/WipperSnapper_I2C_Driver_TSL2591.h"
6565
#include "drivers/WipperSnapper_I2C_Driver_VCNL4020.h"
6666
#include "drivers/WipperSnapper_I2C_Driver_VCNL4040.h"
67+
#include "drivers/WipperSnapper_I2C_Driver_VCNL4200.h"
6768
#include "drivers/WipperSnapper_I2C_Driver_VEML7700.h"
6869
#include "drivers/WipperSnapper_I2C_Driver_VL53L0X.h"
6970
#include "drivers/WipperSnapper_I2C_Driver_VL53L1X.h"
@@ -159,6 +160,7 @@ class WipperSnapper_Component_I2C {
159160
WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
160161
WipperSnapper_I2C_Driver_VCNL4020 *_vcnl4020 = nullptr;
161162
WipperSnapper_I2C_Driver_VCNL4040 *_vcnl4040 = nullptr;
163+
WipperSnapper_I2C_Driver_VCNL4200 *_vcnl4200 = nullptr;
162164
WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
163165
WipperSnapper_I2C_Driver_SCD4X *_scd40 = nullptr;
164166
WipperSnapper_I2C_Driver_SEN5X *_sen5x = nullptr;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_VCNL4200.h
3+
*
4+
* Device driver for the VCNL4200 light + proximity 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 2024 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WipperSnapper_I2C_Driver_VCNL4200_H
16+
#define WipperSnapper_I2C_Driver_VCNL4200_H
17+
18+
#include "WipperSnapper_I2C_Driver.h"
19+
#include <Adafruit_VCNL4200.h>
20+
21+
/**************************************************************************/
22+
/*!
23+
@brief Class that provides a driver interface for a VCNL4200 sensor.
24+
*/
25+
/**************************************************************************/
26+
class WipperSnapper_I2C_Driver_VCNL4200 : public WipperSnapper_I2C_Driver {
27+
public:
28+
/*******************************************************************************/
29+
/*!
30+
@brief Constructor for a VCNL4200 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_VCNL4200(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 VCNL4200 sensor.
46+
*/
47+
/*******************************************************************************/
48+
~WipperSnapper_I2C_Driver_VCNL4200() { delete _vcnl4200; }
49+
50+
/*******************************************************************************/
51+
/*!
52+
@brief Initializes the VCNL4200 sensor and begins I2C.
53+
@returns True if initialized successfully, False otherwise.
54+
*/
55+
/*******************************************************************************/
56+
bool begin() {
57+
_vcnl4200 = new Adafruit_VCNL4200();
58+
bool status = false;
59+
// Attempt to initialize and configure VCNL4200
60+
if (!_vcnl4200->begin(_sensorAddress, _i2c)) {
61+
return false;
62+
}
63+
status = _vcnl4200->setALSshutdown(false);
64+
status &= _vcnl4200->setProxShutdown(false);
65+
status &= _vcnl4200->setProxHD(true); // 16bit instead of 12bit
66+
status &= _vcnl4200->setALSIntegrationTime(VCNL4200_ALS_IT_400MS);
67+
status &= _vcnl4200->setProxDuty(VCNL4200_PS_DUTY_1_160);
68+
status &= _vcnl4200->setProxLEDCurrent(VCNL4200_LED_I_200MA);
69+
status &= _vcnl4200->setProxIntegrationTime(VCNL4200_PS_IT_9T);
70+
return status;
71+
}
72+
73+
/*******************************************************************************/
74+
/*!
75+
@brief Performs a light sensor read using the Adafruit
76+
Unified Sensor API.
77+
@param lightEvent
78+
Light sensor reading, in lux.
79+
@returns True if the sensor event was obtained successfully, False
80+
otherwise.
81+
*/
82+
/*******************************************************************************/
83+
bool getEventLight(sensors_event_t *lightEvent) {
84+
// Get sensor event populated in lux via AUTO integration and gain
85+
lightEvent->light = _vcnl4200->readALSdata();
86+
return true;
87+
}
88+
89+
/*******************************************************************************/
90+
/*!
91+
@brief Reads the VCNL4200's proximity value into an event (no unit).
92+
@param proximityEvent
93+
Pointer to an Adafruit_Sensor event.
94+
@returns True if the proximity was obtained successfully, False
95+
otherwise.
96+
*/
97+
/*******************************************************************************/
98+
bool getEventProximity(sensors_event_t *proximityEvent) {
99+
proximityEvent->data[0] = (float)_vcnl4200->readProxData();
100+
return true;
101+
}
102+
103+
protected:
104+
Adafruit_VCNL4200 *_vcnl4200; ///< Pointer to VCNL4200 light sensor object
105+
};
106+
107+
#endif // WipperSnapper_I2C_Driver_VCNL4200

0 commit comments

Comments
 (0)