Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LTR329 and LTR303 #501

Merged
merged 6 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
category=Communication
url=https://github.com/adafruit/Adafruit_IO_Arduino
architectures=*
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, 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 PM25 AQI Sensor, 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
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 PM25 AQI Sensor, 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
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ lib_deps =
adafruit/Adafruit HTU21DF Library
adafruit/Adafruit HTU31D Library
adafruit/Adafruit LTR390 Library
adafruit/Adafruit LTR329 and LTR303
adafruit/Adafruit PCT2075
adafruit/Adafruit SCD30
adafruit/Adafruit SGP30 Sensor
Expand Down
13 changes: 13 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
_ltr390->configureDriver(msgDeviceInitReq);
drivers.push_back(_ltr390);
WS_DEBUG_PRINTLN("LTR390 Initialized Successfully!");
} else if ((strcmp("ltr329", msgDeviceInitReq->i2c_device_name) == 0) ||
(strcmp("ltr303", msgDeviceInitReq->i2c_device_name) == 0)) {
_ltr329 =
new WipperSnapper_I2C_Driver_LTR329_LTR303(this->_i2c, i2cAddress);
if (!_ltr329->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize LTR329/303");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_ltr329->configureDriver(msgDeviceInitReq);
drivers.push_back(_ltr329);
WS_DEBUG_PRINTLN("LTR329/303 Initialized Successfully!");
} else if (strcmp("sgp30", msgDeviceInitReq->i2c_device_name) == 0) {
_sgp30 = new WipperSnapper_I2C_Driver_SGP30(this->_i2c, i2cAddress);
if (!_sgp30->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 @@ -37,6 +37,7 @@
#include "drivers/WipperSnapper_I2C_Driver_LPS22HB.h"
#include "drivers/WipperSnapper_I2C_Driver_LPS25HB.h"
#include "drivers/WipperSnapper_I2C_Driver_LPS3XHW.h"
#include "drivers/WipperSnapper_I2C_Driver_LTR329_LTR303.h"
#include "drivers/WipperSnapper_I2C_Driver_LTR390.h"
#include "drivers/WipperSnapper_I2C_Driver_MAX17048.h"
#include "drivers/WipperSnapper_I2C_Driver_MCP9808.h"
Expand Down Expand Up @@ -120,6 +121,7 @@ class WipperSnapper_Component_I2C {
WipperSnapper_I2C_Driver_HTU21D *_htu21d = nullptr;
WipperSnapper_I2C_Driver_HTU31D *_htu31d = nullptr;
WipperSnapper_I2C_Driver_INA219 *_ina219 = nullptr;
WipperSnapper_I2C_Driver_LTR329_LTR303 *_ltr329 = nullptr;
WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr;
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
Expand Down
123 changes: 123 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_LTR329_LTR303.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*!
* @file WipperSnapper_I2C_Driver_LTR329_LTR303.h
*
* Device driver for the LTR329 + LTR303 (329+interrupt) light sensors.
*
* 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 2023 for Adafruit Industries.
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef WipperSnapper_I2C_Driver_LTR329_LTR303_H
#define WipperSnapper_I2C_Driver_LTR329_LTR303_H

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

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

/*******************************************************************************/
/*!
@brief Destructor for an LTR329/303 sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_LTR329_LTR303() { delete _LTR329; }

/*******************************************************************************/
/*!
@brief Initializes the LTR329/303 sensor and begins I2C.
@returns True if initialized successfully, False otherwise.
*/
/*******************************************************************************/
bool begin() {
_LTR329 = new Adafruit_LTR329();
// Attempt to initialize LTR329
if (!_LTR329->begin(_i2c))
return false;

// Configure LTR329 sensor - tested on a dull British day Oct'23 @7kLux
// Matches similar lux value from LTR390 with default configuration.
_LTR329->setGain(LTR3XX_GAIN_48);
_LTR329->setIntegrationTime(LTR3XX_INTEGTIME_100);
_LTR329->setMeasurementRate(LTR3XX_MEASRATE_100);
_delayBetweenReads = 110; // 100ms measurement time + 10ms fudge-factor
return true;
}

/*******************************************************************************/
/*!
@brief Reads the LTR329's ambient light level ([Visible+IR] - IR-only)
@param lightEvent
Light sensor reading.
@returns True if the sensor event was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventLight(sensors_event_t *lightEvent) {
if (!_LTR329->newDataAvailable())
return false;

uint16_t visible_plus_ir, infrared;
_LTR329->readBothChannels(visible_plus_ir, infrared);
lightEvent->light = visible_plus_ir - infrared;
return true;
}

/*******************************************************************************/
/*!
@brief Reads the LTR329's infrared value into an event.
@param rawEvent
Pointer to an adafruit sensor event.
@returns True if the sensor event was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventRaw(sensors_event_t *rawEvent) {

if (!_LTR329->newDataAvailable()) {
delay(
_delayBetweenReads); // Raw comes after Light event and needs new data
if (!_LTR329->newDataAvailable())
return false;
}

uint16_t visible_plus_ir, infrared;
_LTR329->readBothChannels(visible_plus_ir, infrared);
rawEvent->data[0] = (float)infrared;
return true;
}

protected:
Adafruit_LTR329 *_LTR329; ///< Pointer to LTR329 light sensor object

/**
* @brief The delay between consecutive reads in milliseconds.
*/
uint16_t _delayBetweenReads;
};

#endif // WipperSnapper_I2C_Driver_LTR329_LTR303