mirror of https://github.com/arendst/Tasmota.git
Add experimental SI7021 support
* Add (experimental) support for iTead SI7021 temperature and humidity sensor (#735) * Change ADS1115 default voltage range from +/-2V to +/-6V (#1289)
This commit is contained in:
parent
c102fc5f9e
commit
253d60fd2b
|
@ -1,6 +1,7 @@
|
||||||
/* 5.10.0a
|
/* 5.10.0a
|
||||||
* Add (experimental) support for sensor SHT3x
|
* Add (experimental) support for sensor SHT3x
|
||||||
* Change ADS1115 default voltage range from +/-2V to +/-4V (#1289)
|
* Add (experimental) support for iTead SI7021 temperature and humidity sensor (#735)
|
||||||
|
* Change ADS1115 default voltage range from +/-2V to +/-6V (#1289)
|
||||||
* Add multipress support and more user configurable options to Sonoff Dual R2 (#1291)
|
* Add multipress support and more user configurable options to Sonoff Dual R2 (#1291)
|
||||||
*
|
*
|
||||||
* 5.10.0 20171201
|
* 5.10.0 20171201
|
||||||
|
|
|
@ -460,7 +460,7 @@
|
||||||
#define D_SENSOR_NONE "None"
|
#define D_SENSOR_NONE "None"
|
||||||
#define D_SENSOR_DHT11 "DHT11"
|
#define D_SENSOR_DHT11 "DHT11"
|
||||||
#define D_SENSOR_AM2301 "AM2301"
|
#define D_SENSOR_AM2301 "AM2301"
|
||||||
#define D_SENSOR_DHT22 "DHT22"
|
#define D_SENSOR_SI7021 "SI7021"
|
||||||
#define D_SENSOR_DS18X20 "DS18x20"
|
#define D_SENSOR_DS18X20 "DS18x20"
|
||||||
#define D_SENSOR_I2C_SCL "I2C SCL"
|
#define D_SENSOR_I2C_SCL "I2C SCL"
|
||||||
#define D_SENSOR_I2C_SDA "I2C SDA"
|
#define D_SENSOR_I2C_SDA "I2C SDA"
|
||||||
|
|
|
@ -460,7 +460,7 @@
|
||||||
#define D_SENSOR_NONE "None"
|
#define D_SENSOR_NONE "None"
|
||||||
#define D_SENSOR_DHT11 "DHT11"
|
#define D_SENSOR_DHT11 "DHT11"
|
||||||
#define D_SENSOR_AM2301 "AM2301"
|
#define D_SENSOR_AM2301 "AM2301"
|
||||||
#define D_SENSOR_DHT22 "DHT22"
|
#define D_SENSOR_SI7021 "SI7021"
|
||||||
#define D_SENSOR_DS18X20 "DS18x20"
|
#define D_SENSOR_DS18X20 "DS18x20"
|
||||||
#define D_SENSOR_I2C_SCL "I2C SCL"
|
#define D_SENSOR_I2C_SCL "I2C SCL"
|
||||||
#define D_SENSOR_I2C_SDA "I2C SDA"
|
#define D_SENSOR_I2C_SDA "I2C SDA"
|
||||||
|
|
|
@ -460,7 +460,7 @@
|
||||||
#define D_SENSOR_NONE "Geen"
|
#define D_SENSOR_NONE "Geen"
|
||||||
#define D_SENSOR_DHT11 "DHT11"
|
#define D_SENSOR_DHT11 "DHT11"
|
||||||
#define D_SENSOR_AM2301 "AM2301"
|
#define D_SENSOR_AM2301 "AM2301"
|
||||||
#define D_SENSOR_DHT22 "DHT22"
|
#define D_SENSOR_SI7021 "SI7021"
|
||||||
#define D_SENSOR_DS18X20 "DS18x20"
|
#define D_SENSOR_DS18X20 "DS18x20"
|
||||||
#define D_SENSOR_I2C_SCL "I2C SCL"
|
#define D_SENSOR_I2C_SCL "I2C SCL"
|
||||||
#define D_SENSOR_I2C_SDA "I2C SDA"
|
#define D_SENSOR_I2C_SDA "I2C SDA"
|
||||||
|
|
|
@ -460,7 +460,7 @@
|
||||||
#define D_SENSOR_NONE "Brak"
|
#define D_SENSOR_NONE "Brak"
|
||||||
#define D_SENSOR_DHT11 "DHT11"
|
#define D_SENSOR_DHT11 "DHT11"
|
||||||
#define D_SENSOR_AM2301 "AM2301"
|
#define D_SENSOR_AM2301 "AM2301"
|
||||||
#define D_SENSOR_DHT22 "DHT22"
|
#define D_SENSOR_SI7021 "SI7021"
|
||||||
#define D_SENSOR_DS18X20 "DS18x20"
|
#define D_SENSOR_DS18X20 "DS18x20"
|
||||||
#define D_SENSOR_I2C_SCL "I2C SCL"
|
#define D_SENSOR_I2C_SCL "I2C SCL"
|
||||||
#define D_SENSOR_I2C_SDA "I2C SDA"
|
#define D_SENSOR_I2C_SDA "I2C SDA"
|
||||||
|
|
|
@ -2376,34 +2376,36 @@ void SerialInput()
|
||||||
serial_in_byte = Serial.read();
|
serial_in_byte = Serial.read();
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------------------------*\
|
||||||
* Sonoff dual 19200 baud serial interface
|
* Sonoff dual and ch4 19200 baud serial interface
|
||||||
\*-------------------------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------------------------*/
|
||||||
|
if ((SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) {
|
||||||
if (dual_hex_code) {
|
|
||||||
dual_hex_code--;
|
|
||||||
if (dual_hex_code) {
|
if (dual_hex_code) {
|
||||||
dual_button_code = (dual_button_code << 8) | serial_in_byte;
|
dual_hex_code--;
|
||||||
serial_in_byte = 0;
|
if (dual_hex_code) {
|
||||||
} else {
|
dual_button_code = (dual_button_code << 8) | serial_in_byte;
|
||||||
if (serial_in_byte != 0xA1) {
|
serial_in_byte = 0;
|
||||||
dual_button_code = 0; // 0xA1 - End of Sonoff dual button code
|
} else {
|
||||||
|
if (serial_in_byte != 0xA1) {
|
||||||
|
dual_button_code = 0; // 0xA1 - End of Sonoff dual button code
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (0xA0 == serial_in_byte) { // 0xA0 - Start of Sonoff dual button code
|
||||||
if (0xA0 == serial_in_byte) { // 0xA0 - Start of Sonoff dual button code
|
serial_in_byte = 0;
|
||||||
serial_in_byte = 0;
|
dual_button_code = 0;
|
||||||
dual_button_code = 0;
|
dual_hex_code = 3;
|
||||||
dual_hex_code = 3;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------------------------*\
|
||||||
* Sonoff bridge 19200 baud serial interface
|
* Sonoff bridge 19200 baud serial interface
|
||||||
\*-------------------------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------------------------*/
|
||||||
|
if (SONOFF_BRIDGE == Settings.module) {
|
||||||
if (SonoffBridgeSerialInput()) {
|
if (SonoffBridgeSerialInput()) {
|
||||||
serial_in_byte_counter = 0;
|
serial_in_byte_counter = 0;
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
@ -2424,7 +2426,6 @@ void SerialInput()
|
||||||
/*-------------------------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------------------------*\
|
||||||
* Sonoff SC 19200 baud serial interface
|
* Sonoff SC 19200 baud serial interface
|
||||||
\*-------------------------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
if (serial_in_byte == '\x1B') { // Sonoff SC status from ATMEGA328P
|
if (serial_in_byte == '\x1B') { // Sonoff SC status from ATMEGA328P
|
||||||
serial_in_buffer[serial_in_byte_counter] = 0; // serial data completed
|
serial_in_buffer[serial_in_byte_counter] = 0; // serial data completed
|
||||||
SonoffScSerialInput(serial_in_buffer);
|
SonoffScSerialInput(serial_in_buffer);
|
||||||
|
@ -2494,7 +2495,7 @@ void GpioInit()
|
||||||
mpin -= (GPIO_PWM1_INV - GPIO_PWM1);
|
mpin -= (GPIO_PWM1_INV - GPIO_PWM1);
|
||||||
}
|
}
|
||||||
#ifdef USE_DHT
|
#ifdef USE_DHT
|
||||||
else if ((mpin >= GPIO_DHT11) && (mpin <= GPIO_DHT22)) {
|
else if ((mpin >= GPIO_DHT11) && (mpin <= GPIO_SI7021)) {
|
||||||
if (DhtSetup(i, mpin)) {
|
if (DhtSetup(i, mpin)) {
|
||||||
dht_flg = 1;
|
dht_flg = 1;
|
||||||
mpin = GPIO_DHT11;
|
mpin = GPIO_DHT11;
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
enum UserSelectablePins {
|
enum UserSelectablePins {
|
||||||
GPIO_NONE, // Not used
|
GPIO_NONE, // Not used
|
||||||
GPIO_DHT11, // DHT11
|
GPIO_DHT11, // DHT11
|
||||||
GPIO_DHT21, // DHT21, AM2301
|
GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321
|
||||||
GPIO_DHT22, // DHT22, AM2302, AM2321
|
GPIO_SI7021, // iTead SI7021
|
||||||
GPIO_DSB, // Single wire DS18B20 or DS18S20
|
GPIO_DSB, // Single wire DS18B20 or DS18S20
|
||||||
GPIO_I2C_SCL, // I2C SCL
|
GPIO_I2C_SCL, // I2C SCL
|
||||||
GPIO_I2C_SDA, // I2C SDA
|
GPIO_I2C_SDA, // I2C SDA
|
||||||
|
@ -85,7 +85,7 @@ const char kSensors[GPIO_SENSOR_END][9] PROGMEM = {
|
||||||
D_SENSOR_NONE,
|
D_SENSOR_NONE,
|
||||||
D_SENSOR_DHT11,
|
D_SENSOR_DHT11,
|
||||||
D_SENSOR_AM2301,
|
D_SENSOR_AM2301,
|
||||||
D_SENSOR_DHT22,
|
D_SENSOR_SI7021,
|
||||||
D_SENSOR_DS18X20,
|
D_SENSOR_DS18X20,
|
||||||
D_SENSOR_I2C_SCL,
|
D_SENSOR_I2C_SCL,
|
||||||
D_SENSOR_I2C_SDA,
|
D_SENSOR_I2C_SDA,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
xsns_06_dht.ino - DHTxx and AM23xx temperature and humidity sensor support for Sonoff-Tasmota
|
xsns_06_dht.ino - DHTxx, AM23xx and SI7021 temperature and humidity sensor support for Sonoff-Tasmota
|
||||||
|
|
||||||
Copyright (C) 2017 Theo Arends
|
Copyright (C) 2017 Theo Arends
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#ifdef USE_DHT
|
#ifdef USE_DHT
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* DHT11, DHT21 (AM2301), DHT22 (AM2302, AM2321) - Temperature and Humidy
|
* DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321), SI7021 - Temperature and Humidy
|
||||||
*
|
*
|
||||||
* Reading temperature or humidity takes about 250 milliseconds!
|
* Reading temperature or humidity takes about 250 milliseconds!
|
||||||
* Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
* Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
||||||
|
@ -85,7 +85,12 @@ void DhtRead(byte sensor)
|
||||||
}
|
}
|
||||||
pinMode(Dht[sensor].pin, OUTPUT);
|
pinMode(Dht[sensor].pin, OUTPUT);
|
||||||
digitalWrite(Dht[sensor].pin, LOW);
|
digitalWrite(Dht[sensor].pin, LOW);
|
||||||
delay(20);
|
|
||||||
|
if (GPIO_SI7021 == Dht[sensor].type) {
|
||||||
|
delayMicroseconds(500);
|
||||||
|
} else {
|
||||||
|
delay(20);
|
||||||
|
}
|
||||||
|
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
digitalWrite(Dht[sensor].pin, HIGH);
|
digitalWrite(Dht[sensor].pin, HIGH);
|
||||||
|
@ -153,24 +158,18 @@ boolean DhtReadTempHum(byte sensor, float &t, float &h)
|
||||||
switch (Dht[sensor].type) {
|
switch (Dht[sensor].type) {
|
||||||
case GPIO_DHT11:
|
case GPIO_DHT11:
|
||||||
h = dht_data[0];
|
h = dht_data[0];
|
||||||
t = ConvertTemp(dht_data[2]);
|
t = dht_data[2];
|
||||||
break;
|
break;
|
||||||
case GPIO_DHT22:
|
case GPIO_DHT22:
|
||||||
case GPIO_DHT21:
|
case GPIO_SI7021:
|
||||||
h = dht_data[0];
|
h = ((dht_data[0] << 8) | dht_data[1]) * 0.1;
|
||||||
h *= 256;
|
t = (((dht_data[2] & 0x7F) << 8 ) | dht_data[3]) * 0.1;
|
||||||
h += dht_data[1];
|
|
||||||
h *= 0.1;
|
|
||||||
t = dht_data[2] & 0x7F;
|
|
||||||
t *= 256;
|
|
||||||
t += dht_data[3];
|
|
||||||
t *= 0.1;
|
|
||||||
if (dht_data[2] & 0x80) {
|
if (dht_data[2] & 0x80) {
|
||||||
t *= -1;
|
t *= -1;
|
||||||
}
|
}
|
||||||
t = ConvertTemp(t);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
t = ConvertTemp(t);
|
||||||
if (!isnan(t)) {
|
if (!isnan(t)) {
|
||||||
Dht[sensor].t = t;
|
Dht[sensor].t = t;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@
|
||||||
* Setting these values incorrectly may destroy your ADC!
|
* Setting these values incorrectly may destroy your ADC!
|
||||||
* ADS1115
|
* ADS1115
|
||||||
* -------
|
* -------
|
||||||
* ADS1115_REG_CONFIG_PGA_6_144V // 2/3x gain +/- 6.144V 1 bit = 0.1875mV
|
* ADS1115_REG_CONFIG_PGA_6_144V // 2/3x gain +/- 6.144V 1 bit = 0.1875mV (default)
|
||||||
* ADS1115_REG_CONFIG_PGA_4_096V // 1x gain +/- 4.096V 1 bit = 0.125mV (default)
|
* ADS1115_REG_CONFIG_PGA_4_096V // 1x gain +/- 4.096V 1 bit = 0.125mV
|
||||||
* ADS1115_REG_CONFIG_PGA_2_048V // 2x gain +/- 2.048V 1 bit = 0.0625mV
|
* ADS1115_REG_CONFIG_PGA_2_048V // 2x gain +/- 2.048V 1 bit = 0.0625mV
|
||||||
* ADS1115_REG_CONFIG_PGA_1_024V // 4x gain +/- 1.024V 1 bit = 0.03125mV
|
* ADS1115_REG_CONFIG_PGA_1_024V // 4x gain +/- 1.024V 1 bit = 0.03125mV
|
||||||
* ADS1115_REG_CONFIG_PGA_0_512V // 8x gain +/- 0.512V 1 bit = 0.015625mV
|
* ADS1115_REG_CONFIG_PGA_0_512V // 8x gain +/- 0.512V 1 bit = 0.015625mV
|
||||||
|
@ -75,9 +75,9 @@ CONFIG REGISTER
|
||||||
#define ADS1115_REG_CONFIG_MUX_SINGLE_3 (0x7000) // Single-ended AIN3
|
#define ADS1115_REG_CONFIG_MUX_SINGLE_3 (0x7000) // Single-ended AIN3
|
||||||
|
|
||||||
#define ADS1115_REG_CONFIG_PGA_MASK (0x0E00)
|
#define ADS1115_REG_CONFIG_PGA_MASK (0x0E00)
|
||||||
#define ADS1115_REG_CONFIG_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3
|
#define ADS1115_REG_CONFIG_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3 (default)
|
||||||
#define ADS1115_REG_CONFIG_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1
|
#define ADS1115_REG_CONFIG_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1
|
||||||
#define ADS1115_REG_CONFIG_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2 (default)
|
#define ADS1115_REG_CONFIG_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2
|
||||||
#define ADS1115_REG_CONFIG_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4
|
#define ADS1115_REG_CONFIG_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4
|
||||||
#define ADS1115_REG_CONFIG_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8
|
#define ADS1115_REG_CONFIG_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8
|
||||||
#define ADS1115_REG_CONFIG_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16
|
#define ADS1115_REG_CONFIG_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16
|
||||||
|
@ -126,7 +126,7 @@ void Ads1115StartComparator(uint8_t channel, uint16_t mode)
|
||||||
uint16_t config = mode |
|
uint16_t config = mode |
|
||||||
ADS1115_REG_CONFIG_CQUE_NONE | // Comparator enabled and asserts on 1 match
|
ADS1115_REG_CONFIG_CQUE_NONE | // Comparator enabled and asserts on 1 match
|
||||||
ADS1115_REG_CONFIG_CLAT_NONLAT | // Non Latching mode
|
ADS1115_REG_CONFIG_CLAT_NONLAT | // Non Latching mode
|
||||||
ADS1115_REG_CONFIG_PGA_4_096V | // ADC Input voltage range (Gain)
|
ADS1115_REG_CONFIG_PGA_6_144V | // ADC Input voltage range (Gain)
|
||||||
ADS1115_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
|
ADS1115_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
|
||||||
ADS1115_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
|
ADS1115_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
|
||||||
ADS1115_REG_CONFIG_DR_6000SPS; // 6000 samples per second
|
ADS1115_REG_CONFIG_DR_6000SPS; // 6000 samples per second
|
||||||
|
|
|
@ -84,7 +84,7 @@ void Ads1115Detect()
|
||||||
ADS1115 adc0(ads1115_address);
|
ADS1115 adc0(ads1115_address);
|
||||||
if (adc0.testConnection()) {
|
if (adc0.testConnection()) {
|
||||||
adc0.initialize();
|
adc0.initialize();
|
||||||
adc0.setGain(ADS1115_PGA_4P096); // Set the gain (PGA) +/-4.096V
|
adc0.setGain(ADS1115_PGA_6P144); // Set the gain (PGA) +/-6.144V
|
||||||
adc0.setRate(ADS1115_RATE_860);
|
adc0.setRate(ADS1115_RATE_860);
|
||||||
adc0.setMode(ADS1115_MODE_CONTINUOUS);
|
adc0.setMode(ADS1115_MODE_CONTINUOUS);
|
||||||
ads1115_type = 1;
|
ads1115_type = 1;
|
||||||
|
|
Loading…
Reference in New Issue