Skip to content

Commit 438ef4f

Browse files
authored
Merge pull request #4910 from flashmark/P164_gases-ens160
P164 gases ens160
2 parents 6647e35 + 7c3b582 commit 438ef4f

11 files changed

+1364
-3
lines changed

docs/source/Plugin/P164.rst

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
.. include:: ../Plugin/_plugin_substitutions_p16x.repl
2+
.. _P164_page:
3+
4+
|P164_typename|
5+
==================================================
6+
7+
|P164_shortinfo|
8+
9+
Plugin details
10+
--------------
11+
12+
Type: |P164_type|
13+
14+
Name: |P164_name|
15+
16+
Status: |P164_status|
17+
18+
GitHub: |P164_github|_
19+
20+
Maintainer: |P164_maintainer|
21+
22+
Used libraries: |P164_usedlibraries|
23+
24+
Description
25+
-----------
26+
27+
Sciosense ENS160 and its successor ENS161 are multi-gas sensors based on metal oxide (MOX) technology. They can detect multiple VOCs including ethanol, toluene, hydrogen and oxidizing gases.
28+
The sensors are connected to the I2C bus and provide preprocessed data as TVOC and eCO2 values. See https://www.sciosense.com/ens16x-digital-metal-oxide-multi-gas-sensor-family/ for details about the device.
29+
30+
Hardware
31+
--------
32+
33+
Various boards with the ENS160 are available through electronics market places like Aliexpress. A popular board contains both ENS160 and AHT21 on a single PCB. The AHT21 can be used for temperature compensation as provided by this plugin.
34+
35+
.. image:: P164_board.jpg
36+
37+
Configuration
38+
-------------
39+
40+
.. image:: P164_DeviceConfiguration.png
41+
42+
* **Name**: Required by ESPEasy, must be unique among the list of available devices/tasks.
43+
44+
* **Enabled**: The device can be disabled or enabled. When not enabled the device should not use any resources.
45+
46+
I2C options
47+
^^^^^^^^^^^
48+
49+
* **I2C Address**: The sensor supports two addresses. The actual address depends on the voltage on the ADDR pin of the device.
50+
51+
.. csv-table::
52+
:header: "Address", "Remark"
53+
:widths: 10, 50
54+
55+
"0x52", "Connect ADDR GND"
56+
"0x53", "Connect ADDR to VDD (default on most boards)"
57+
58+
The available I2C settings here depend on the build used. At least the **Force Slow I2C speed** option is available, but selections for the I2C Multiplexer can also be shown. For details see the :ref:`Hardware_page`
59+
60+
The chip supports both SPI and I2C. The plugin only support I2C using the following pins:
61+
62+
* 1 SDA: Data [MOSI/SDA]
63+
* 2 SCL: Serial Clock [SCLK/SCL]
64+
* 3 ADDR: Address [MISO/ADDR]
65+
* 6 INTn: Interrupt [INTn]
66+
* 7 CSn: SPI interface select, low-> SPI, high->I2C [CSn]
67+
68+
For this plugin the CSn must be wired to VDD to enable the I2C protocol.
69+
70+
On boards sold online, SDO and SDI are often already pulled-up, setting the default I2C address to 0x53.
71+
72+
73+
Device Settings
74+
^^^^^^^^^^^^^^^
75+
76+
* **Detected Sensor Type**: Shows either ``ENS160`` or ``ENS161`` or a number if no sensor or an unknown sensor ID is detected. It will also show the firmware version read from the device if the data is available.
77+
* **Temperature Task**: Task (plugin) providing the temperature compensation
78+
* **Temperature Value**: Value for the temperature compensation
79+
* **Humidity Task**: Task (plugin) providing the humidity compensation
80+
* **Humidity Value**: Value for the humidity compensation
81+
82+
The ENS16x provides temperature and humidity compensation. The plugin must provide the actual temperature and humidity to the device to enable this compensation. For this the plugin needs to read these values from other tasks.
83+
84+
Using the **Temperature Task** and **Temperature Value** the task and value for the Temperature compensation can be selected. Compensation can be switched off by selecting **Not Set**.
85+
86+
Using the **Humidity Task** and **Humidity Value** the task and value for the Humidity compensation can be selected. Compensation can be switched off by selecting **Not Set**.
87+
88+
Note that if either one of the tasks is set to **Not Set** compensation is switched off and a default value is used.
89+
90+
The ENS160 is sold on popular websites on a board including the AHT21 temperature and humidity sensor. This sensor can be used for the compensation algorithm of the ENS160.
91+
92+
Data Acquisition
93+
^^^^^^^^^^^^^^^^
94+
95+
This group of settings, **Single event with all values** and **Send to Controller** settings are standard available configuration items. Send to Controller is only visible when one or more Controllers are configured.
96+
97+
* **Interval** By default, Interval will be set to 60 sec. The data will be collected and optionally sent to any configured controllers using this interval. If the Interval is set lower or equal than the required 10 * Heater time, the plugin will not start!
98+
99+
Values
100+
^^^^^^
101+
102+
The plugin provides the ``TVOC`` and ``eCO2`` values. A formula can be set to recalculate. The number of decimals can be set as desired, and defaults to 2.
103+
104+
In selected builds, per Value is a **Stats** checkbox available, that when checked, gathers the data and presents recent data in a graph, as described here: :ref:`Task Value Statistics: <Task Value Statistics>`
105+
106+
Currently the extra features offered by the sensore are not configurable in this plugin.
107+
These may be added later.
108+
109+
Change log
110+
----------
111+
112+
.. versionchanged:: 2.0
113+
...
114+
115+
|added|
116+
2023-12-27 Initial release version.
117+
67.6 KB
Loading

