Skip to content

Commit 0a24b2c

Browse files
authored
Merge pull request #501 from tyeth/add-LTR329-303
Add LTR329 and LTR303
2 parents ae916c7 + 1840b86 commit 0a24b2c

File tree

5 files changed

+140
-1
lines changed

5 files changed

+140
-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_IO_Arduino
99
architectures=*
10-
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
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 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

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ lib_deps =
3333
adafruit/Adafruit HTU21DF Library
3434
adafruit/Adafruit HTU31D Library
3535
adafruit/Adafruit LTR390 Library
36+
adafruit/Adafruit LTR329 and LTR303
3637
adafruit/Adafruit PCT2075
3738
adafruit/Adafruit SCD30
3839
adafruit/Adafruit SGP30 Sensor

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,19 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
373373
_ltr390->configureDriver(msgDeviceInitReq);
374374
drivers.push_back(_ltr390);
375375
WS_DEBUG_PRINTLN("LTR390 Initialized Successfully!");
376+
} else if ((strcmp("ltr329", msgDeviceInitReq->i2c_device_name) == 0) ||
377+
(strcmp("ltr303", msgDeviceInitReq->i2c_device_name) == 0)) {
378+
_ltr329 =
379+
new WipperSnapper_I2C_Driver_LTR329_LTR303(this->_i2c, i2cAddress);
380+
if (!_ltr329->begin()) {
381+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize LTR329/303");
382+
_busStatusResponse =
383+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
384+
return false;
385+
}
386+
_ltr329->configureDriver(msgDeviceInitReq);
387+
drivers.push_back(_ltr329);
388+
WS_DEBUG_PRINTLN("LTR329/303 Initialized Successfully!");
376389
} else if (strcmp("sgp30", msgDeviceInitReq->i2c_device_name) == 0) {
377390
_sgp30 = new WipperSnapper_I2C_Driver_SGP30(this->_i2c, i2cAddress);
378391
if (!_sgp30->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "drivers/WipperSnapper_I2C_Driver_LPS22HB.h"
3838
#include "drivers/WipperSnapper_I2C_Driver_LPS25HB.h"
3939
#include "drivers/WipperSnapper_I2C_Driver_LPS3XHW.h"
40+
#include "drivers/WipperSnapper_I2C_Driver_LTR329_LTR303.h"
4041
#include "drivers/WipperSnapper_I2C_Driver_LTR390.h"
4142
#include "drivers/WipperSnapper_I2C_Driver_MAX17048.h"
4243
#include "drivers/WipperSnapper_I2C_Driver_MCP9808.h"
@@ -120,6 +121,7 @@ class WipperSnapper_Component_I2C {
120121
WipperSnapper_I2C_Driver_HTU21D *_htu21d = nullptr;
121122
WipperSnapper_I2C_Driver_HTU31D *_htu31d = nullptr;
122123
WipperSnapper_I2C_Driver_INA219 *_ina219 = nullptr;
124+
WipperSnapper_I2C_Driver_LTR329_LTR303 *_ltr329 = nullptr;
123125
WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr;
124126
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
125127
WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_LTR329_LTR303.h
3+
*
4+
* Device driver for the LTR329 + LTR303 (329+interrupt) light sensors.
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 2023 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WipperSnapper_I2C_Driver_LTR329_LTR303_H
16+
#define WipperSnapper_I2C_Driver_LTR329_LTR303_H
17+
18+
#include "WipperSnapper_I2C_Driver.h"
19+
#include <Adafruit_LTR329_LTR303.h>
20+
21+
/**************************************************************************/
22+
/*!
23+
@brief Class that provides a driver interface for a LTR329/303 sensor.
24+
*/
25+
/**************************************************************************/
26+
class WipperSnapper_I2C_Driver_LTR329_LTR303 : public WipperSnapper_I2C_Driver {
27+
public:
28+
/*******************************************************************************/
29+
/*!
30+
@brief Constructor for a LTR329/303 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_LTR329_LTR303(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 LTR329/303 sensor.
46+
*/
47+
/*******************************************************************************/
48+
~WipperSnapper_I2C_Driver_LTR329_LTR303() { delete _LTR329; }
49+
50+
/*******************************************************************************/
51+
/*!
52+
@brief Initializes the LTR329/303 sensor and begins I2C.
53+
@returns True if initialized successfully, False otherwise.
54+
*/
55+
/*******************************************************************************/
56+
bool begin() {
57+
_LTR329 = new Adafruit_LTR329();
58+
// Attempt to initialize LTR329
59+
if (!_LTR329->begin(_i2c))
60+
return false;
61+
62+
// Configure LTR329 sensor - tested on a dull British day Oct'23 @7kLux
63+
// Matches similar lux value from LTR390 with default configuration.
64+
_LTR329->setGain(LTR3XX_GAIN_48);
65+
_LTR329->setIntegrationTime(LTR3XX_INTEGTIME_100);
66+
_LTR329->setMeasurementRate(LTR3XX_MEASRATE_100);
67+
_delayBetweenReads = 110; // 100ms measurement time + 10ms fudge-factor
68+
return true;
69+
}
70+
71+
/*******************************************************************************/
72+
/*!
73+
@brief Reads the LTR329's ambient light level ([Visible+IR] - IR-only)
74+
@param lightEvent
75+
Light sensor reading.
76+
@returns True if the sensor event was obtained successfully, False
77+
otherwise.
78+
*/
79+
/*******************************************************************************/
80+
bool getEventLight(sensors_event_t *lightEvent) {
81+
if (!_LTR329->newDataAvailable())
82+
return false;
83+
84+
uint16_t visible_plus_ir, infrared;
85+
_LTR329->readBothChannels(visible_plus_ir, infrared);
86+
lightEvent->light = visible_plus_ir - infrared;
87+
return true;
88+
}
89+
90+
/*******************************************************************************/
91+
/*!
92+
@brief Reads the LTR329's infrared value into an event.
93+
@param rawEvent
94+
Pointer to an adafruit sensor event.
95+
@returns True if the sensor event was obtained successfully, False
96+
otherwise.
97+
*/
98+
/*******************************************************************************/
99+
bool getEventRaw(sensors_event_t *rawEvent) {
100+
101+
if (!_LTR329->newDataAvailable()) {
102+
delay(
103+
_delayBetweenReads); // Raw comes after Light event and needs new data
104+
if (!_LTR329->newDataAvailable())
105+
return false;
106+
}
107+
108+
uint16_t visible_plus_ir, infrared;
109+
_LTR329->readBothChannels(visible_plus_ir, infrared);
110+
rawEvent->data[0] = (float)infrared;
111+
return true;
112+
}
113+
114+
protected:
115+
Adafruit_LTR329 *_LTR329; ///< Pointer to LTR329 light sensor object
116+
117+
/**
118+
* @brief The delay between consecutive reads in milliseconds.
119+
*/
120+
uint16_t _delayBetweenReads;
121+
};
122+
123+
#endif // WipperSnapper_I2C_Driver_LTR329_LTR303

0 commit comments

Comments
 (0)