diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 186ff457e550..2689a72229be 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -3,6 +3,7 @@ ### 8.1.0.9 20200220 - Revert most wifi connectivity changes introduced in 8.1.0.5 (#7746, #7602, #7621) +- Add initial support for Sensors AHT10 and AHT15 by Martin Wagner (#7596) ### 8.1.0.8 20200212 diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index 615ff8919ad8..c148efd9fd33 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -164,6 +164,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack //#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 Honywell HIH Humidity and Temperature sensor (I2C address 0x27) (+0k6) +//#define USE_AHT1x // Enable AHT10/15 humidity and temperature sensor (I2C address 0x38) (+0k8 code) #define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code) #define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code) diff --git a/tasmota/xsns_63_aht1x.ino b/tasmota/xsns_63_aht1x.ino index b3b17e0e4d48..542cb72ea18f 100644 --- a/tasmota/xsns_63_aht1x.ino +++ b/tasmota/xsns_63_aht1x.ino @@ -30,10 +30,10 @@ #define AHT10_ADDR 0x38 -unsigned char eSensorCalibrateCmd[3] = {0xE1, 0x08, 0x00}; -unsigned char eSensorNormalCmd[3] = {0xA8, 0x00, 0x00}; -unsigned char eSensorMeasureCmd[3] = {0xAC, 0x33, 0x00}; -unsigned char eSensorResetCmd = 0xBA; +uint8_t eSensorCalibrateCmd[3] = {0xE1, 0x08, 0x00}; +uint8_t eSensorNormalCmd[3] = {0xA8, 0x00, 0x00}; +uint8_t eSensorMeasureCmd[3] = {0xAC, 0x33, 0x00}; +uint8_t eSensorResetCmd = 0xBA; struct AHT10 { float humidity = NAN; @@ -43,75 +43,73 @@ struct AHT10 { char name[6] = "AHT1x"; } AHT10; - bool AHT10Read(void) { - unsigned long result_t, result_h, data[6]; - if (AHT10.valid) { AHT10.valid--; } - Wire.beginTransmission(AHT10_ADDR); - Wire.write(eSensorMeasureCmd, 3); - Wire.endTransmission(); - delay(100); + uint8_t data[6]; + + Wire.beginTransmission(AHT10_ADDR); + Wire.write(eSensorMeasureCmd, 3); + Wire.endTransmission(); + delay(100); + + Wire.requestFrom(AHT10_ADDR, 6); + for (uint32_t i = 0; Wire.available() > 0; i++) { + data[i] = Wire.read(); + } - Wire.requestFrom(AHT10_ADDR, 6); - for(uint8_t i = 0; Wire.available() > 0; i++) - { - data[i] = Wire.read(); - } + uint32_t result_h = ((data[1] << 16) | (data[2] << 8) | data[3]) >> 4; + uint32_t result_t = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5]; - result_h = ((data[1] << 16) | (data[2] << 8) | data[3]) >> 4; - result_t = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5]; + float humidity = result_h * 100 / 1048576; + float temperature = ((200 * result_t) / 1048576) - 50; - AHT10.humidity = result_h * 100 / 1048576; - AHT10.temperature = ((200 * result_t) / 1048576) - 50; + if (isnan(temperature) || isnan(humidity)) { return false; } - if (isnan(AHT10.temperature) || isnan(AHT10.humidity)) { return false; } + AHT10.humidity = ConvertHumidity(humidity); + AHT10.temperature = ConvertTemp(temperature); AHT10.valid = SENSOR_MAX_MISS; return true; } /********************************************************************************************/ -bool AHT10Init() + +bool AHT10Init(void) { - Wire.begin(AHT10_ADDR); - Wire.beginTransmission(AHT10_ADDR); - Wire.write(eSensorCalibrateCmd, 3); - Wire.endTransmission(); - delay(500); - - if((AHT10ReadStatus() & 0x68) == 0x08) { - return true;} - else - { return false; } + Wire.begin(AHT10_ADDR); + Wire.beginTransmission(AHT10_ADDR); + Wire.write(eSensorCalibrateCmd, 3); + Wire.endTransmission(); + + delay(500); // ?!?! too long + + return (0x08 == (AHT10ReadStatus() & 0x68)); } -unsigned char AHT10ReadStatus(void) +uint8_t AHT10ReadStatus(void) { - unsigned char result = 0; - Wire.requestFrom(AHT10_ADDR, 1); - result = Wire.read(); - return result; + Wire.requestFrom(AHT10_ADDR, 1); + uint8_t result = Wire.read(); + return result; } void AHT10Reset(void) { - Wire.beginTransmission(AHT10_ADDR); - Wire.write(eSensorResetCmd); - Wire.endTransmission(); - delay(20); + Wire.beginTransmission(AHT10_ADDR); + Wire.write(eSensorResetCmd); + Wire.endTransmission(); + delay(20); } /********************************************************************************************/ + void AHT10Detect(void) { - if (I2cActive(AHT10_ADDR)) - {return;} + if (I2cActive(AHT10_ADDR)) { return; } - if (AHT10Init()) - { + if (AHT10Init()) { I2cSetActiveFound(AHT10_ADDR, AHT10.name); AHT10.count = 1; } diff --git a/tools/decode-status.py b/tools/decode-status.py index f4d00833a6f8..210175de88d2 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -193,7 +193,7 @@ "USE_ARDUINO_SLAVE","USE_HIH6","USE_HPMA","USE_TSL2591", "USE_DHT12","USE_DS1624","USE_GPS","USE_HOTPLUG", "USE_NRF24","USE_MIBLE","USE_HM10","USE_LE01MR", - "","","","" + "USE_AHT1x","","","" ],[ "","","","", "","","","", @@ -236,7 +236,7 @@ obj = json.load(fp) def StartDecode(): - print ("\n*** decode-status.py v20200210 by Theo Arends and Jacek Ziolkowski ***") + print ("\n*** decode-status.py v20200220 by Theo Arends and Jacek Ziolkowski ***") # print("Decoding\n{}".format(obj))