docs/source/Plugin/P164_board.jpg

92.6 KB
Loading

docs/source/Plugin/_Plugin.rst

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ There are different released versions of ESP Easy:
386386
":ref:`P153_page`","|P153_status|","P153"
387387
":ref:`P154_page`","|P154_status|","P154"
388388
":ref:`P159_page`","|P159_status|","P159"
389+
":ref:`P164_page`","|P164_status|","P164"
389390
":ref:`P166_page`","|P166_status|","P166"
390391

391392

docs/source/Plugin/_plugin_categories.repl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.. |Plugin_Energy_Heat| replace:: :ref:`P088_page`, :ref:`P093_page`
1111
.. |Plugin_Environment| replace:: :ref:`P004_page`, :ref:`P005_page`, :ref:`P006_page`, :ref:`P014_page`, :ref:`P024_page`, :ref:`P028_page`, :ref:`P030_page`, :ref:`P031_page`, :ref:`P032_page`, :ref:`P034_page`, :ref:`P039_page`, :ref:`P047_page`, :ref:`P051_page`, :ref:`P068_page`, :ref:`P069_page`, :ref:`P072_page`, :ref:`P103_page`, :ref:`P105_page`, :ref:`P106_page`, :ref:`P122_page`, :ref:`P150_page`, :ref:`P151_page`, :ref:`P153_page`, :ref:`P154_page`
1212
.. |Plugin_Extra_IO| replace:: :ref:`P011_page`, :ref:`P022_page`
13-
.. |Plugin_Gases| replace:: :ref:`P049_page`, :ref:`P052_page`, :ref:`P083_page`, :ref:`P090_page`, :ref:`P117_page`, :ref:`P127_page`, :ref:`P135_page`, :ref:`P145_page`, :ref:`P147_page`
13+
.. |Plugin_Gases| replace:: :ref:`P049_page`, :ref:`P052_page`, :ref:`P083_page`, :ref:`P090_page`, :ref:`P117_page`, :ref:`P127_page`, :ref:`P135_page`, :ref:`P145_page`, :ref:`P147_page`, :ref:`P164_page`
1414
.. |Plugin_Generic| replace:: :ref:`P003_page`, :ref:`P026_page`, :ref:`P033_page`, :ref:`P037_page`, :ref:`P081_page`, :ref:`P100_page`, :ref:`P146_page`
1515
.. |Plugin_Gesture| replace:: :ref:`P064_page`
1616
.. |Plugin_Gyro| replace:: :ref:`P045_page`, :ref:`P119_page`

