Support for DFRobot SEN0390 V30B ambient light sensor

Add support for DFRobot SEN0390 V30B ambient light sensor (#16105)
This commit is contained in:
Theo Arends 2022-09-02 13:13:47 +02:00
parent 684584a5e5
commit 86e45969bd
9 changed files with 387 additions and 166 deletions

View File

@ -7,7 +7,7 @@ l = lite, t = tasmota, k = knx, s = sensors, i = ir, d = display
Note: `minimal` variant is not listed as it shouldn't be used outside of the [upgrading](https://tasmota.github.io/docs/Upgrading/) process.
| Feature or Sensor | l | t | k | s | i | d | Remarks
|-----------------------|---|-------|---|---|---|---|--------
|---------------------------|---|-------|---|---|---|---|--------
| MY_LANGUAGE en_GB | x | x / x | x | x | x | x |
| USE_IMPROV | x | x / x | x | x | x | x |
| USE_UFILESYS | - | - / x | - | - | - | - |
@ -176,6 +176,7 @@ Note: `minimal` variant is not listed as it shouldn't be used outside of the [up
| USE_PCF85363 | - | - / - | - | - | - | - |
| USE_DS3502 | - | - / - | - | - | - | - |
| USE_HYT | - | - / - | - | - | - | - |
| USE_LUXV30B | - | - / - | - | - | - | - |
| | | | | | | |
| Feature or Sensor | l | t | k | s | i | d | Remarks
| USE_SPI | - | - / - | - | - | - | x |

View File

@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Flowrate meter flow amount/duration, show values in table format (#16385)
- Zigbee prepare for Green Power support (#16407)
- Command ``SetOption146 1`` to enable display of ESP32 internal temperature
- Support for DFRobot SEN0390 V30B ambient light sensor (#16105)
### Changed
- TasmotaModbus library from v3.5.0 to v3.6.0 (#16351)

View File

@ -113,6 +113,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
- Command ``StatusRetain`` [#11109](https://github.com/arendst/Tasmota/issues/11109)
- Support for SGP40 gas and air quality sensor [#16341](https://github.com/arendst/Tasmota/issues/16341)
- Support for Modbus writing using ModbusBridge by JeroenSt [#16351](https://github.com/arendst/Tasmota/issues/16351)
- Support for DFRobot SEN0390 V30B ambient light sensor [#16105](https://github.com/arendst/Tasmota/issues/16105)
- Zigbee device plugin mechanism with commands ``ZbLoad``, ``ZbUnload`` and ``ZbLoadDump`` [#16252](https://github.com/arendst/Tasmota/issues/16252)
- Zigbee prepare for Green Power support [#16407](https://github.com/arendst/Tasmota/issues/16407)
- Flowrate meter flow amount/duration, show values in table format [#16385](https://github.com/arendst/Tasmota/issues/16385)

View File

@ -153,6 +153,7 @@
//#define USE_HDC2010 // [I2cDriver64] Enable HDC2010 temperature/humidity sensor (I2C address 0x40) (+1k5 code)
//#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code)
//#define USE_HYT // [I2CDriver68] Enable HYTxxx temperature and humidity sensor (I2C address 0x28) (+0k5 code)
//#define USE_LUXV30B // [I2CDriver70] Enable RFRobot SEN0390 LuxV30b ambient light sensor (I2C address 0x4A) (+0k5 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)

View File

@ -410,6 +410,7 @@
//#define USE_T67XX // [I2cDriver61] Enable Telaire T67XX CO2 sensor (I2C address 0x15) (+1k3 code)
//#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code)
//#define USE_HYT // [I2CDriver68] Enable HYTxxx temperature and humidity sensor (I2C address 0x28) (+0k5 code)
//#define USE_LUXV30B // [I2CDriver70] Enable RFRobot SEN0390 LuxV30b ambient light sensor (I2C address 0x4A) (+0k5 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)
@ -617,6 +618,7 @@
//#define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code)
//#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code)
//#define USE_HYT // [I2CDriver68] Enable HYTxxx temperature and humidity sensor (I2C address 0x28) (+0k5 code)
//#define USE_LUXV30B // [I2CDriver70] Enable RFRobot SEN0390 LuxV30b ambient light sensor (I2C address 0x4A) (+0k5 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)

View File

@ -681,6 +681,7 @@
// #define USE_HDC2010 // [I2cDriver64] Enable HDC2010 temperature/humidity sensor (I2C address 0x40) (+1k5 code)
// #define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code)
// #define USE_HYT // [I2CDriver68] Enable HYTxxx temperature and humidity sensor (I2C address 0x28) (+0k5 code)
// #define USE_LUXV30B // [I2CDriver70] Enable RFRobot SEN0390 LuxV30b ambient light sensor (I2C address 0x4A) (+0k5 code)
// #define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)

View File

@ -828,7 +828,9 @@ void ResponseAppendFeatures(void)
#if defined(USE_I2C) && defined(USE_SGP40)
feature9 |= 0x00000001; // xsns_98_sgp40.ino
#endif
// feature9 |= 0x00000002;
#if defined(USE_I2C) && defined(USE_LUXV30B)
feature9 |= 0x00000002;
#endif
// feature9 |= 0x00000004;
// feature9 |= 0x00000008;

View File

@ -0,0 +1,212 @@
/*
xsns_99_luxv30b.ino - Driver for DFRobot V30B lux sensor
Copyright (C) 2022 Marius Bezuidenhout
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_I2C
#ifdef USE_LUXV30B
/**************************************************************************************************
* DFRobot SEN0390 V30B ambient light sensor
*
* https://wiki.dfrobot.com/Ambient_Light_Sensor_0_200klx_SKU_SEN0390
* https://github.com/DFRobot/DFRobot_B_LUX_V30B/
*
* I2C Address: 0x4A
* ================================================================================================
* This driver use the I2C mode. Uses address 0x94 and 0x95. Its address cannot be changed.
*
* Supply Voltage: 2.7-6V
* Operating Current: 0.7mA
* Detection Range: 0-200klx
* Accuracy: 0.054lx
* Operating Temperature Range: -40°C~+85°C
* I2C Address: 0x4A
*
* Pin assignments:
*
* ------------------------------------------
* | Num | Label | Description |
* 1 VCC 2.7-6V +
* 2 SCL I2C Serial Clock Line
* 3 SDA I2C Serial Data
* 4 GND Ground
* 5 EN Sensor Chip-select Enable/Disable port, High to enable, Low to disable sensor
*
*
* You can write the desired configuration to the configuration register(address:0x04), setting
* different acquisition accuracy.
* You can read the light intensity data from the data register(address:0x00~0x03).
* ------------------------------------------------------------------------------------------
* | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
* ------------------------------------------------------------------------------------------
* | 0 | MANUAL | 0 | 0 | CDR | TIM |
* ------------------------------------------------------------------------------------------
* MANUAL Manual configuration register.
* 0 represents the default automatic mode.In this mode ,CDR and TIM are automatically assigned.
* 1 represents the configuration of manual mode.In this mode,CDR and TIM can be set by the user.
* CDR Shunt ratio register.
* 0 represents the default of not dividing,all the current of the photodiode into the ADC
* 1 represents the division of 8,as long as 1/8 of the current of the photodiode changes to ADC.
* This mode is used in high brightness situations.
* TIM[2:0]Acquisition time.
* ------------------------------------------------------------------------------------------------
* TIM[2:0] | TIMEms | Introduction |
* ------------------------------------------------------------------------------------------------
* 000 | 800 | Preferred mode in low light environment |
* ------------------------------------------------------------------------------------------------
* 001 | 400 | --- |
* ------------------------------------------------------------------------------------------------
* 010 | 200 | --- |
* ------------------------------------------------------------------------------------------------
* 011 | 100 | In the strong light environment, select the mode preferentially |
* ------------------------------------------------------------------------------------------------
* 100 | 50 | Manual mode only |
* ------------------------------------------------------------------------------------------------
* 101 | 250 | Manual mode only |
* ------------------------------------------------------------------------------------------------
* 110 | 12.5 | Manual mode only |
* ------------------------------------------------------------------------------------------------
* 111 | 6.25 | Manual mode only |
* ------------------------------------------------------------------------------------------------
* Accuracy that can be set in manual mode:
* -------------------------------------------------------------------------------------------------------------
* | Light conditions | | TIM & CDR |
* -------------------------------------------------------------------------------------------------------------
* | Minimum accuracy | Maximum accuracy | Maximum | Acquisition time(ms) | TIM | CDR |
* ------------------------------------------------------------------------------------------------------------
* 0.054 11.52 2938 800 000 0
* 0.09 23.04 5875 400 001 0
* 0.18 46.08 11750 200 010 0
* 0.36 92.16 23501 100 011 0
* 0.36 92.16 23501 800 000 1
* 0.72 184.32 47002 50 100 0
* 0.72 184.32 47002 400 001 1
* 1.44 368.64 94003 25 101 0
* 1.44 368.64 94003 200 010 1
* 2.88 737.28 200000 12.5 110 0
* 2.88 737.28 200000 100 011 1
* 5.76 737.28 200000 6.25 111 0
* 5.76 737.28 200000 50 100 1
* 11.52 737.28 200000 25 101 1
* 23.04 737.28 200000 12.5 110 1
* 46.08 737.28 200000 6.25 111 1
* ------------------------------------------------------------------------------------------------------------
* *************************************************************************************************/
#define XSNS_99 99
#define XI2C_70 70 // See I2CDEVICES.md
#define LUXV30B_ADDR 0x4A // Two wire library uses 7-bit addresses throughout
#define LUXV30B_DATAREG 0x00 // Address of the data register
#define LUXV30B_CONFREG 0x04 // Address of the configuration register
class LuxV30b {
public:
LuxV30b();
void Detect();
bool Found();
void Read();
void Show(uint8_t function);
private:
float Lux();
bool _found;
uint32_t _lux;
};
LuxV30b::LuxV30b() {
_found = false;
_lux = 0;
}
void LuxV30b::Detect() {
if (!I2cSetDevice(LUXV30B_ADDR)) { return; }
_found = true;
I2cSetActiveFound(LUXV30B_ADDR, "LUXV30B");
}
bool LuxV30b::Found() {
return _found;
}
void LuxV30b::Read() {
_lux = I2cRead8(LUXV30B_ADDR, 0);
delay(8);
_lux |= I2cRead8(LUXV30B_ADDR, 1) << 8;
delay(8);
_lux |= I2cRead8(LUXV30B_ADDR, 2) << 16;
delay(8);
_lux |= I2cRead8(LUXV30B_ADDR, 3) << 24;
}
float LuxV30b::Lux() {
return ((float)_lux * 1.4) / 1000;
}
void LuxV30b::Show(uint8_t function) {
// if (0 < Lux()) {
if (_lux) {
char lux[FLOATSZ];
dtostrfd(Lux(), 2, lux);
if (FUNC_JSON_APPEND == function) {
ResponseAppend_P(PSTR(",\"LUXV30B\":{\"" D_JSON_ILLUMINANCE "\":%s}"), lux);
#ifdef USE_DOMOTICZ
// Instead of below code use a rule like 'on tele-luxv30b#illuminance do dzsend1 9988,%value% endon'
// where 9988 is the domoticz sensor Idx
// if (0 == TasmotaGlobal.tele_period) { DomoticzSensor(DZ_ILLUMINANCE, lux); }
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(PSTR("{s}LUXV30B " D_ILLUMINANCE "{m}%s " D_UNIT_LUX "{e}"), lux);
#endif // USE_WEBSERVER
}
}
}
LuxV30b Luxv30b;
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns99(uint8_t function) {
if (!I2cEnabled(XI2C_70)) { return false; }
bool result = false;
if (FUNC_INIT == function) {
Luxv30b.Detect();
}
else if (Luxv30b.Found()) {
switch (function) {
case FUNC_EVERY_SECOND:
Luxv30b.Read();
break;
case FUNC_JSON_APPEND:
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
#endif // USE_WEBSERVER
Luxv30b.Show(function);
break;
}
}
return result;
}
#endif // USE_LUXV30B
#endif // USE_I2C

View File

@ -285,7 +285,7 @@ a_features = [[
"USE_PCF85363","USE_DS3502","USE_IMPROV","USE_FLOWRATEMETER",
"USE_BP5758D","USE_HYT","USE_SM2335","USE_DISPLAY_TM1621_SONOFF"
],[
"USE_SGP40","","","",
"USE_SGP40","USE_LUXV30B","","",
"","","","",
"","","","",
"","","","",