diff --git a/docs/12.HardwareSONOFF.md b/docs/12.HardwareSONOFF.md index 6cf62a3e..c82bb86b 100644 --- a/docs/12.HardwareSONOFF.md +++ b/docs/12.HardwareSONOFF.md @@ -1,23 +1,45 @@ -BrewPiLess can run on [SONOFF Basic](https://www.itead.cc/wiki/Sonoff) and [SONOFF TH10/16](https://www.itead.cc/wiki/Sonoff_TH_10/16). You will need to solder the header pins for the first flashing and install temperature sensors. However, because of the small 1M byte flash memory, you will either sacrifice +# General + +BrewPiLess can run on many different Sonoff devices. You will need to solder the header pins for the first flashing and install temperature sensors. + +## Sonoff Basic, Sonoff TH10/16 + +Sonoff Basic and Sonoff TH10/16 use an ESP8266. Because of the small 1M byte flash memory, you will either sacrifice + * OTA web update for log storage, or * 500k log storage for OTA update -* LCD is not available. -SONOFF dual is not supported, because the Relays are controlled by Serial instead of GPIO.Instead, SONOFF Dual **R2** should work by specify correct PINs. +LCD is not available. + +Sonoff Dual is not supported, because the Relays are controlled by Serial instead of GPIO. Instead, SONOFF Dual **R2** should work by specify correct PINs. Please note that some older SONOFFs, maybe before 2018, use ESP8266 while new ones use ESP8285. Right configuration must be used. -### ESP32 SonOff devices (Sonoff TH Origin and Sonoff TH Elite) +## Sonoff TH Elite, Sonoff TH Origin + +Sonoff TH Elite and Sonoff TH Origin use an ESP32. + +For Sonoff TH Elite the built-in LCD display can be removed and a OLED LCD screen can be connected in its place. Use electrical tape to make sure that the LCD pcb is not touching the main pcb. The front glass is a thin plastic be gentle with it. + +### Relay pins + +* 16A devices (THR316 and THR316D): 21 +* 20A devices (THR320 and THR320D): 19 (SET) and 22 (RESET) + +The 20A devices use a latching relay that requires two pins to set and reset the relay. Configure both pins 19 and 22 for the specific function. + +![Configuration Sonoff THR320](image/sonoff_thr320_configuration.png) + +### Connecting sensor + +The sensor that has the RJ9 connector comes with a controller in the wire that needs to be removed: -For Sonoff TH Elite the built-in lcd display can be removed and a OLED LCD screen can be connected in it's place.. Use electrical tape to make sure that the LCD pcb is not touching the main pcb. The front glass is a thin plastic be gentle with it. +* Option 1: Remove the controller and reconnect the wires. +* Option 2: Use `Sonoff AL010 2.5mm Audio Jack to RJ9 Adapter` with the old sensor using the audio jack conntector. -#### Conntecting sensor -The sensor that has the RJ9 connector comes with a controller in the wire that needs to be removed -Option 1: Remove the controller and reconntect the wires (not tested). -Option 2: Use `Sonoff AL010 2.5mm Audio Jack to RJ9 Adapter` with the old sensor using the audio jack conntector. +### Connecting OLED LCD (optional) -##### Connecting OLED LCD (optional) -* Connect SDA to WR solder pad -* Connect SCL to CS solder pad -* Use hotglue over soldered contacts so that you don't ripoff the solder pads accidentally. -* Connect 3v and Gnd to corresponding solderpads +1. Connect SDA to WR solder pad. +1. Connect SCL to CS solder pad. +1. Use hotglue over soldered contacts so that you don't ripoff the solder pads accidentally. +1. Connect 3V and GND to corresponding solderpads. diff --git a/docs/image/sonoff_thr320_configuration.png b/docs/image/sonoff_thr320_configuration.png new file mode 100644 index 00000000..a80d02a3 Binary files /dev/null and b/docs/image/sonoff_thr320_configuration.png differ diff --git a/platformio.ini b/platformio.ini index 136747fb..cd5f50f5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -140,7 +140,7 @@ build_flags = monitor_speed = 115200 lib_deps = ${common_env_data.lib_deps_external_esp32} -[env:esp32-sonoff] # for newgen sonoff devices like sonoff elite and origin +[env:sonoff-thr316] # Sonoff TH Elite 16A (THR316D) and Sonoff TH Origin 16A (THR316) platform = ${common_env_data.esp32_framework} board = esp32dev framework = arduino @@ -157,6 +157,27 @@ build_flags = -DEnableBME280Support=false -DSONOFF_NEWGEN=true +monitor_speed = 115200 +lib_deps = ${common_env_data.lib_deps_external_esp32} + + +[env:sonoff-thr320] # Sonoff TH Elite 20A (THR320D) and Sonoff TH Origin 20A (THR320) +platform = ${common_env_data.esp32_framework} +board = esp32dev +framework = arduino +board_build.mcu = esp32 +lib_extra_dirs = ${common_env_data.esp32_lib} + +board_build.partitions = ./partition2.csv + +build_flags = + -DOLED_LCD=true + -DSerialDebug=false + -DEnableHumidityControlSupport=false + -DEanbleParasiteTempControl=false + -DEnableBME280Support=false + -DSONOFF_NEWGEN=true -DSONOFF_THR320 + monitor_speed = 115200 lib_deps = ${common_env_data.lib_deps_external_esp32} diff --git a/src/ActuatorArduinoPin.h b/src/ActuatorArduinoPin.h index 89450a5b..f431b54b 100644 --- a/src/ActuatorArduinoPin.h +++ b/src/ActuatorArduinoPin.h @@ -9,6 +9,11 @@ #include "Actuator.h" +#ifdef SONOFF_THR320 +#define LATCH_PIN_SET 22 +#define LATCH_PIN_RESET 19 +#endif + template class DigitalConstantPinActuator ACTUATOR_BASE_CLASS_DECL { @@ -47,7 +52,20 @@ class DigitalPinActuator ACTUATOR_BASE_CLASS_DECL inline ACTUATOR_METHOD void setActive(bool active) { this->active = active; + + #ifdef SONOFF_THR320 + if (active) { + digitalWrite(LATCH_PIN_SET, HIGH); + delay(10); + digitalWrite(LATCH_PIN_SET, LOW); + } else { + digitalWrite(LATCH_PIN_RESET, HIGH); + delay(10); + digitalWrite(LATCH_PIN_RESET, LOW); + } + #else digitalWrite(pin, active^invert ? HIGH : LOW); + #endif } bool isActive() { return active; } diff --git a/src/Config.h b/src/Config.h index 8d73fc7b..92d7e5da 100644 --- a/src/Config.h +++ b/src/Config.h @@ -356,11 +356,11 @@ #define oneWirePin 25 -#define actuatorPin1 21 // This is relay 1 +#define actuatorPin1 21 // Relay 1 in 16A versions #define actuatorPin2 23 // TM1621 RD #define actuatorPin3 5 // TM1621 DAT -#define actuatorPin4 24 -#define actuatorPin5 26 +#define actuatorPin4 19 // Relay 1 in 20A versions. Latching relay needs 2 pins +#define actuatorPin5 22 // Relay 1 in 20A versions #else // SONOFF_NEWGEN ends #define PIN_SDA 21