docs/source/Plugin/_plugin_substitutions_p16x.repl

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
.. |P164_name| replace:: :cyan:`ENS16x TVOC/eCO2`
2+
.. |P164_type| replace:: :cyan:`Gases`
3+
.. |P164_typename| replace:: :cyan:`Gases - ENS16x TVOC/eCO2`
4+
.. |P164_porttype| replace:: `.`
5+
.. |P164_status| replace:: :yellow:`COLLECTION G` :yellow:`CLIMATE`
6+
.. |P164_github| replace:: P164_gases_ens160.ino
7+
.. _P164_github: https://github.com/letscontrolit/ESPEasy/blob/mega/src/_P164_gases_ens160.ino
8+
.. |P164_usedby| replace:: `.`
9+
.. |P164_shortinfo| replace:: `ENS16x TVOC/eCO2 sensors`
10+
.. |P164_maintainer| replace:: `flashmark`
11+
.. |P164_compileinfo| replace:: `.`
12+
.. |P164_usedlibraries| replace:: `I2C`
13+
114
.. |P166_name| replace:: :cyan:`GP8403 Dual channel DAC 0-10V`
215
.. |P166_type| replace:: :cyan:`Output`
316
.. |P166_typename| replace:: :cyan:`Output - GP8403 Dual channel DAC 0-10V`

src/Custom-sample.h

