From 4bfbf79cfc32c2b2c3770d396eb0bd96cafa4154 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Tue, 3 Dec 2024 22:40:33 +0100 Subject: [PATCH] [P105] Add Alternative initialization option for AHT10 clones --- docs/source/Plugin/P105.rst | 14 +++++++--- docs/source/Plugin/P105_AHT10_alt_init.png | Bin 0 -> 5570 bytes src/_P105_AHT.ino | 30 ++++++++++++--------- src/src/PluginStructs/P105_data_struct.cpp | 14 ++++++---- src/src/PluginStructs/P105_data_struct.h | 7 +++-- 5 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 docs/source/Plugin/P105_AHT10_alt_init.png diff --git a/docs/source/Plugin/P105.rst b/docs/source/Plugin/P105.rst index 49c21d21a8..c28fc651d0 100644 --- a/docs/source/Plugin/P105.rst +++ b/docs/source/Plugin/P105.rst @@ -67,11 +67,17 @@ Available options: .. image:: P105_SensorModelOptions.png -**AHT1x** AHT10/AHT15. These sensor models should better be avoided, as it doesn't always work with other devices on the same I2C bus. +* **AHT1x** AHT10/AHT15. These sensor models should better be avoided, as it doesn't always work with other devices on the same I2C bus. -**AHT20** An more modern version of the sensor. Use this option also when connecting a DHT20 or AM2301B sensor. +* **AHT20** An more modern version of the sensor. Use this option also when connecting a DHT20 or AM2301B sensor. -**AHT21** An more modern version of the sensor, very similar to the AHT20, in a more compact chip package. +* **AHT21** An more modern version of the sensor, very similar to the AHT20, in a more compact chip package. + +When selecting the **AHT1x** Sensor model, an extra option is made available: + +.. image:: P105_AHT10_alt_init.png + +* **AHT10 Alternative initialization**: Some AHT10 clone sensors do not seem to like the regular AHT10/AHT15 initialization sequence. They do however accept a soft reset command. By enabling this checkbox, only the soft reset is sent to the device. Only available for AHT1x devices. Data Acquisition ^^^^^^^^^^^^^^^^ @@ -92,4 +98,6 @@ Change log .. versionchanged:: 2.0 ... + |changed| 2024-12-03 Add alternative initialization option + |added| 2021-08-01 Moved from ESPEasy PluginPlayground to the main repository. diff --git a/docs/source/Plugin/P105_AHT10_alt_init.png b/docs/source/Plugin/P105_AHT10_alt_init.png new file mode 100644 index 0000000000000000000000000000000000000000..f74ee299b44a3dba2acd4c64016bdf64b8c5f114 GIT binary patch literal 5570 zcmcIoc{r5c+aDE?tcmP{5ZQ((d$uB3B3qU*7~2eD?95=Ih^&PyO|}rS>x+!OBgQVW zOr-f`&oYy}vHl)?-|KqcKi>Dh-}_wiJoj^*Irll|xtGtmKPSQ5^ft>mzH=ZDh{ecI z-vR_Wg#_MFj10h2{Hc>JAQ)VXZ|egRxM+HDIRzzIh@z~bg5ou>3|LW74Wgo^q{?#6z|vev(emU! z2v`<;+t1Gf2?y)_(NWB;)B=GnvK#5^+z)kH%ZCJfQ{jmYO6H1^c)7l$@hnw?E3WpJDp2d()-dF#&-g_veNhv4?`1KT4VhCkvc> zLVu1}*og!!&=XERQUS%T0*L6Bk80=u*)I^w;#_d>d%XjF@O!w*`s(h^nmraA&%>h4 zMlf2Jr!~98mM?1se#(ZK9m5swX-(NsQPVu{TKp zkK@*+CIy8Bn~Sa`Pf&7Y&cfx)gotaTs`j1>aC}t?uLp@=oui4Zx+C(}@+dlUQE0Yf zWuy7YP$^|>wy|3K_YiLS=T!*t5=ZZ{ic>zun#hFxt$YgBC&g?p#&?@CXCbt6VJYFl zlY%n@1|?S>!g%+{%0xow&&?o$#O$L8^ffsboEcPk^NX!27R-8`y(zD-M%hKer|QQ@ zzJ}>@;?$+?bRCkjyM`S}?T2>=(J9Itz9WgGB|9_==&(N#Vzf8aA>o_1{f$US!l3vOUq+TzbL3|Pbx-56SQ_+s2d0>V;Kb4GjKZ2~uZ;JwFl#L57@;`6Huy6m6oKS84o z=a2TO+Ckrh)ipJ(h-kp9^e{w8!DaDN+d22~rq4LV#4k6$q2*De8!f(!afnND@Yvn% zw@Y*~eO~v@LDYOB`#@t9zZ_!YCyK25euZd6E~%kgO)q82C0SkVp1{Ob6*_FT233Fi zx%jKOr-S_t7W_*7dt1ar<+G?GTIv2SIjVK`Xy_%xu+DrVmr;CvW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bN zJ!86Qt1u8y=Syog?552X-*;lPS7O+F&>)|<>)N&IEP#SdogN$d`~wS6dI6y#!gzv? zzsOWk4ZPK(E^pd5!%r&9Fv~La??6e}=$f@S!6Y%lP9Sg$5Z&RbPqHZB&CD&l%pw#0 zh%nxp<2NK{6KZ9(J}LJ?&_0qAcA?tg3+C~MJye+7n%s9a!#f(nakGl8RWwy#PF5W1!?Ku?3py7q^+9WD5Juz29wUg$8Zqi*L$-!f}IxaxK$ombG|Q! zrsR7TRas6i&N_guy#{a0a5uDb4q#n1WtP1 zDD{;c0=KQGeLxfgE`Y-_nC)(O%Gi$A#>T|;I*`uy2V}$!3|dWSiy})@>hkmj9Xa&) z?rb+(M}II^xpx)0@nI>Xylo`=)_GXQVZ_s#lGuomU9>ukpFAu*R!x-f(KB`i3zL1Q z>!_218v!8$V2TGq4}6Qy1f7?;|KK^YKR~?slBfK+N0b!XhLR-1Vb96W6HiDnHSq2C zM1z+QSYNMMFWH$)kf4~MzD>4CkC9!puC%gwpKLiFB8Igj^< zqa&L~j#`|PS5}jI)>Cm}7j>2J+5DU%TK>_8k@F=Cv);)tnC&?Fo4Jd>?u7uGbFW*}5#zoP`d2~HNavYbXd-9h8mup-USd*;_dr%*kp5VD>8)0FNhCNkQn>jcWNrY96iqih}aNHeM)r90b|{ t@DkWG{u87VwFMjrsbj&6z|RH09(8oIoOC{5)gKrhWMp8f|4!E#`)@QZb7=qo literal 0 HcmV?d00001 diff --git a/src/_P105_AHT.ino b/src/_P105_AHT.ino index f0de4315b8..b11240f814 100644 --- a/src/_P105_AHT.ino +++ b/src/_P105_AHT.ino @@ -27,6 +27,8 @@ */ /** History: + * 2024-12-03 tonhuisman: Add alternative initialization for AHT10 (clone), see https://github.com/letscontrolit/ESPEasy/issues/5172 + * Small code optimization. * 2024-04-28 tonhuisman: Update plugin name and documentation as DHT20 and AM2301B actually contain an AHT20! * DHT20: https://www.adafruit.com/product/5183 (Description) * AM2301B: https://www.adafruit.com/product/5181 (Description) @@ -54,18 +56,15 @@ boolean Plugin_105(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_105; - Device[deviceCount].Type = DEVICE_TYPE_I2C; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TEMP_HUM; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = true; - Device[deviceCount].PluginStats = true; + Device[++deviceCount].Number = PLUGIN_ID_105; + Device[deviceCount].Type = DEVICE_TYPE_I2C; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TEMP_HUM; + Device[deviceCount].Ports = 0; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].PluginStats = true; break; } @@ -146,6 +145,10 @@ boolean Plugin_105(uint8_t function, struct EventStruct *event, String& string) static_cast(AHTx_device_type::AHT21_DEVICE) }; addFormSelector(F("Sensor model"), F("ahttype"), 3, options, indices, PCONFIG(1), true); addFormNote(F("Changing Sensor model will reload the page.")); + + if (static_cast(AHTx_device_type::AHT10_DEVICE) == PCONFIG(1)) { + addFormCheckBox(F("AHT10 Alternative initialization"), F("altinit"), PCONFIG(2)); + } } success = true; @@ -160,6 +163,7 @@ boolean Plugin_105(uint8_t function, struct EventStruct *event, String& string) PCONFIG(0) = 0x38; // AHT20/AHT21 only support a single I2C address. } else { PCONFIG(0) = getFormItemInt(F("i2c_addr")); + PCONFIG(2) = isFormItemChecked(F("altinit")) ? 1 : 0; } success = true; break; @@ -169,7 +173,7 @@ boolean Plugin_105(uint8_t function, struct EventStruct *event, String& string) { success = initPluginTaskData( event->TaskIndex, - new (std::nothrow) P105_data_struct(PCONFIG(0), static_cast(PCONFIG(1)))); + new (std::nothrow) P105_data_struct(PCONFIG(0), static_cast(PCONFIG(1)), 1 == PCONFIG(2))); break; } diff --git a/src/src/PluginStructs/P105_data_struct.cpp b/src/src/PluginStructs/P105_data_struct.cpp index 04f653108f..b653ea4d11 100644 --- a/src/src/PluginStructs/P105_data_struct.cpp +++ b/src/src/PluginStructs/P105_data_struct.cpp @@ -22,11 +22,12 @@ struct AHTx_Status { const uint8_t status; }; -AHTx_Device::AHTx_Device(uint8_t addr, AHTx_device_type type) : +AHTx_Device::AHTx_Device(uint8_t addr, AHTx_device_type type, bool altInit) : i2cAddress(addr), device_type(type), last_hum_val(0.0f), - last_temp_val(0.0f) {} + last_temp_val(0.0f), + alt_init(altInit) {} const __FlashStringHelper * AHTx_Device::getDeviceName() const { switch (device_type) { @@ -38,8 +39,11 @@ const __FlashStringHelper * AHTx_Device::getDeviceName() const { } bool AHTx_Device::initialize() { - const uint8_t cmd_init = (device_type == AHTx_device_type::AHT10_DEVICE) ? 0xE1 : 0xBE; + const uint8_t cmd_init = (AHTx_device_type::AHT10_DEVICE == device_type) ? 0xE1 : 0xBE; + if ((AHTx_device_type::AHT10_DEVICE == device_type) && alt_init) { + return I2C_write8(i2cAddress, 0xBA); // Soft reset only + } return I2C_write16_reg(i2cAddress, cmd_init, 0x0800); } @@ -92,8 +96,8 @@ bool AHTx_Device::readData() { return true; } -P105_data_struct::P105_data_struct(uint8_t addr, AHTx_device_type dev) : - device(addr, dev), +P105_data_struct::P105_data_struct(uint8_t addr, AHTx_device_type dev, bool altInit) : + device(addr, dev, altInit), state(AHTx_state::AHTx_Uninitialized), last_measurement(0), trigger_time(0) {} diff --git a/src/src/PluginStructs/P105_data_struct.h b/src/src/PluginStructs/P105_data_struct.h index d358ee61e7..ba3ebbd0fd 100644 --- a/src/src/PluginStructs/P105_data_struct.h +++ b/src/src/PluginStructs/P105_data_struct.h @@ -23,7 +23,8 @@ class AHTx_Device { public: AHTx_Device(uint8_t addr, - AHTx_device_type type); + AHTx_device_type type, + bool altInit); AHTx_Device() = delete; const __FlashStringHelper* getDeviceName() const; @@ -48,11 +49,13 @@ class AHTx_Device { const AHTx_device_type device_type; float last_hum_val = 0.0f; float last_temp_val = 0.0f; + bool alt_init = false; }; struct P105_data_struct : public PluginTaskData_base { P105_data_struct(uint8_t addr, - AHTx_device_type dev); + AHTx_device_type dev, + bool altInit); P105_data_struct() = delete; virtual ~P105_data_struct() = default;