[TEMT] Added Temt6000 light sensor using a d1 mini (#1550)

Added light sensor TEMPT6000
This commit is contained in:
Die Peter Pan authored and GitHub committed 2023-03-18 09:33:35 -05:00
1 parent c12f51ee0e
commit 7bae999435
8 files changed
+175 -4

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ OpenMQTTGateway is not closed to one board or type of board, by using the power
You can take a look to the [OpenMQTTGateway compatible website](https://compatible.openmqttgateway.com) to have a view of the [supported boards](https://compatible.openmqttgateway.com/index.php/boards/).
Moreover the gateways capacities can be extended with sensors; DHT, HC SR501, ADC, I2C bus, INA226, TSL2561, BME280/BMP280, HTU21D, AHTx0, DS1820
Moreover the gateways capacities can be extended with sensors; DHT, HC SR501, ADC, I2C bus, INA226, TEMT6000, TSL2561, BME280/BMP280, HTU21D, AHTx0, DS1820
or actuators; LED, relays, PWM.
::: tip Running on a computer
+5 -3
View File
@@ -12,24 +12,26 @@
|GPIO Input|Inputs|-|
|GPIO KeyCode|Keycode|[parts list](https://compatible.openmqttgateway.com/index.php/parts)|
|INA226|Current, Voltage|[parts list](https://compatible.openmqttgateway.com/index.php/parts)|
|TEMT6000|Luminosity|[parts list](https://compatible.openmqttgateway.com/index.php/parts)|
|TSL2561|Luminosity|[parts list](https://compatible.openmqttgateway.com/index.php/parts)|
## Pinout
|Module|Arduino Pin| ESP8266 Pin|ESP32 Pin|
|-|-|-|-|
|DHT11/22|<a href="img/OpenMQTTgateway_Arduino_Addon_DHT.png" target="_blank">D8</a>|<a href="img/OpenMQTTgateway_ESP8266_Addon_DHT.png" target="_blank">D1</a>|16|
|HC-SR501/HC-SR505|7|D5|5|
|Analog reading|A0|A0|A0|
|BH1750 SDA|A4|D2|21|
|BH1750 SCL|A5|D1|22|
|BME280/BMP280 SDA|A4|D2|21|
|BME280/BMP280 SCL|A5|D1|22|
|DHT11/22|<a href="img/OpenMQTTgateway_Arduino_Addon_DHT.png" target="_blank">D8</a>|<a href="img/OpenMQTTgateway_ESP8266_Addon_DHT.png" target="_blank">D1</a>|16|
|HC-SR501/HC-SR505|7|D5|5|
|HTU21 SDA|A4|D2|21|
|HTU21 SCL|A5|D1|22|
|INA226 SDA|A4|D2|21|
|INA226 SCL|A5|D1|22|
|TEMT6000 |A0|A0|A0|
|TSL2561 SDA|A4|D2|21|
|TSL2561 SCL|A5|D1|22|
Vcc pin of the board and the Module to a 5V supply source
Vcc pin of the board and the Module to a 3.3V or 5V supply source depending on sensor voltage requirement.
Ground pins of the board and the Module to the ground of the supply source.
+3
View File
@@ -98,6 +98,7 @@ build_flags =
'-DBME280Correction=-3.4'
'-DZsensorHTU21="HTU21"'
'-DZsensorAHTx0="AHTx0"'
'-DZsensorTEMT6000="TEMT6000"'
'-DZsensorTSL2561="TSL2561"'
'-DZsensorDHT="DHT"'
'-DZsensorDS1820="DS1820"'
@@ -1104,6 +1105,7 @@ build_flags =
'-DZsensorBME280="BME280"'
;'-DZsensorHTU21="HTU21"'
'-DZsensorAHTx0="AHTx0"'
'-DZsensorTEMT6000="TEMT6000"'
'-DZsensorTSL2561="TSL2561"'
'-DZsensorDHT="DHT"'
'-DZsensorDS1820="DS1820"'
@@ -1675,3 +1677,4 @@ build_flags =
; '-DsimplePublishing=true'
custom_description = BLE Gateway using ethernet, requires PIO configuration
custom_hardware = ThingPulse gateway single ESP32
+1
View File
@@ -326,6 +326,7 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
//#define ZsensorHCSR501 "HCSR501" //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZsensorADC "ADC" //ESP8266, Arduino, ESP32
//#define ZsensorBH1750 "BH1750" //ESP8266, Arduino, ESP32
//#define ZsensorTEMT6000 "TEMT6000" //ESP8266
//#define ZsensorTSL2561 "TSL2561" //ESP8266, Arduino, ESP32
//#define ZsensorBME280 "BME280" //ESP8266, Arduino, ESP32
//#define ZsensorHTU21 "HTU21" //ESP8266, Arduino, ESP32
+23
View File
@@ -752,6 +752,29 @@ void pubMqttDiscovery() {
}
# endif
# ifdef ZsensorTEMT6000
# define TEMT6000parametersCount 3
Log.trace(F("TEMT6000Discovery" CR));
char* TEMT6000sensor[TEMT6000parametersCount][8] = {
{"sensor", "lux", "TEMT6000", "illuminance", jsonLux, "", "", "lx"},
{"sensor", "ftcd", "TEMT6000", "", jsonFtcd, "", "", ""},
{"sensor", "wattsm2", "TEMT6000", "", jsonWm2, "", "", "wm²"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < TEMT6000parametersCount; i++) {
//trc(TEMT6000sensor[i][1]);
createDiscovery(TEMT6000sensor[i][0],
subjectTEMT6000toMQTT, TEMT6000sensor[i][1], (char*)getUniqueId(TEMT6000sensor[i][1], TEMT6000sensor[i][2]).c_str(),
will_Topic, TEMT6000sensor[i][3], TEMT6000sensor[i][4],
TEMT6000sensor[i][5], TEMT6000sensor[i][6], TEMT6000sensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
}
# endif
# ifdef ZsensorTSL2561
# define TSL2561parametersCount 3
Log.trace(F("TSL2561Discovery" CR));
+77
View File
@@ -0,0 +1,77 @@
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
This is the Light Meter Addon based on modules with a TEMT6000:
- Measures ambient Light Intensity in Lux (lx), Foot Candela (ftcd) and Watt/m^2 (wattsm2)
- Required Hardware Module: TEMT6000
- Dependencies: none
Connection Scheme:
--------------------
TEMT6000------> ESP8266
==============================================
Vcc ---------> 3.3V
GND ---------> GND
SIG ---------> A0
Copyright: (c) Andre Greyling - this is a modified copy of Chris Broekema
This file is part of OpenMQTTGateway.
OpenMQTTGateway 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.
OpenMQTTGateway 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/>.
*/
#include "User_config.h"
#ifdef ZsensorTEMT6000
# include "Wire.h"
# include "math.h"
void setupZsensorTEMT6000() {
Log.notice(F("Setup TEMT6000 on pin: %i" CR), TEMT6000LIGHTSENSORPIN);
pinMode(TEMT6000LIGHTSENSORPIN, INPUT);
}
void MeasureLightIntensityTEMT6000() {
if (millis() > (timetemt6000 + TimeBetweenReadingtemt6000)) {
static uint32_t persisted_lux;
timetemt6000 = millis();
Log.trace(F("Creating TEMT6000 buffer" CR));
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject TEMT6000data = jsonBuffer.to<JsonObject>();
float volts = analogRead(TEMT6000LIGHTSENSORPIN) * 5.0 / 1024.0;
float amps = volts / 10000.0; // across 10,000 Ohms
float microamps = amps * 1000000;
float lux = microamps * 2.0;
if (persisted_lux != lux || temt6000_always) {
persisted_lux = lux;
TEMT6000data["lux"] = (float)lux;
TEMT6000data["ftcd"] = (float)(lux) / 10.764;
TEMT6000data["wattsm2"] = (float)(lux) / 683.0;
pub(subjectTEMT6000toMQTT, TEMT6000data);
} else {
Log.trace(F("Same lux value, do not send" CR));
}
}
}
#endif
+55
View File
@@ -0,0 +1,55 @@
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
This is the Light Meter Addon based on modules with a TEMT6000:
- Measures ambient Light Intensity in Lux (lx), Foot Candela (ftcd) and Watt/m^2 (wattsm2)
- Required Hardware Module: TEMT6000
- Dependencies: none
Connection Scheme:
--------------------
TEMT6000 ----> ESP8266
==============================================
Vcc ---------> 3.3V
GND ---------> GND
SIG ---------> A0
Copyright: (c) Andre Greyling - this is a modified copy of Chris Broekema
This file is part of OpenMQTTGateway.
OpenMQTTGateway 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.
OpenMQTTGateway 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/>.
*/
#ifndef config_TEMT6000_h
#define config_TEMT6000_h
extern void setupTEMT6000();
extern void TEMT6000toMQTT();
#define temt6000_always true // if false only send current value if it has changed
#define TEMT6000LIGHTSENSORPIN A0 //Ambient light sensor reading = ADC0
#define TimeBetweenReadingtemt6000 10000 //10000 ms
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectTEMT6000toMQTT "/LIGHTtoMQTT"
//Time used to wait for an interval before resending measured values
unsigned long timetemt6000 = 0;
#endif
+10
View File
@@ -109,6 +109,9 @@ struct GfSun2000Data {};
#ifdef ZsensorBH1750
# include "config_BH1750.h"
#endif
#ifdef ZsensorTEMT6000
# include "config_TEMT6000.h"
#endif
#ifdef ZsensorTSL2561
# include "config_TSL2561.h"
#endif
@@ -872,6 +875,10 @@ void setup() {
setupZsensorBH1750();
modules.add(ZsensorBH1750);
#endif
#ifdef ZsensorTEMT6000
setupZsensorTEMT6000();
modules.add(ZsensorTEMT6000);
#endif
#ifdef ZsensorTSL2561
setupZsensorTSL2561();
modules.add(ZsensorTSL2561);
@@ -1638,6 +1645,9 @@ void loop() {
#ifdef ZsensorBH1750
MeasureLightIntensity(); //Addon to measure Light Intensity with a BH1750
#endif
#ifdef ZsensorTEMT6000
MeasureLightIntensityTEMT6000();
#endif
#ifdef ZsensorTSL2561
MeasureLightIntensityTSL2561();
#endif