diff --git a/platformio.ini b/platformio.ini
index ca41a8021c..f4306c2ea8 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -135,4 +135,5 @@ lib_deps =
adafruit/Adafruit LSM6DS@^4.7.2
mprograms/QMC5883LCompass@^1.2.0
adafruit/Adafruit VEML7700 Library@^2.1.6
- adafruit/Adafruit SHT4x Library@^1.0.4
\ No newline at end of file
+ adafruit/Adafruit SHT4x Library@^1.0.4
+ adafruit/Adafruit TSL2591 Library@^1.4.5
\ No newline at end of file
diff --git a/src/configuration.h b/src/configuration.h
index daaf1a720f..2d0095e22e 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -131,6 +131,7 @@ along with this program. If not, see .
#define AHT10_ADDR 0x38
#define RCWL9620_ADDR 0x57
#define VEML7700_ADDR 0x10
+#define TSL25911_ADDR 0x29
// -----------------------------------------------------------------------------
// ACCELEROMETER
diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h
index 67e2287917..a2ccb18a81 100644
--- a/src/detect/ScanI2C.h
+++ b/src/detect/ScanI2C.h
@@ -45,7 +45,8 @@ class ScanI2C
VEML7700,
RCWL9620,
NCP5623,
- AHT10
+ TSL2591,
+ AHT10,
} DeviceType;
// typedef uint8_t DeviceAddress;
diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp
index d46497d093..d2a6e7848a 100644
--- a/src/detect/ScanI2CTwoWire.cpp
+++ b/src/detect/ScanI2CTwoWire.cpp
@@ -342,6 +342,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3 accelerometer found at address 0x%x\n", (uint8_t)addr.address);
SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555 I2C expander found\n");
SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700 light sensor found\n");
+ SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591 light sensor found\n");
default:
LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address);
diff --git a/src/main.cpp b/src/main.cpp
index f0564ea367..d9b4d84abf 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -533,6 +533,7 @@ void setup()
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::RCWL9620, meshtastic_TelemetrySensorType_RCWL9620)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::VEML7700, meshtastic_TelemetrySensorType_VEML7700)
+ SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::TSL2591, meshtastic_TelemetrySensorType_TSL25911FN)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::SHT4X, meshtastic_TelemetrySensorType_SHT4X)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::AHT10, meshtastic_TelemetrySensorType_AHT10)
diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp
index 6d58460f49..5ecfe73289 100644
--- a/src/modules/Telemetry/EnvironmentTelemetry.cpp
+++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp
@@ -29,6 +29,7 @@
#include "Sensor/SHT31Sensor.h"
#include "Sensor/SHT4XSensor.h"
#include "Sensor/SHTC3Sensor.h"
+#include "Sensor/TSL2591Sensor.h"
#include "Sensor/VEML7700Sensor.h"
BMP085Sensor bmp085Sensor;
@@ -40,6 +41,7 @@ SHTC3Sensor shtc3Sensor;
LPS22HBSensor lps22hbSensor;
SHT31Sensor sht31Sensor;
VEML7700Sensor veml7700Sensor;
+TSL2591Sensor tsl2591Sensor;
SHT4XSensor sht4xSensor;
RCWL9620Sensor rcwl9620Sensor;
AHT10Sensor aht10Sensor;
@@ -65,7 +67,7 @@ int32_t EnvironmentTelemetryModule::runOnce()
*/
// moduleConfig.telemetry.environment_measurement_enabled = 1;
- // moduleConfig.telemetry.environment_screen_enabled = 1;
+ // moduleConfig.telemetry.environment_screen_enabled = 1;
// moduleConfig.telemetry.environment_update_interval = 45;
if (!(moduleConfig.telemetry.environment_measurement_enabled || moduleConfig.telemetry.environment_screen_enabled)) {
@@ -105,6 +107,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
result = ina260Sensor.runOnce();
if (veml7700Sensor.hasSensor())
result = veml7700Sensor.runOnce();
+ if (tsl2591Sensor.hasSensor())
+ result = tsl2591Sensor.runOnce();
if (rcwl9620Sensor.hasSensor())
result = rcwl9620Sensor.runOnce();
if (aht10Sensor.hasSensor())
@@ -291,6 +295,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
valid = valid && veml7700Sensor.getMetrics(&m);
hasSensor = true;
}
+ if (tsl2591Sensor.hasSensor()) {
+ valid = valid && tsl2591Sensor.getMetrics(&m);
+ hasSensor = true;
+ }
if (rcwl9620Sensor.hasSensor()) {
valid = valid && rcwl9620Sensor.getMetrics(&m);
hasSensor = true;
diff --git a/src/modules/Telemetry/Sensor/TSL2591Sensor.cpp b/src/modules/Telemetry/Sensor/TSL2591Sensor.cpp
new file mode 100644
index 0000000000..0a3f5d685c
--- /dev/null
+++ b/src/modules/Telemetry/Sensor/TSL2591Sensor.cpp
@@ -0,0 +1,38 @@
+#include "TSL2591Sensor.h"
+#include "../mesh/generated/meshtastic/telemetry.pb.h"
+#include "TelemetrySensor.h"
+#include "configuration.h"
+#include
+#include
+
+TSL2591Sensor::TSL2591Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_TSL25911FN, "TSL2591") {}
+
+int32_t TSL2591Sensor::runOnce()
+{
+ LOG_INFO("Init sensor: %s\n", sensorName);
+ if (!hasSensor()) {
+ return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
+ }
+ status = tsl.begin(nodeTelemetrySensorsMap[sensorType].second);
+
+ return initI2CSensor();
+}
+
+void TSL2591Sensor::setup()
+{
+ tsl.setGain(TSL2591_GAIN_MED); // 25x gain
+ tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
+}
+
+bool TSL2591Sensor::getMetrics(meshtastic_Telemetry *measurement)
+{
+ uint32_t lum = tsl.getFullLuminosity();
+ uint16_t ir, full;
+ ir = lum >> 16;
+ full = lum & 0xFFFF;
+
+ measurement->variant.environment_metrics.lux = tsl.calculateLux(full, ir);
+ LOG_INFO("Lux: %f\n", measurement->variant.environment_metrics.lux);
+
+ return true;
+}
\ No newline at end of file
diff --git a/src/modules/Telemetry/Sensor/TSL2591Sensor.h b/src/modules/Telemetry/Sensor/TSL2591Sensor.h
new file mode 100644
index 0000000000..a24d539756
--- /dev/null
+++ b/src/modules/Telemetry/Sensor/TSL2591Sensor.h
@@ -0,0 +1,17 @@
+#include "../mesh/generated/meshtastic/telemetry.pb.h"
+#include "TelemetrySensor.h"
+#include
+
+class TSL2591Sensor : public TelemetrySensor
+{
+ private:
+ Adafruit_TSL2591 tsl;
+
+ protected:
+ virtual void setup() override;
+
+ public:
+ TSL2591Sensor();
+ virtual int32_t runOnce() override;
+ virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
+};
\ No newline at end of file