From 73547c8bd7f5c0d89aa9af5ed4649e9c0d451780 Mon Sep 17 00:00:00 2001 From: arendst Date: Sat, 2 Dec 2017 12:38:29 +0100 Subject: [PATCH] v5.10.0a - Fixes ADS1115 and Sonoff Dual R2 5.10.0a * Add (experimental) support for sensor SHT3x * Change ADS1115 default voltage range from +/-2V to +/-4V (#1289) * Add multipress support and more user configurable options to Sonoff Dual R2 (#1291) --- sonoff/README.md | 62 +++++++++++++++++++++++++++++++ sonoff/_releasenotes.ino | 2 + sonoff/sonoff.ino | 36 +++++++++--------- sonoff/sonoff_template.h | 6 +-- sonoff/xsns_12_ads1115.ino | 16 ++++---- sonoff/xsns_12_ads1115_i2cdev.ino | 2 +- sonoff/xsns_14_sht3x.ino | 11 +++--- 7 files changed, 100 insertions(+), 35 deletions(-) create mode 100644 sonoff/README.md diff --git a/sonoff/README.md b/sonoff/README.md new file mode 100644 index 000000000..45cb17c95 --- /dev/null +++ b/sonoff/README.md @@ -0,0 +1,62 @@ +## Sonoff-Tasmota +Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE. + +Current version is **5.10.0a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. + +### ATTENTION All versions + +Only Flash Mode DOUT is supported. Do not use Flash Mode DIO / QIO / QOUT as it might seem to brick your device. + +See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki/Theo's-Tasmota-Tips) for background information. + +### ATTENTION Version 5 and up + +These versions use a new linker script to free flash memory for future code additions. It moves the settings from Spiffs to Eeprom. If you compile your own firmware download the new linker to your IDE or Platformio base folder. See [Wiki > Prerequisite](https://github.com/arendst/Sonoff-Tasmota/wiki/Prerequisite). + +Best practice to implement is: +- Open the webpage to your device +- Perform option ``Backup Configuration`` +- Upgrade new firmware using ``Firmware upgrade`` +- If configuration conversion fails keep the webpage open and perform ``Restore Configuration`` + +You should now have a device with 32k more code memory to play with. + +### Version Information + +- Sonoff-Tasmota provides all (Sonoff) modules in one file and starts with module Sonoff Basic. +- Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```. +- After reboot select config menu again or use commands ```GPIOs``` and ```GPIO``` to change GPIO with desired sensor. + + + +See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki) for more information.
+See [Community](https://groups.google.com/d/forum/sonoffusers) for forum and more user experience. + +The following devices are supported: +- [iTead Sonoff Basic](https://www.itead.cc/smart-home/sonoff-wifi-wireless-switch-1.html) +- [iTead Sonoff RF](https://www.itead.cc/smart-home/sonoff-rf.html) +- [iTead Sonoff SV](https://www.itead.cc/smart-home/sonoff-sv.html) +- [iTead Sonoff TH10/TH16 with temperature sensor](https://www.itead.cc/smart-home/sonoff-th.html) +- [iTead Sonoff Dual (R2)](https://www.itead.cc/smart-home/sonoff-dual.html) +- [iTead Sonoff Pow](https://www.itead.cc/smart-home/sonoff-pow.html) +- [iTead Sonoff 4CH](https://www.itead.cc/smart-home/sonoff-4ch.html) +- [iTead Sonoff 4CH Pro](https://www.itead.cc/smart-home/sonoff-4ch-pro.html) +- [iTead S20 Smart Socket](https://www.itead.cc/smart-socket.html) +- [iTead Slampher](https://www.itead.cc/slampher.html) +- [iTead Sonoff Touch](https://www.itead.cc/sonoff-touch.html) +- [iTead Sonoff T1](https://www.itead.cc/sonoff-t1.html) +- [iTead Sonoff SC](https://www.itead.cc/sonoff-sc.html) +- [iTead Sonoff Led](https://www.itead.cc/sonoff-led.html) +- [iTead Sonoff BN-SZ01 Ceiling Led](https://www.itead.cc/bn-sz01.html) +- [iTead Sonoff B1](https://www.itead.cc/sonoff-b1.html) +- [iTead Sonoff RF Bridge 433](https://www.itead.cc/sonoff-rf-bridge-433.html) +- [iTead Sonoff Dev](https://www.itead.cc/sonoff-dev.html) +- [iTead 1 Channel Switch 5V / 12V](https://www.itead.cc/smart-home/inching-self-locking-wifi-wireless-switch.html) +- [iTead Motor Clockwise/Anticlockwise](https://www.itead.cc/smart-home/motor-reversing-wifi-wireless-switch.html) +- [Electrodragon IoT Relay Board](http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/) +- [AI Light or any my9291 compatible RGBW LED](http://www.ebay.com/itm/172644855726) +- MagicHome and AriLux AL-LC01 and AL-LC11 + +### License + +This program is licensed under GPL-3.0 \ No newline at end of file diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 80a9af330..10a0699c7 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,5 +1,7 @@ /* 5.10.0a * Add (experimental) support for sensor SHT3x + * Change ADS1115 default voltage range from +/-2V to +/-4V (#1289) + * Add multipress support and more user configurable options to Sonoff Dual R2 (#1291) * * 5.10.0 20171201 * Upgrade library ArduinoJson to 5.11.2 diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 3bb680aa2..ec33d9ee3 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1925,7 +1925,7 @@ void ButtonHandler() snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " " D_CODE " %04X"), dual_button_code); AddLog(LOG_LEVEL_DEBUG); button = PRESSED; - if (0xF500 == dual_button_code) { // Button hold + if (0xF500 == dual_button_code) { // Button hold holdbutton[i] = (Settings.param[P_HOLD_TIME] * (STATES / 10)) -1; } dual_button_code = 0; @@ -1952,28 +1952,28 @@ void ButtonHandler() if ((NOT_PRESSED == button) && (PRESSED == lastbutton[i])) { snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " %d " D_LEVEL_01), i +1); AddLog(LOG_LEVEL_DEBUG); - if (!holdbutton[i]) { // Do not allow within 1 second + if (!holdbutton[i]) { // Do not allow within 1 second button_pressed = true; } } if (button_pressed) { - if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set - ExecuteCommandPower(i +1, 2); // Execute Toggle command internally + if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set + ExecuteCommandPower(i +1, 2); // Execute Toggle command internally } } } else { if ((PRESSED == button) && (NOT_PRESSED == lastbutton[i])) { - if (Settings.flag.button_single) { // Allow only single button press for immediate action + if (Settings.flag.button_single) { // Allow only single button press for immediate action snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " %d " D_IMMEDIATE), i +1); AddLog(LOG_LEVEL_DEBUG); - if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set - ExecuteCommandPower(i +1, 2); // Execute Toggle command internally + if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set + ExecuteCommandPower(i +1, 2); // Execute Toggle command internally } } else { multipress[i] = (multiwindow[i]) ? multipress[i] +1 : 1; snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " %d " D_MULTI_PRESS " %d"), i +1, multipress[i]); AddLog(LOG_LEVEL_DEBUG); - multiwindow[i] = STATES /2; // 0.5 second multi press window + multiwindow[i] = STATES /2; // 0.5 second multi press window } blinks = 201; } @@ -1982,33 +1982,33 @@ void ButtonHandler() holdbutton[i] = 0; } else { holdbutton[i]++; - if (Settings.flag.button_single) { // Allow only single button press for immediate action + if (Settings.flag.button_single) { // Allow only single button press for immediate action if (holdbutton[i] == Settings.param[P_HOLD_TIME] * (STATES / 10) * 4) { // Button hold for four times longer // Settings.flag.button_single = 0; snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_SETOPTION "13 0")); // Disable single press only ExecuteCommand(scmnd); } } else { - if (holdbutton[i] == Settings.param[P_HOLD_TIME] * (STATES / 10)) { // Button hold + if (holdbutton[i] == Settings.param[P_HOLD_TIME] * (STATES / 10)) { // Button hold multipress[i] = 0; - if (!Settings.flag.button_restrict) { // No button restriction + if (!Settings.flag.button_restrict) { // No button restriction snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1")); ExecuteCommand(scmnd); } else { - send_button_power(0, i +1, 3); // Execute Hold command via MQTT if ButtonTopic is set + send_button_power(0, i +1, 3); // Execute Hold command via MQTT if ButtonTopic is set } } } } - if (!Settings.flag.button_single) { // Allow multi-press + if (!Settings.flag.button_single) { // Allow multi-press if (multiwindow[i]) { multiwindow[i]--; } else { if (!restart_flag && !holdbutton[i] && (multipress[i] > 0) && (multipress[i] < MAX_BUTTON_COMMANDS +3)) { boolean single_press = false; - if (multipress[i] < 3) { // Single or Double press - if ((SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) { + if (multipress[i] < 3) { // Single or Double press + if ((SONOFF_DUAL_R2 == Settings.module) || (SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) { single_press = true; } else { single_press = (Settings.flag.button_swap +1 == multipress[i]); @@ -2018,13 +2018,13 @@ void ButtonHandler() if (single_press && send_button_power(0, i + multipress[i], 2)) { // Execute Toggle command via MQTT if ButtonTopic is set // Success } else { - if (multipress[i] < 3) { // Single or Double press - if (WifiState()) { // WPSconfig, Smartconfig or Wifimanager active + if (multipress[i] < 3) { // Single or Double press + if (WifiState()) { // WPSconfig, Smartconfig or Wifimanager active restart_flag = 1; } else { ExecuteCommandPower(i + multipress[i], 2); // Execute Toggle command internally } - } else { // 3 - 7 press + } else { // 3 - 7 press if (!Settings.flag.button_restrict) { snprintf_P(scmnd, sizeof(scmnd), kCommands[multipress[i] -3]); ExecuteCommand(scmnd); diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index e7e1d6cbb..89384d938 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -765,15 +765,15 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { 0, 0 }, { "Sonoff Dual R2", // Sonoff Dual R2 (ESP8285) - GPIO_SWT1, // GPIO00 Button 1 on header + GPIO_USER, // GPIO00 Button 0 on header (0 = On, 1 = Off) GPIO_USER, // GPIO01 Serial RXD and Optional sensor 0, GPIO_USER, // GPIO03 Serial TXD and Optional sensor 0, GPIO_REL2, // GPIO05 Relay 2 (0 = Off, 1 = On) 0, 0, 0, // Flash connection - GPIO_SWT2, // GPIO09 Button 2 on header - GPIO_KEY1, // GPIO10 Button 3 on casing + GPIO_USER, // GPIO09 Button 1 on header (0 = On, 1 = Off) + GPIO_KEY1, // GPIO10 Button on casing 0, // Flash connection GPIO_REL1, // GPIO12 Relay 1 (0 = Off, 1 = On) GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off) diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino index ffe5c5eca..411d9a4b3 100644 --- a/sonoff/xsns_12_ads1115.ino +++ b/sonoff/xsns_12_ads1115.ino @@ -33,19 +33,19 @@ * ADS1115 * ------- * ADS1115_REG_CONFIG_PGA_6_144V // 2/3x gain +/- 6.144V 1 bit = 0.1875mV - * 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 (default) + * ADS1115_REG_CONFIG_PGA_4_096V // 1x gain +/- 4.096V 1 bit = 0.125mV (default) + * 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_0_512V // 8x gain +/- 0.512V 1 bit = 0.015625mV * ADS1115_REG_CONFIG_PGA_0_256V // 16x gain +/- 0.256V 1 bit = 0.0078125mV \*********************************************************************************************/ -#define ADS1115_ADDRESS_ADDR_GND 0x48 // address pin low (GND) -#define ADS1115_ADDRESS_ADDR_VDD 0x49 // address pin high (VCC) -#define ADS1115_ADDRESS_ADDR_SDA 0x4A // address pin tied to SDA pin -#define ADS1115_ADDRESS_ADDR_SCL 0x4B // address pin tied to SCL pin +#define ADS1115_ADDRESS_ADDR_GND 0x48 // address pin low (GND) +#define ADS1115_ADDRESS_ADDR_VDD 0x49 // address pin high (VCC) +#define ADS1115_ADDRESS_ADDR_SDA 0x4A // address pin tied to SDA pin +#define ADS1115_ADDRESS_ADDR_SCL 0x4B // address pin tied to SCL pin -#define ADS1115_CONVERSIONDELAY (8) // CONVERSION DELAY (in mS) +#define ADS1115_CONVERSIONDELAY (8) // CONVERSION DELAY (in mS) /*====================================================================== POINTER REGISTER @@ -126,7 +126,7 @@ void Ads1115StartComparator(uint8_t channel, uint16_t mode) uint16_t config = mode | ADS1115_REG_CONFIG_CQUE_NONE | // Comparator enabled and asserts on 1 match ADS1115_REG_CONFIG_CLAT_NONLAT | // Non Latching mode - ADS1115_REG_CONFIG_PGA_2_048V | // ADC Input voltage range (Gain) + ADS1115_REG_CONFIG_PGA_4_096V | // ADC Input voltage range (Gain) ADS1115_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val) ADS1115_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val) ADS1115_REG_CONFIG_DR_6000SPS; // 6000 samples per second diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino index 10def543c..08db3cc63 100644 --- a/sonoff/xsns_12_ads1115_i2cdev.ino +++ b/sonoff/xsns_12_ads1115_i2cdev.ino @@ -84,7 +84,7 @@ void Ads1115Detect() ADS1115 adc0(ads1115_address); if (adc0.testConnection()) { adc0.initialize(); - adc0.setGain(ADS1115_PGA_2P048); // Set the gain (PGA) +/-4.096V + adc0.setGain(ADS1115_PGA_4P096); // Set the gain (PGA) +/-4.096V adc0.setRate(ADS1115_RATE_860); adc0.setMode(ADS1115_MODE_CONTINUOUS); ads1115_type = 1; diff --git a/sonoff/xsns_14_sht3x.ino b/sonoff/xsns_14_sht3x.ino index bd8cd981d..6b38cf661 100644 --- a/sonoff/xsns_14_sht3x.ino +++ b/sonoff/xsns_14_sht3x.ino @@ -1,7 +1,7 @@ /* - xsns_15SHT3X.ino - WeMos SHT30 Shield + xsns_14_sht3x.ino - SHT3X temperature and humidity sensor support for Sonoff-Tasmota - Copyright (C) 2017 Palich2000 + Copyright (C) 2017 Theo Arends 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 @@ -20,10 +20,11 @@ #ifdef USE_I2C #ifdef USE_SHT3X /*********************************************************************************************\ - * WeMos SHT30 Shield - * https://wiki.wemos.cc/products:d1_mini_shields:sht30_shield + * SHT3X - Temperature and Humidy * - * https://github.com/wemos/WEMOS_SHT3x_Arduino_Library + * Required library: none but based on Adafruit Industries SHT31 library + * + * I2C Address: 0x44 or 0x45 \*********************************************************************************************/ #define SHT3X_ADDR_GND 0x44 // address pin low (GND)