Add I2C bus2 support to LM75AD temperature sensor

This commit is contained in:
Theo Arends 2023-10-21 15:42:32 +02:00
parent bec0c27750
commit 6efe2ab514
4 changed files with 20 additions and 20 deletions

View File

@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- I2C bus2 support to SHTxX temperature and humidity sensor - I2C bus2 support to SHTxX temperature and humidity sensor
- I2C bus2 support to HYTxxx temperature and humidity sensor - I2C bus2 support to HYTxxx temperature and humidity sensor
- I2C bus2 support to SI1145/6/7 Ultra violet index and light sensor - I2C bus2 support to SI1145/6/7 Ultra violet index and light sensor
- I2C bus2 support to LM75AD temperature sensor
### Breaking Changed ### Breaking Changed

View File

@ -40,7 +40,7 @@ Index | Define | Driver | Device | Address(es) | Bus2 | Descrip
19 | USE_SI1145 | xsns_24 | SI1145 | 0x60 | Yes | Ultra violet index and light sensor 19 | USE_SI1145 | xsns_24 | SI1145 | 0x60 | Yes | Ultra violet index and light sensor
19 | USE_SI1145 | xsns_24 | SI1146 | 0x60 | Yes | Ultra violet index and light sensor 19 | USE_SI1145 | xsns_24 | SI1146 | 0x60 | Yes | Ultra violet index and light sensor
19 | USE_SI1145 | xsns_24 | SI1147 | 0x60 | Yes | Ultra violet index and light sensor 19 | USE_SI1145 | xsns_24 | SI1147 | 0x60 | Yes | Ultra violet index and light sensor
20 | USE_LM75AD | xsns_26 | LM75AD | 0x48 - 0x4F | | Temperature sensor 20 | USE_LM75AD | xsns_26 | LM75AD | 0x48 - 0x4F | Yes | Temperature sensor
21 | USE_APDS9960 | xsns_27 | APDS9960 | 0x39 | | Proximity ambient light RGB and gesture sensor 21 | USE_APDS9960 | xsns_27 | APDS9960 | 0x39 | | Proximity ambient light RGB and gesture sensor
22 | USE_MCP230xx | xsns_29 | MCP23008 | 0x20 - 0x26 | | 8-bit I/O expander 22 | USE_MCP230xx | xsns_29 | MCP23008 | 0x20 - 0x26 | | 8-bit I/O expander
22 | USE_MCP230xx | xsns_29 | MCP23017 | 0x20 - 0x26 | | 16-bit I/O expander 22 | USE_MCP230xx | xsns_29 | MCP23017 | 0x20 - 0x26 | | 16-bit I/O expander

View File

@ -120,6 +120,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- I2C bus2 support to SHTxX temperature and humidity sensor - I2C bus2 support to SHTxX temperature and humidity sensor
- I2C bus2 support to HYTxxx temperature and humidity sensor - I2C bus2 support to HYTxxx temperature and humidity sensor
- I2C bus2 support to SI1145/6/7 Ultra violet index and light sensor - I2C bus2 support to SI1145/6/7 Ultra violet index and light sensor
- I2C bus2 support to LM75AD temperature sensor
### Breaking Changed ### Breaking Changed

View File

@ -47,31 +47,30 @@
bool lm75ad_type = false; bool lm75ad_type = false;
uint8_t lm75ad_address; uint8_t lm75ad_address;
uint8_t lm75ad_bus;
uint8_t lm75ad_addresses[] = { LM75AD_ADDRESS1, LM75AD_ADDRESS2, LM75AD_ADDRESS3, LM75AD_ADDRESS4, LM75AD_ADDRESS5, LM75AD_ADDRESS6, LM75AD_ADDRESS7, LM75AD_ADDRESS8 }; uint8_t lm75ad_addresses[] = { LM75AD_ADDRESS1, LM75AD_ADDRESS2, LM75AD_ADDRESS3, LM75AD_ADDRESS4, LM75AD_ADDRESS5, LM75AD_ADDRESS6, LM75AD_ADDRESS7, LM75AD_ADDRESS8 };
void LM75ADDetect(void) void LM75ADDetect(void) {
{ for (lm75ad_bus = 0; lm75ad_bus < 2; lm75ad_bus++) {
for (uint32_t i = 0; i < sizeof(lm75ad_addresses); i++) { for (uint32_t i = 0; i < sizeof(lm75ad_addresses); i++) {
lm75ad_address = lm75ad_addresses[i]; lm75ad_address = lm75ad_addresses[i];
if (!I2cSetDevice(lm75ad_address)) { if (!I2cSetDevice(lm75ad_address, lm75ad_bus)) { continue; } // do not make the next step without a confirmed device on the bus
continue; // do not make the next step without a confirmed device on the bus uint16_t buffer;
} if (I2cValidRead16(&buffer, lm75ad_address, LM75_THYST_REGISTER, lm75ad_bus)) {
uint16_t buffer; if (buffer == 0x4B00) {
if (I2cValidRead16(&buffer, lm75ad_address, LM75_THYST_REGISTER)) { lm75ad_type = true;
if (buffer == 0x4B00) { I2cSetActiveFound(lm75ad_address, "LM75AD", lm75ad_bus);
lm75ad_type = true; return;
I2cSetActiveFound(lm75ad_address, "LM75AD"); }
break;
} }
} }
} }
} }
float LM75ADGetTemp(void) float LM75ADGetTemp(void) {
{
int16_t sign = 1; int16_t sign = 1;
uint16_t t = I2cRead16(lm75ad_address, LM75_TEMP_REGISTER); uint16_t t = I2cRead16(lm75ad_address, LM75_TEMP_REGISTER, lm75ad_bus);
if (t & 0x8000) { // we are getting a negative temperature value if (t & 0x8000) { // we are getting a negative temperature value
t = (~t) +0x20; t = (~t) +0x20;
sign = -1; sign = -1;
@ -80,14 +79,13 @@ float LM75ADGetTemp(void)
return ConvertTemp(sign * t * 0.125f); return ConvertTemp(sign * t * 0.125f);
} }
void LM75ADShow(bool json) void LM75ADShow(bool json) {
{
float t = LM75ADGetTemp(); float t = LM75ADGetTemp();
if (json) { if (json) {
ResponseAppend_P(JSON_SNS_F_TEMP, "LM75AD", Settings->flag2.temperature_resolution, &t); ResponseAppend_P(JSON_SNS_F_TEMP, "LM75AD", Settings->flag2.temperature_resolution, &t);
#ifdef USE_DOMOTICZ #ifdef USE_DOMOTICZ
if (0 == TasmotaGlobal.tele_period) DomoticzFloatSensor(DZ_TEMP, t); if (0 == TasmotaGlobal.tele_period) { DomoticzFloatSensor(DZ_TEMP, t); }
#endif // USE_DOMOTICZ #endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
} else { } else {