Skip to content

Commit

Permalink
Add support for I2C sensor TLS2591
Browse files Browse the repository at this point in the history
Add support for I2C sensor TLS2591 Light Intensity sensor (#6873)
  • Loading branch information
arendst committed Nov 11, 2019
1 parent d972ca7 commit b31f3d8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 68 deletions.
3 changes: 2 additions & 1 deletion I2CDEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Index | Define | Driver | Device | Address(es) | Description
10 | USE_BMP | xsns_09 | BME680 | 0x76 - 0x77 | Pressure, temperature, humidity and gas sensor
11 | USE_BH1750 | xsns_10 | BH1750 | 0x23, 0x5C | Ambient light intensity sensor
12 | USE_VEML6070 | xsns_11 | VEML6070 | 0x38 - 0x39 | Ultra violet light intensity sensor
13 | USE_ADS1115_I2CDEV | xsns_12 | ADS1115 | 0x48 - 0x4B | 4-channel 16-bit A/D converter
13 | USE_ADS1115 | xsns_12 | ADS1115 | 0x48 - 0x4B | 4-channel 16-bit A/D converter
14 | USE_INA219 | xsns_13 | INA219 | 0x40 - 0x41, 0x44 - 0x45 | Low voltage current sensor
15 | USE_SHT3X | xsns_14 | SHT3X | 0x44 - 0x45 | Temperature and Humidity sensor
Expand Down Expand Up @@ -63,3 +62,5 @@ Index | Define | Driver | Device | Address(es) | Description
37 | USE_24C256 | xdrv_10 | 24C256 | 0x50 | Scripter EEPROM storage
38 | USE_DISPLAY_ILI9488 | xdsp_08 | FT6236 | 0x38 | Touch panel controller
39 | USE_DISPLAY_RA8876 | xdsp_10 | FT5316 | 0x38 | Touch panel controller
40 | USE_TSL2591 | xsns_57 | TLS2591 | 0x29 | Light intensity sensor

5 changes: 3 additions & 2 deletions tasmota/_changelog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* Change supported PCF8574 I2C address range to 0x20 - 0x26 allowing other I2C devices with address 0x27 to be used at the same time
* Change supported PCF8574A I2C address range to 0x39 - 0x3F allowing other I2C devices with address 0x38 to be used at the same time
* Change supported MCP230xx I2C address range to 0x20 - 0x26 allowing other I2C devices with address 0x27 to be used at the same time
* Add Keep last channels values when Color command end with '=' #6799
* Add Keep last channels values when Color command end with '=' (#6799)
* Add support for I2C sensor TLS2591 Light Intensity sensor (#6873)
*
* 7.0.0.3 20191103
* Initial support for I2C driver runtime control using command I2CDriver and document I2CDEVICES.md
* Add command I2cDriver for I2C driver runtime control using document I2CDEVICES.md
* Fix random crash caused by UPNP flood
* Add support for Honeywell HPMA115S0 particle concentration sensor by David Hunt (#6843)
* Remove driver xsns_12_ads1115_i2cdev replaced by xsns_12_ads1115
Expand Down
80 changes: 40 additions & 40 deletions tasmota/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
#define USE_BUZZER // Add support for a buzzer (+0k6 code)
#define USE_ARILUX_RF // Add support for Arilux RF remote controller (+0k8 code, 252 iram (non 2.3.0))
//#define USE_SHUTTER // Add Shutter support for up to 4 shutter with different motortypes (+6k code)
//#define USE_DEEPSLEEP // Add support for deepsleep (+1k code)
#define USE_DEEPSLEEP // Add support for deepsleep (+1k code)
//#define USE_EXS_DIMMER // Add support for ES-Store WiFi Dimmer (+1k5 code)
// #define EXS_MCU_CMNDS // Add command to send MCU commands (+0k8 code)

Expand Down Expand Up @@ -371,56 +371,56 @@
#define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram)

#ifdef USE_I2C
#define USE_SHT // Enable SHT1X sensor (+1k4 code)
#define USE_HTU // Enable HTU21/SI7013/SI7020/SI7021 sensor (I2C address 0x40) (+1k5 code)
#define USE_BMP // Enable BMP085/BMP180/BMP280/BME280 sensors (I2C addresses 0x76 and 0x77) (+4k4 code)
#define USE_SHT // [I2cDriver8] Enable SHT1X sensor (+1k4 code)
#define USE_HTU // [I2cDriver9] Enable HTU21/SI7013/SI7020/SI7021 sensor (I2C address 0x40) (+1k5 code)
#define USE_BMP // [I2cDriver10] Enable BMP085/BMP180/BMP280/BME280 sensors (I2C addresses 0x76 and 0x77) (+4k4 code)
// #define USE_BME680 // Enable support for BME680 sensor using Bosch BME680 library (+4k code)
#define USE_BH1750 // Enable BH1750 sensor (I2C address 0x23 or 0x5C) (+0k5 code)
// #define USE_VEML6070 // Enable VEML6070 sensor (I2C addresses 0x38 and 0x39) (+1k5 code)
#define USE_BH1750 // [I2cDriver11] Enable BH1750 sensor (I2C address 0x23 or 0x5C) (+0k5 code)
// #define USE_VEML6070 // [I2cDriver12] Enable VEML6070 sensor (I2C addresses 0x38 and 0x39) (+1k5 code)
#define USE_VEML6070_RSET 270000 // VEML6070, Rset in Ohm used on PCB board, default 270K = 270000ohm, range for this sensor: 220K ... 1Meg
#define USE_VEML6070_SHOW_RAW // VEML6070, shows the raw value of UV-A
// #define USE_ADS1115 // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
// #define USE_INA219 // Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code)
// #define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
#define USE_SHT3X // Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code)
// #define USE_TSL2561 // Enable TSL2561 sensor (I2C address 0x29, 0x39 or 0x49) using library Joba_Tsl2561 (+2k3 code)
// #define USE_TSL2591 // Add I2C code for TSL2591 sensor
// #define USE_MGS // Enable Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
// #define USE_ADS1115 // [I2cDriver13] Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
// #define USE_INA219 // [I2cDriver14] Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code)
// #define USE_INA226 // [I2cDriver35] Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
#define USE_SHT3X // [I2cDriver15] Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code)
// #define USE_TSL2561 // [I2cDriver16] Enable TSL2561 sensor (I2C address 0x29, 0x39 or 0x49) using library Joba_Tsl2561 (+2k3 code)
// #define USE_TSL2591 // [I2cDriver40] Enable TSL2591 sensor (I2C address 0x29) using library Adafruit_TSL2591 (+1k6 code)
// #define USE_MGS // [I2cDriver17] Enable Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
#define MGS_SENSOR_ADDR 0x04 // Default Mutichannel Gas sensor i2c address
// #define USE_SGP30 // Enable SGP30 sensor (I2C address 0x58) (+1k1 code)
// #define USE_SI1145 // Enable SI1145/46/47 sensor (I2C address 0x60) (+1k code)
#define USE_LM75AD // Enable LM75AD sensor (I2C addresses 0x48 - 0x4F) (+0k5 code)
// #define USE_APDS9960 // Enable APDS9960 Proximity Sensor (I2C address 0x39). Disables SHT and VEML6070 (+4k7 code)
// #define USE_MCP230xx // Enable MCP23008/MCP23017 - Must define I2C Address in #define USE_MCP230xx_ADDR below - range 0x20 - 0x27 (+4k7 code)
// #define USE_SGP30 // [I2cDriver18] Enable SGP30 sensor (I2C address 0x58) (+1k1 code)
// #define USE_SI1145 // [I2cDriver19] Enable SI1145/46/47 sensor (I2C address 0x60) (+1k code)
#define USE_LM75AD // [I2cDriver20] Enable LM75AD sensor (I2C addresses 0x48 - 0x4F) (+0k5 code)
// #define USE_APDS9960 // [I2cDriver21] Enable APDS9960 Proximity Sensor (I2C address 0x39). Disables SHT and VEML6070 (+4k7 code)
// #define USE_MCP230xx // [I2cDriver22] Enable MCP23008/MCP23017 - Must define I2C Address in #define USE_MCP230xx_ADDR below - range 0x20 - 0x27 (+4k7 code)
// #define USE_MCP230xx_ADDR 0x20 // Enable MCP23008/MCP23017 I2C Address to use (Must be within range 0x20 through 0x26 - set according to your wired setup)
// #define USE_MCP230xx_OUTPUT // Enable MCP23008/MCP23017 OUTPUT support through sensor29 commands (+1k5 code)
// #define USE_MCP230xx_DISPLAYOUTPUT // Enable MCP23008/MCP23017 to display state of OUTPUT pins on Web UI (+0k2 code)
// #define USE_PCA9685 // Enable PCA9685 I2C HW PWM Driver - Must define I2C Address in #define USE_PCA9685_ADDR below - range 0x40 - 0x47 (+1k4 code)
// #define USE_PCA9685 // [I2cDriver1] Enable PCA9685 I2C HW PWM Driver - Must define I2C Address in #define USE_PCA9685_ADDR below - range 0x40 - 0x47 (+1k4 code)
// #define USE_PCA9685_ADDR 0x40 // Enable PCA9685 I2C Address to use (Must be within range 0x40 through 0x47 - set according to your wired setup)
// #define USE_PCA9685_FREQ 50 // Define default PWM frequency in Hz to be used (must be within 24 to 1526) - If other value is used, it will rever to 50Hz
// #define USE_MPR121 // Enable MPR121 controller (I2C addresses 0x5A, 0x5B, 0x5C and 0x5D) in input mode for touch buttons (+1k3 code)
// #define USE_CCS811 // Enable CCS811 sensor (I2C address 0x5A) (+2k2 code)
// #define USE_MPU6050 // Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+3K3 of code and 188 Bytes of RAM)
// #define USE_MPR121 // [I2cDriver23] Enable MPR121 controller (I2C addresses 0x5A, 0x5B, 0x5C and 0x5D) in input mode for touch buttons (+1k3 code)
// #define USE_CCS811 // [I2cDriver24] Enable CCS811 sensor (I2C address 0x5A) (+2k2 code)
// #define USE_MPU6050 // [I2cDriver25] Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+3K3 of code and 188 Bytes of RAM)
// #define USE_MPU6050_DMP // Enable in MPU6050 to use the DMP on the chip, should create better results (+8k6 of code)
// #define USE_DS3231 // Enable DS3231 external RTC in case no Wifi is avaliable. See docs in the source file (+1k2 code)
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 external RTC in case no Wifi is avaliable. See docs in the source file (+1k2 code)
// #define USE_RTC_ADDR 0x68 // Default I2C address 0x68
// #define USE_MGC3130 // Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem)
// #define USE_MAX44009 // Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code)
// #define USE_SCD30 // Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code)
// #define USE_SPS30 // Enable Sensiron SPS30 particle sensor (I2C address 0x69) (+1.7 code)
#define USE_ADE7953 // Enable ADE7953 Energy monitor as used on Shelly 2.5 (I2C address 0x38) (+1k5)
// #define USE_VL53L0X // Enable VL53L0x time of flight sensor (I2C address 0x29) (+4k code)
// #define USE_MLX90614 // Enable MLX90614 ir temp sensor (I2C address 0x5a) (+0.6k code)
// #define USE_CHIRP // Enable CHIRP soil moisture sensor (variable I2C address, default 0x20)
// #define USE_PAJ7620 // Enable PAJ7620 gesture sensor (I2C address 0x73) (+2.5k code)
// #define USE_PCF8574 // Enable PCF8574 I/O Expander (I2C addresses 0x20 - 0x26 and 0x39 - 0x3F) (+1k9 code)
// #define USE_HIH6 // Enable Honeywell HIH Humidity and Temperature sensor (I2C address 0x27) (+0k6)
// #define USE_MGC3130 // [I2cDriver27] Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem)
// #define USE_MAX44009 // [I2cDriver28] Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code)
// #define USE_SCD30 // [I2cDriver29] Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code)
// #define USE_SPS30 // [I2cDriver30] Enable Sensiron SPS30 particle sensor (I2C address 0x69) (+1.7 code)
#define USE_ADE7953 // [I2cDriver7] Enable ADE7953 Energy monitor as used on Shelly 2.5 (I2C address 0x38) (+1k5)
// #define USE_VL53L0X // [I2cDriver31] Enable VL53L0x time of flight sensor (I2C address 0x29) (+4k code)
// #define USE_MLX90614 // [I2cDriver32] Enable MLX90614 ir temp sensor (I2C address 0x5a) (+0.6k code)
// #define USE_CHIRP // [I2cDriver33] Enable CHIRP soil moisture sensor (variable I2C address, default 0x20)
// #define USE_PAJ7620 // [I2cDriver34] Enable PAJ7620 gesture sensor (I2C address 0x73) (+2.5k code)
// #define USE_PCF8574 // [I2cDriver2] Enable PCF8574 I/O Expander (I2C addresses 0x20 - 0x26 and 0x39 - 0x3F) (+1k9 code)
// #define USE_HIH6 // [I2cDriver36] Enable Honeywell HIH Humidity and Temperature sensor (I2C address 0x27) (+0k6)

// #define USE_DISPLAY // Add I2C Display Support (+2k code)
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0
#define USE_DISPLAY_LCD // [DisplayModel 1] Enable Lcd display (I2C addresses 0x27 and 0x3F) (+6k code)
#define USE_DISPLAY_SSD1306 // [DisplayModel 2] Enable SSD1306 Oled 128x64 display (I2C addresses 0x3C and 0x3D) (+16k code)
#define USE_DISPLAY_MATRIX // [DisplayModel 3] Enable 8x8 Matrix display (I2C adresseses see below) (+11k code)
#define USE_DISPLAY_LCD // [DisplayModel 1] [I2cDriver3] Enable Lcd display (I2C addresses 0x27 and 0x3F) (+6k code)
#define USE_DISPLAY_SSD1306 // [DisplayModel 2] [I2cDriver4] Enable SSD1306 Oled 128x64 display (I2C addresses 0x3C and 0x3D) (+16k code)
#define USE_DISPLAY_MATRIX // [DisplayModel 3] [I2cDriver5] Enable 8x8 Matrix display (I2C adresseses see below) (+11k code)
#define MTX_ADDRESS1 0x71 // [DisplayAddress1] I2C address of first 8x8 matrix module
#define MTX_ADDRESS2 0x74 // [DisplayAddress2] I2C address of second 8x8 matrix module
#define MTX_ADDRESS3 0x75 // [DisplayAddress3] I2C address of third 8x8 matrix module
Expand All @@ -429,7 +429,7 @@
#define MTX_ADDRESS6 0x76 // [DisplayAddress6] I2C address of sixth 8x8 matrix module
#define MTX_ADDRESS7 0x00 // [DisplayAddress7] I2C address of seventh 8x8 matrix module
#define MTX_ADDRESS8 0x00 // [DisplayAddress8] I2C address of eigth 8x8 matrix module
// #define USE_DISPLAY_SH1106 // [DisplayModel 7] Enable SH1106 Oled 128x64 display (I2C addresses 0x3C and 0x3D)
// #define USE_DISPLAY_SH1106 // [DisplayModel 7] [I2cDriver6] Enable SH1106 Oled 128x64 display (I2C addresses 0x3C and 0x3D)
#endif // USE_I2C

// -- SPI sensors ---------------------------------
Expand All @@ -442,9 +442,9 @@
#define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code)
// #define USE_DISPLAY_EPAPER_29 // [DisplayModel 5] Enable e-paper 2.9 inch display (+19k code)
// #define USE_DISPLAY_EPAPER_42 // [DisplayModel 6] Enable e-paper 4.2 inch display
// #define USE_DISPLAY_ILI9488 // [DisplayModel 8]
// #define USE_DISPLAY_ILI9488 // [DisplayModel 8] [I2cDriver38] (Touch)
// #define USE_DISPLAY_SSD1351 // [DisplayModel 9]
// #define USE_DISPLAY_RA8876 // [DisplayModel 10]
// #define USE_DISPLAY_RA8876 // [DisplayModel 10] [I2cDriver39] (Touch)
#endif // USE_SPI

// -- Serial sensors ------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
//#define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
#define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code)
#define USE_TSL2561 // Add I2C code for TSL2561 sensor using library Adafruit TSL2561 Arduino (+1k2 code)
//#define USE_TSL2591 // Add I2C code for TSL2591 sensor
//#define USE_TSL2591 // Add I2C code for TSL2591 sensor library Adafruit_TSL2591 (+1k6 code)
#define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
#define USE_SGP30 // Add I2C code for SGP30 sensor (+1k1 code)
//#define USE_SI1145 // Add I2C code for SI1145/46/47 sensor (+1k code)
Expand Down
58 changes: 34 additions & 24 deletions tasmota/xsns_57_tsl2591.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
xsns_57_tsl2591.ino - TSL2591 light sensor support for Sonoff-Tasmota
xsns_57_tsl2591.ino - TSL2591 light sensor support for Tasmota
Copyright (C) 2019 Markus Bösling and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -21,9 +23,13 @@
* TSL2591 - Light Intensity
*
* I2C Addresses: 0x29 (low), 0x39 (float) or 0x49 (high)
* (Used library supports address 0x29 only)
\*********************************************************************************************/

#define XSNS_57 57
#define XI2C_40 40 // See I2CDEVICES.md

#define TSL2591_ADDRESS 0x29 // Used library only supports this address only

#include <Adafruit_TSL2591.h>

Expand All @@ -35,13 +41,15 @@ float tsl2591_lux = 0;

void Tsl2591Init(void)
{
if (tsl2591_type) {
return;
}
if (tsl.begin()) {
tsl.setGain(TSL2591_GAIN_MED);
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
tsl2591_type = 1;
if (tsl2591_type) { return; }

if (I2cSetDevice(0x29) || I2cSetDevice(0x39) || I2cSetDevice(0x49)) {
if (tsl.begin()) {
tsl.setGain(TSL2591_GAIN_MED);
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
tsl2591_type = 1;
I2cSetActiveFound(TSL2591_ADDRESS, "TSL2591");
}
}
}

Expand All @@ -57,7 +65,9 @@ bool Tsl2591Read(void)

void Tsl2591EverySecond(void)
{
Tsl2591Read();
if (tsl2591_type) {
Tsl2591Read();
}
}

#ifdef USE_WEBSERVER
Expand Down Expand Up @@ -89,25 +99,25 @@ void Tsl2591Show(bool json)

bool Xsns57(uint8_t function)
{
if (!I2cEnabled(XI2C_40)) { return false; }

bool result = false;

if (i2c_flg) {
switch (function) {
case FUNC_INIT:
Tsl2591Init();
break;
case FUNC_EVERY_SECOND:
Tsl2591EverySecond();
break;
case FUNC_JSON_APPEND:
Tsl2591Show(1);
break;
switch (function) {
case FUNC_EVERY_SECOND:
Tsl2591EverySecond();
break;
case FUNC_JSON_APPEND:
Tsl2591Show(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
Tsl2591Show(0);
break;
case FUNC_WEB_SENSOR:
Tsl2591Show(0);
break;
#endif // USE_WEBSERVER
}
case FUNC_INIT:
Tsl2591Init();
break;
}
return result;
}
Expand Down

0 comments on commit b31f3d8

Please sign in to comment.