+1
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = {
538538

539539
// #define USES_P159 // Presence - LD2410 Radar detection
540540

541+
// #define USES_P164 // Gases - ENS16x TVOC/eCO2
541542
/*
542543
#######################################################################################################
543544
########### Controllers

src/_P164_gases_ens160.ino

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#include "_Plugin_Helper.h"
2+
#ifdef USES_P164
3+
4+
// #######################################################################################################
5+
// #################################### Plugin-164: Gases - ENS16x (tvoc,eco2) ###########################
6+
// #######################################################################################################
7+
// P164 "GASES - ENS16x (TVOC, eCO2)"
8+
// Plugin for ENS160 & ENS161 TVOC and eCO2 sensor with I2C interface from ScioSense
9+
// For documentation of the ENS160 hardware device see
10+
// https://www.sciosense.com/wp-content/uploads/documents/SC-001224-DS-9-ENS160-Datasheet.pdf
11+
//
12+
// PLugin code:
13+
// 2023 By flashmark
14+
// #######################################################################################################
15+
16+
# include "src/PluginStructs/P164_data_struct.h"
17+
18+
# define PLUGIN_164
19+
# define PLUGIN_ID_164 164
20+
# define PLUGIN_NAME_164 "Gases - ENS16x"
21+
# define PLUGIN_VALUENAME1_164 "TVOC"
22+
# define PLUGIN_VALUENAME2_164 "eCO2"
23+
24+
boolean Plugin_164(uint8_t function, struct EventStruct *event, String& string)
25+
{
26+
boolean success = false;
27+
28+
switch (function)
29+
{
30+
case PLUGIN_DEVICE_ADD:
31+
{
32+
Device[++deviceCount].Number = PLUGIN_ID_164;
33+
Device[deviceCount].Type = DEVICE_TYPE_I2C;
34+
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_DUAL;
35+
Device[deviceCount].Ports = 0;
36+
Device[deviceCount].PullUpOption = false;
37+
Device[deviceCount].InverseLogicOption = false;
38+
Device[deviceCount].FormulaOption = true;
39+
Device[deviceCount].ValueCount = 2;
40+
Device[deviceCount].SendDataOption = true;
41+
Device[deviceCount].TimerOption = true;
42+
Device[deviceCount].GlobalSyncOption = true;
43+
Device[deviceCount].PluginStats = true;
44+
break;
45+
}
46+
47+
case PLUGIN_GET_DEVICENAME:
48+
{
49+
string = F(PLUGIN_NAME_164);
50+
break;
51+
}
52+
53+
case PLUGIN_GET_DEVICEVALUENAMES:
54+
{
55+
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_164));
56+
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_164));
57+
break;
58+
}
59+
60+
case PLUGIN_I2C_HAS_ADDRESS:
61+
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
62+
{
63+
const uint8_t i2cAddressValues[] = { P164_ENS160_I2CADDR_0, P164_ENS160_I2CADDR_1 };
64+
constexpr int nrAddressOptions = NR_ELEMENTS(i2cAddressValues);
65+
66+
if (function == PLUGIN_WEBFORM_SHOW_I2C_PARAMS) {
67+
addFormSelectorI2C(F("i2c_addr"), nrAddressOptions, i2cAddressValues, P164_PCONFIG_I2C_ADDR);
68+
addFormNote(F("ADDR Low=0x52, High=0x53"));
69+
} else {
70+
success = intArrayContains(nrAddressOptions, i2cAddressValues, event->Par1);
71+
}
72+
73+
break;
74+
}
75+
76+
# if FEATURE_I2C_GET_ADDRESS
77+
case PLUGIN_I2C_GET_ADDRESS:
78+
{
79+
event->Par1 = P164_PCONFIG_I2C_ADDR;
80+
success = true;
81+
break;
82+
}
83+
# endif // if FEATURE_I2C_GET_ADDRESS
84+
85+
case PLUGIN_SET_DEFAULTS:
86+
{
87+
P164_PCONFIG_I2C_ADDR = P164_ENS160_I2CADDR_1;
88+
success = true;
89+
break;
90+
}
91+
92+
case PLUGIN_INIT:
93+
{
94+
initPluginTaskData(event->TaskIndex, new (std::nothrow) P164_data_struct(event));
95+
P164_data_struct *P164_data = static_cast<P164_data_struct *>(getPluginTaskData(event->TaskIndex));
96+
97+
success = (nullptr != P164_data && P164_data->begin());
98+
break;
99+
}
100+
101+
case PLUGIN_READ:
102+
{
103+
P164_data_struct *P164_data = static_cast<P164_data_struct *>(getPluginTaskData(event->TaskIndex));
104+
105+
if (nullptr == P164_data) {
106+
addLogMove(LOG_LEVEL_ERROR, F("P164: plugin_read NULLPTR"));
107+
break;
108+
}
109+
110+
float temperature = 20.0f; // A reasonable value in case temperature source task is invalid
111+
float humidity = 50.0f; // A reasonable value in case humidity source task is invalid
112+
float tvoc = 0.0f; // tvoc value to be retrieved from device
113+
float eco2 = 0.0f; // eCO2 value to be retrieved from device
114+
115+
if (validTaskIndex(P164_PCONFIG_TEMP_TASK) && validTaskIndex(P164_PCONFIG_HUM_TASK))
116+
{
117+
// we're checking a value from other tasks
118+
temperature = UserVar.getFloat(P164_PCONFIG_TEMP_TASK, P164_PCONFIG_TEMP_VAL); // in degrees C
119+
humidity = UserVar.getFloat(P164_PCONFIG_HUM_TASK, P164_PCONFIG_HUM_VAL); // in % relative
120+
}
121+
success = P164_data->read(tvoc, eco2, temperature, humidity);
122+
UserVar.setFloat(event->TaskIndex, 0, tvoc);
123+
UserVar.setFloat(event->TaskIndex, 1, eco2);
124+
break;
125+
}
126+
127+
case PLUGIN_WEBFORM_LOAD:
128+
{
129+
success = P164_data_struct::webformLoad(event);
130+
break;
131+
}
132+
133+
case PLUGIN_WEBFORM_SAVE:
134+
{
135+
success = P164_data_struct::webformSave(event);
136+
break;
137+
}
138+
139+
case PLUGIN_TEN_PER_SECOND:
140+
{
141+
P164_data_struct *P164_data =
142+
static_cast<P164_data_struct *>(getPluginTaskData(event->TaskIndex));
143+
if (nullptr == P164_data) {
144+
break;
145+
}
146+
success = P164_data->tenPerSecond(event);
147+
break;
148+
}
149+
}
150+
return success;
151+
}
152+
153+
#endif // ifdef USES_P164

src/src/CustomBuild/define_plugin_sets.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,9 @@ To create/register a plugin, you have to :
16221622
#ifndef USES_P159
16231623
#define USES_P159 // Presence - LD2410 Radar detection
16241624
#endif
1625+
#ifndef USES_P164
1626+
#define USES_P164 // Gases - ENS16x TVOC\eCO2
1627+
#endif
16251628
#ifndef USES_P166
16261629
#define USES_P166 // Output - GP8403 DAC 0-10V
16271630
#endif
@@ -1907,8 +1910,12 @@ To create/register a plugin, you have to :
19071910
#ifndef USES_P154
19081911
#define USES_P154 // Environment - BMP3xx
19091912
#endif
1910-
1911-
1913+
#ifndef USES_P164
1914+
#define USES_P164 // Gases - ENS16x TVOC/eCO2
1915+
#endif
1916+
#ifndef USES_P166
1917+
#define USES_P166 // Output - GP8403 DAC 0-10V
1918+
#endif
19121919

19131920
// Controllers
19141921
#ifndef USES_C011

0 commit comments

Comments
 (0)