mirror of https://github.com/arendst/Tasmota.git
Add support for up to 4 INA226 Voltage and Current sensors
Add support for up to 4 INA226 Voltage and Current sensors by Steve Rogers (#6342)
This commit is contained in:
parent
9aceadc217
commit
3d9a73f826
|
@ -1,6 +1,7 @@
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* 6.6.0.11 20190907
|
* 6.6.0.11 20190907
|
||||||
* Change Settings crc calculation allowing short term backward compatibility
|
* Change Settings crc calculation allowing short term backward compatibility
|
||||||
|
* Add support for up to 4 INA226 Voltage and Current sensors by Steve Rogers (#6342)
|
||||||
*
|
*
|
||||||
* 6.6.0.10 20190905
|
* 6.6.0.10 20190905
|
||||||
* Redesign Tuya support by Shantur Rathore (#6353)
|
* Redesign Tuya support by Shantur Rathore (#6353)
|
||||||
|
|
|
@ -341,6 +341,7 @@
|
||||||
// #define USE_ADS1115 // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
|
// #define USE_ADS1115 // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
|
||||||
// #define USE_ADS1115_I2CDEV // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
|
// #define USE_ADS1115_I2CDEV // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
|
||||||
// #define USE_INA219 // Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code)
|
// #define USE_INA219 // Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code)
|
||||||
|
// #define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
|
||||||
#define USE_SHT3X // Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code)
|
#define USE_SHT3X // Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code)
|
||||||
// #define USE_TSL2561 // Enable TSL2561 sensor (I2C address 0x29, 0x39 or 0x49) using library Joba_Tsl2561 (+2k3 code)
|
// #define USE_TSL2561 // Enable TSL2561 sensor (I2C address 0x29, 0x39 or 0x49) using library Joba_Tsl2561 (+2k3 code)
|
||||||
// #define USE_MGS // Enable Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
|
// #define USE_MGS // Enable Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
|
||||||
|
|
|
@ -376,7 +376,7 @@ struct SYSCFG {
|
||||||
uint16_t ina226_r_shunt[4]; // E20
|
uint16_t ina226_r_shunt[4]; // E20
|
||||||
uint16_t ina226_i_fs[4]; // E28
|
uint16_t ina226_i_fs[4]; // E28
|
||||||
|
|
||||||
uint8_t free_e20[456]; // E30
|
uint8_t free_e30[456]; // E30
|
||||||
|
|
||||||
uint32_t cfg_timestamp; // FF8
|
uint32_t cfg_timestamp; // FF8
|
||||||
uint32_t cfg_crc32; // FFC
|
uint32_t cfg_crc32; // FFC
|
||||||
|
|
|
@ -108,6 +108,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
||||||
#define USE_ADS1115 // Add I2C code for ADS1115 16 bit A/D converter based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
|
#define USE_ADS1115 // Add I2C code for ADS1115 16 bit A/D converter based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
|
||||||
//#define USE_ADS1115_I2CDEV // Add I2C code for ADS1115 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
|
//#define USE_ADS1115_I2CDEV // Add I2C code for ADS1115 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
|
||||||
#define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code)
|
#define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code)
|
||||||
|
//#define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
|
||||||
#define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code)
|
#define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code)
|
||||||
#define USE_TSL2561 // Add I2C code for TSL2561 sensor using library Adafruit TSL2561 Arduino (+1k2 code)
|
#define USE_TSL2561 // Add I2C code for TSL2561 sensor using library Adafruit TSL2561 Arduino (+1k2 code)
|
||||||
#define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
|
#define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
|
||||||
|
|
|
@ -438,9 +438,13 @@ void GetFeatures(void)
|
||||||
#ifdef USE_IBEACON
|
#ifdef USE_IBEACON
|
||||||
feature5 |= 0x00000004; // xsns_52_ibeacon.ino
|
feature5 |= 0x00000004; // xsns_52_ibeacon.ino
|
||||||
#endif
|
#endif
|
||||||
// feature5 |= 0x00000008;
|
#ifdef USE_SML_M
|
||||||
|
feature5 |= 0x00000008; // xsns_53_sml.ino
|
||||||
|
#endif
|
||||||
|
|
||||||
// feature5 |= 0x00000010;
|
#ifdef USE_INA226
|
||||||
|
feature5 |= 0x00000010; // xsns_54_ina226.ino
|
||||||
|
#endif
|
||||||
// feature5 |= 0x00000020;
|
// feature5 |= 0x00000020;
|
||||||
// feature5 |= 0x00000040;
|
// feature5 |= 0x00000040;
|
||||||
// feature5 |= 0x00000080;
|
// feature5 |= 0x00000080;
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
/*
|
/*
|
||||||
xsns_54_ina226.ino - INA226 Current Sensor support for Sonoff-Tasmota
|
xsns_54_ina226.ino - INA226 Current Sensor support for Sonoff-Tasmota
|
||||||
|
|
||||||
Copyright (C) 2019 Stephen Rodgers and Theo Arends
|
Copyright (C) 2019 Stephen Rodgers and Theo Arends
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef USE_I2C
|
||||||
|
#ifdef USE_INA226
|
||||||
/*
|
/*
|
||||||
* Setup a single INA226 device at address 0x40:
|
* Setup a single INA226 device at address 0x40:
|
||||||
*
|
*
|
||||||
|
@ -58,10 +64,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Conditional compilation of driver
|
|
||||||
#ifdef USE_INA226
|
|
||||||
|
|
||||||
// Define driver ID
|
// Define driver ID
|
||||||
|
|
||||||
#define XSNS_54 54
|
#define XSNS_54 54
|
||||||
|
@ -522,12 +524,12 @@ void Ina226Show(bool json)
|
||||||
* It provides the Tasmota callback IDs.
|
* It provides the Tasmota callback IDs.
|
||||||
*
|
*
|
||||||
* @param byte callback_id Tasmota function ID.
|
* @param byte callback_id Tasmota function ID.
|
||||||
* @return boolean Return value.
|
* @return bool Return value.
|
||||||
* @pre None.
|
* @pre None.
|
||||||
* @post None.
|
* @post None.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
boolean Xsns54(byte callback_id) {
|
bool Xsns54(byte callback_id) {
|
||||||
|
|
||||||
// Set return value to `false`
|
// Set return value to `false`
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
@ -537,14 +539,12 @@ if(i2c_flg) {
|
||||||
|
|
||||||
// Check which callback ID is called by Tasmota
|
// Check which callback ID is called by Tasmota
|
||||||
switch (callback_id) {
|
switch (callback_id) {
|
||||||
case FUNC_INIT:
|
|
||||||
Ina226Init();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_50_MSECOND:
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
Ina226EverySecond();
|
Ina226EverySecond();
|
||||||
break;
|
break;
|
||||||
|
case FUNC_INIT:
|
||||||
|
Ina226Init();
|
||||||
|
break;
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
Ina226Show(1);
|
Ina226Show(1);
|
||||||
break;
|
break;
|
||||||
|
@ -553,8 +553,6 @@ if(i2c_flg) {
|
||||||
Ina226Show(0);
|
Ina226Show(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
case FUNC_SAVE_BEFORE_RESTART:
|
|
||||||
break;
|
|
||||||
case FUNC_COMMAND_SENSOR:
|
case FUNC_COMMAND_SENSOR:
|
||||||
if (XSNS_54 == XdrvMailbox.index) {
|
if (XSNS_54 == XdrvMailbox.index) {
|
||||||
result = Ina226CommandSensor();
|
result = Ina226CommandSensor();
|
||||||
|
@ -565,4 +563,6 @@ if(i2c_flg) {
|
||||||
// Return boolean result
|
// Return boolean result
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif // USE_<driver_name>
|
|
||||||
|
#endif // USE_INA226
|
||||||
|
#endif // USE_I2C
|
||||||
|
|
|
@ -86,17 +86,22 @@ a_setoption = [[
|
||||||
],[
|
],[
|
||||||
"Key hold time (ms)",
|
"Key hold time (ms)",
|
||||||
"Sonoff POW Max_Power_Retry",
|
"Sonoff POW Max_Power_Retry",
|
||||||
"Tuya dimmer device id",
|
"(not used) Tuya MCU device id",
|
||||||
"(not used) mDNS delayed start (Sec)",
|
"(not used) mDNS delayed start (Sec)",
|
||||||
"Boot loop retry offset (0 = disable)",
|
"Boot loop retry offset (0 = disable)",
|
||||||
"RGBWW remap",
|
"RGBWW remap",
|
||||||
"IR Unknown threshold",
|
"IR Unknown threshold",
|
||||||
"CSE7766 invalid power margin",
|
"CSE7766 invalid power margin",
|
||||||
"Ignore hold time (s)",
|
"Ignore hold time (s)",
|
||||||
"Number of Tuya relays",
|
"(not used) Number of Tuya MCU relays",
|
||||||
"Over temperature threshold (celsius)",
|
"Over temperature threshold (celsius)",
|
||||||
|
"Tuya MCU max dimmer value",
|
||||||
|
"(not used) Tuya MCU voltage Id",
|
||||||
|
"(not used) Tuya MCU current Id",
|
||||||
|
"(not used) Tuya MCU power Id",
|
||||||
|
"Energy Tariff1 start hour",
|
||||||
|
"Energy Tariff2 start hour",
|
||||||
"",
|
"",
|
||||||
"","","","","","",
|
|
||||||
],[
|
],[
|
||||||
"Timers enabled",
|
"Timers enabled",
|
||||||
"Generic ESP8285 GPIO enabled",
|
"Generic ESP8285 GPIO enabled",
|
||||||
|
@ -113,12 +118,13 @@ a_setoption = [[
|
||||||
"Do not use retain flag on HOLD messages",
|
"Do not use retain flag on HOLD messages",
|
||||||
"Do not scan relay power state at restart",
|
"Do not scan relay power state at restart",
|
||||||
"Use _ instead of - as sensor index separator",
|
"Use _ instead of - as sensor index separator",
|
||||||
"Disable Dimmer slider control",
|
"(not used) Disable Dimmer slider control",
|
||||||
"Disable Dimmer range 255 slider control",
|
"Disable Dimmer range 255 slider control",
|
||||||
"Enable buzzer when available",
|
"Enable buzzer when available",
|
||||||
"Enable multi-channels PWM instead of Color PWM",
|
"Enable multi-channels PWM instead of Color PWM",
|
||||||
"",
|
"Limits Tuya MCU dimmers to minimum of 10% (25) when enabled",
|
||||||
"","","","",
|
"Enable Weekend Energy Tariff",
|
||||||
|
"","","",
|
||||||
"","","","",
|
"","","","",
|
||||||
"","","",""
|
"","","",""
|
||||||
]]
|
]]
|
||||||
|
@ -160,8 +166,8 @@ a_features = [[
|
||||||
"USE_ADE7953","USE_SPS30","USE_VL53L0X","USE_MLX90614",
|
"USE_ADE7953","USE_SPS30","USE_VL53L0X","USE_MLX90614",
|
||||||
"USE_MAX31865","USE_CHIRP","USE_SOLAX_X1","USE_PAJ7620"
|
"USE_MAX31865","USE_CHIRP","USE_SOLAX_X1","USE_PAJ7620"
|
||||||
],[
|
],[
|
||||||
"USE_BUZZER","USE_RDM6300","USE_IBEACON","",
|
"USE_BUZZER","USE_RDM6300","USE_IBEACON","USE_SML_M",
|
||||||
"","","","",
|
"USE_INA226","","","",
|
||||||
"","","","",
|
"","","","",
|
||||||
"","","","",
|
"","","","",
|
||||||
"","","","",
|
"","","","",
|
||||||
|
|
Loading…
Reference in New Issue