Skip to content

Commit

Permalink
Merge pull request #349 from tyeth/add-VEML7700
Browse files Browse the repository at this point in the history
Add VEML7700 Lux sensor
  • Loading branch information
brentru authored Oct 14, 2022
2 parents 0f11dc5 + ae7fd17 commit 3234662
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=Adafruit WipperSnapper
version=1.0.0-beta.51
version=1.0.0-beta.52
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino client for Adafruit.io WipperSnapper
paragraph=Arduino client for Adafruit.io WipperSnapper
category=Communication
url=https://github.com/adafruit/Adafruit_IO_Arduino
architectures=*
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library, Adafruit PM25 AQI Sensor, Adafruit LC709203F, Adafruit seesaw Library
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library, Adafruit PM25 AQI Sensor, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit seesaw Library
11 changes: 11 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
_tsl2591->configureDriver(msgDeviceInitReq);
drivers.push_back(_tsl2591);
WS_DEBUG_PRINTLN("TSL2591 Initialized Successfully!");
} else if (strcmp("veml7700", msgDeviceInitReq->i2c_device_name) == 0) {
_veml7700 = new WipperSnapper_I2C_Driver_VEML7700(this->_i2c, i2cAddress);
if (!_veml7700->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize VEML7700!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_veml7700->configureDriver(msgDeviceInitReq);
drivers.push_back(_veml7700);
WS_DEBUG_PRINTLN("VEML7700 Initialized Successfully!");
} else if (strcmp("scd40", msgDeviceInitReq->i2c_device_name) == 0) {
_scd40 = new WipperSnapper_I2C_Driver_SCD40(this->_i2c, i2cAddress);
if (!_scd40->begin()) {
Expand Down
2 changes: 2 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "drivers/WipperSnapper_I2C_Driver_SI7021.h"
#include "drivers/WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor.h"
#include "drivers/WipperSnapper_I2C_Driver_TSL2591.h"
#include "drivers/WipperSnapper_I2C_Driver_VEML7700.h"

#define I2C_TIMEOUT_MS 50 ///< Default I2C timeout, in milliseconds.

Expand Down Expand Up @@ -85,6 +86,7 @@ class WipperSnapper_Component_I2C {
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
WipperSnapper_I2C_Driver_MCP9601 *_mcp9601 = nullptr;
WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
WipperSnapper_I2C_Driver_SCD40 *_scd40 = nullptr;
WipperSnapper_I2C_Driver_PM25 *_pm25 = nullptr;
WipperSnapper_I2C_Driver_SI7021 *_si7021 = nullptr;
Expand Down
84 changes: 84 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_VEML7700.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*!
* @file WipperSnapper_I2C_Driver_VEML7700.h
*
* Device driver for the VEML7700 digital luminosity (light) sensor.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) Tyeth Gundry 2022 for Adafruit Industries.
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef WipperSnapper_I2C_Driver_VEML7700_H
#define WipperSnapper_I2C_Driver_VEML7700_H

#include "WipperSnapper_I2C_Driver.h"
#include <Adafruit_VEML7700.h>

/**************************************************************************/
/*!
@brief Class that provides a driver interface for a VEML7700 sensor.
*/
/**************************************************************************/
class WipperSnapper_I2C_Driver_VEML7700 : public WipperSnapper_I2C_Driver {
public:
/*******************************************************************************/
/*!
@brief Constructor for a VEML7700 sensor.
@param i2c
The I2C interface.
@param sensorAddress
The 7-bit I2C address of the sensor.
*/
/*******************************************************************************/
WipperSnapper_I2C_Driver_VEML7700(TwoWire *i2c, uint16_t sensorAddress)
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
_i2c = i2c;
_sensorAddress = sensorAddress;
}

/*******************************************************************************/
/*!
@brief Destructor for an VEML7700 sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_VEML7700() { delete _veml; }

/*******************************************************************************/
/*!
@brief Initializes the VEML7700 sensor and begins I2C.
@returns True if initialized successfully, False otherwise.
*/
/*******************************************************************************/
bool begin() {
_veml = new Adafruit_VEML7700();
// Attempt to initialize and configure VEML7700
return _veml->begin(_i2c);
}

/*******************************************************************************/
/*!
@brief Performs a light sensor read using the Adafruit
Unified Sensor API. Always uses VEML_LUX_AUTO,
controlling sensor integration time and gain.
@param lightEvent
Light sensor reading, in lux.
@returns True if the sensor event was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventLight(sensors_event_t *lightEvent) {
// Get sensor event populated in lux via AUTO integration and gain
lightEvent->light = _veml->readLux(VEML_LUX_AUTO);

return true;
}

protected:
Adafruit_VEML7700 *_veml; ///< Pointer to VEML7700 light sensor object
};

#endif // WipperSnapper_I2C_Driver_VEML7700

0 comments on commit 3234662

Please sign in to comment.