6

I'm looking for an ESP8266 board with a dual relay for one of my projects. Yes a Sonoff Dual - quite answers all my needs, beside the part of messing around with soldering and the for need more GPIO's and I want them reachable.

While looking around, this product caught my eye. All seemed good, but I suddenly noticed that there is a STM microprocessor additional to an ESP8266 chip.

  1. I'll be happy to hear pros and cons for such system (dual MCUs).

  2. Since I write my own code using Arduino IDE, how is the access is done when ESP8266 serves only the wifi connectivity .

4 Answers 4

4

I successfully used this exact board tctech.cc's relay boards on my project. It's very easy to program.

Here's how to control the relay from the ESP01 module:

Send this to the TX pin using the UART 115200 bps (some boards could be 9600):

  • Relay 1 ON: 0xA0, 0x01, 0x01, 0xA2
  • Relay 1 OFF: 0xA0, 0x01, 0x00, 0xA1
  • Relay 2 ON: 0xA0, 0x02, 0x01, 0xA3
  • Relay 2 OFF: 0xA0, 0x02, 0x00, 0xA2

(if you get the 4 relay version...)

  • Relay 3 ON: 0xA0, 0x03, 0x01, 0xA4
  • Relay 3 OFF: 0xA0, 0x03, 0x00, 0xA3
  • Relay 4 ON: 0xA0, 0x04, 0x01, 0xA5
  • Relay 4 OFF: 0xA0, 0x04, 0x00, 0xA4

The format is the following:

  1. first byte: 0xA0
  2. second byte: relay number (first is 0x01)
  3. third byte: command (0x00-off, 0x01-on)
  4. fourth byte: sum of previous bytes
1
2

The product link which you have provided contains the ESP-01 module. The ESP or wifi module is only used for communication through wifi or server and it will send the data through the UART to the STM8 controller and the further controlling will be done through the STM8 you will need to check whether the Rx and Tx lines of ESP-01 are connected to the Rx and Tx of the STM8. If yes then the STM8 will only compare the string received and will turn On or Off the relay.

For using your own code on Arduino the access will be done through the UART as said before

I cannot comment on the pros and cons of the module or of using different MCUs

2
  • Thank you for your answer. I can’t see how can I affect ESP chip in code ( for example sending a MQTT message) or define a certain behavior of the STM chip
    – guyd
    Commented Dec 24, 2020 at 14:28
  • If you want to define a certain behaviour then you will need to change the firmware of the STM32 and what do you really want to affect of the ESP
    – Maaz Sk
    Commented Dec 26, 2020 at 15:48
1

I'll be happy to hear pros and cons for such system (dual MCUs).

I have used two STM32 MCUS in a robotic application before, where one MCU was responsible for processing 32 analogue signals, which means 32 ADC channels to be read and processed in real-time. The higher sampling rate was the better. The other MCU was responsible for multiple PID controllers, battery management, Bluetooth connection, controlling servos and a DC motor. So the pros were:

  • Load balanced, decoupled system parts with clear responsibilities. The large amount of analogue signal processing did not conflict with the PID controllers, motor drive, etc. It could run on highest priority on another MCU without compromising other parts of the system.
  • The increased hardware complexity resulted a decreased software complexity. (To be honest this could be a con as well, depending on the application.)

Regarding the relay board in question, I do not see any requirement that would justify the two MCUs. It could have been realized just with the ESP only.

Now as for the cons:

  • Number one con is cost. An additional MCU and its supplementary circuity (programming interface, power, etc.) will cost more. Same goes for the increased PCB size.
  • With the different MCU selection on the relay board, more complexity was introduced in development as the MCU are from different manufacturers. They require different toolchains, programming tools, SDKs, etc. (In my example we went with two STM32 MCU, so it was not an issue.)

Since I write my own code using Arduino IDE, how is the access is done when ESP8266 serves only the wifi connectivity .

The other answers have summed it up pretty well that the STM8 expects commands via UART, so you could change the program on the ESP while interfacing the STM8 with the same UART commands. The STM8 will act as an external peripheral like a GPS or GSM module would. So you can create an MQTT client on the ESP that will subscribe to some topic instead of using the demo app to control the relays.

Luckily the ESP-01 can be removed from the board, which makes it much simpler to flash it, How to Program ESP8266 (ESP-01) Module with Arduino UNO. You do not have to bother with the STM8 and with the fact that it sits on the same UART lines.

1
  • I reverse engineered the board, it includes two jumpers to detach the UART RX/TX lines of the ESP-01 from the STM8. Commented May 5 at 16:28
0

Just got the same board (2-relay version), and made a bit late the same discovery as you : the ESP8266 is only doing a Wifi-to-Serial translation, while the ocntrol of the relays (and the interfacing of the two buttons) is handled by another processos (8-bit STM8) that you can't change. The buttons are used to change between an "Access Point" mode, where your controlling device (phone/PC/...) connects on the 8266 private WiFi network or "Station" mode (where both your phone and relay module are connected on the same network.

You obviously can reprogram the ESP8266 any way you like, using Arduino IDE or other compiler, but the interface between both system is 4bytes fixed : "A0"/Relay/On-Off/Checksum First byte = "A0", second byte = relay number "01" or "02, third byte is 0 for OFF and 1 for ON, and fourth byte is sum of all three. No CR/LF or other separator needed, but they are sort of allowed between the commands as they will be discarded. Only teh 4-byte sequence above is recognized and executed.

Pros and Cons : For me the biggest pro was the price and size : very cheap module, cheaper than a relay module with 8266 soldered on board, or relay module with cable to some ESP8266 or ESP32 module.

Cons are that you are forced to adopt the system, and you don't get feedback on the execution AFAIK : there is no documented way to confirm that the relays are ON or OFF, the buttons cannot be used for manual override, there are several versions (some with 9V-30V regulator to accept higher power supply voltage, some without, some different pinout with "SWIN" or other unclear functions, using the buttons may change the WiFi mode without warning to your system, etc.

1
  • The SWIM line is the Single Wire Interface Module, the standard protocol to program ST micros. All the programming lines are exposed, so I'm pretty sure you can reprogram the STM8 micro with a custom firmware. Commented May 5 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.