Flashing ESPEasy to the Sonoff 4CH

So far flashing the ESP8266 has been pretty easy, but with the new Smart Home devices from itead,it has become a bit more complicated. The reason for this, is because they have changed from the ESP8266, to the physically smaller ESP8285. The function of the 8285 is the same as the 8266, but it got the memory build in, instead of having it on an external chip.

Before we can flash ESPEasy to the ESP8285, we need a .bin file compiled for it. You can do that with the Arduino IDE, and in that load the ESPEasy source code, set the ESP8285 under Tools > Board, and then go to Sketch > Export compiled Binary, and you will then find a .bin file in the same directory as your Arduino sketch. Or you can go here and download the .bin file I compiled and put on mine https://github.com/blddk/esp8285/tree/sonoff_4ch. Here you can also find the NodeMCU flasher tool, which I used to flash my Sonoff 4CH.

Before being able to flash the ESP8285, there are a few settings which needs to be changed  (config file is also included on my github), here is how I set mine up to be able to flash it.

So now we got the software part ready, but this isn’t enough this time. With the Sonoff switch, we have been able to just power it by giving it 3v3 from the TTL adapter, but the Sonoff 4CH draw too much current, so the CH340G chip on my TTL adapter can’t supply enough current to make it boot up properly. So to get enough current available, I modified my TTL adapter a bit.

From the top side, it still looks pretty normal, except you can see the extra jumper I added to easy be able to switch between 3v3 and 5v while having a connector attached to it.

On the bottom side, I put an LM1117 voltage regulator on between the VCC and 3v3 pin, and also connected it to GND to complete the circuit. This isn’t perfect, as it is just in parallel with the voltage regulator inside the CH340G chip, but it works. With this extra voltage regulator, you no longer have to worry about having enough current on 3v3, because it can supply a lot more than the TTL adapters normally can do.

I also made a cable just for connecting easily to the Sonoff 4CH.

And then I got to something very confusing, because it just would not work.

Normally TX on your TTL adapter, needs to go to RX on the thing you are connecting to, and RX to TX. This is because the transmitted signal must go to the pin where it is expected to be received. But the silkscreen on my Sonoff 4CH was actually opposite. RX from the TTL adapter needs to go to RX on the Sonoff board. I first found this after having been struggling with getting it to work for some hours, where I just go absolutely nowhere. I then found the datasheet for the ESP8285 based module they used, and probed for a bad connection, but instead I found the TX and RX pins swapped, so it was opposite than the silk screen.

After swapping the wires around in the connector, I could flash ESPEasy onto the Sonoff 4CH, and finally it accepted the new code.

All I needed now was to figure out what pin was connected to what function, and then it was ready to use. And to save a bit of your time, here is my findings for pin connections.

GPIO13 Status LED (blue)
GPIO12 Relay 1
GPIO05 Relay 2
GPIO04 Relay 3
GPIO15 Relay 4
GPIO00 Button 1 / Flash
GPIO09 Button 2
GPIO10 Button 3
GPIO14 Button 4
GPIO07 2.5mm jack
GPIO08 2.5mm jack

7 comments

  • HI captain, may I know how you managed to trace the ESP8285 pins to the respective function (relay, button etc)?

    • I looked at the itead wiki, and found some data on some of their other modules, then I just tried to compare that to the one in the Sonoff 4CH with my multimeter.

  • Captain, as stated in the schematic you refer to gpio7 anderen gpio8 as 2.5 Jack / Tem1 & Tem2, but i cant find a populated/unpopulated Place of an 4-pol 2.5 Jack. Can you help meine Out. I want to add a Temperatur/Humidity sensor

  • This Page saved my day! Thanks a lot. I neither have the mentioned 2,5mm jack in my device. But the rest works like charm.

  • Hi Captain, thank you ever so much for your help above. I have successfully flashed Espeasy to my sonoff largely inspired by this post. I am having some issues though, I am really hoping you can help?

    So my set up is using Domoticz, http control. Regardless of whether i use Domoticz gui, other controllers, or via HA-Bridge to Alexa I often get a mis-fire on the relays. I have no problem switching relays off, but when I switch them on I often get more than one coming on when not requested. For example, I’ll switch on just Relay 3 and all 4 switch on one after another.

    If you get a chance, could you possibly take a look at my rules and tell me where I am going wrong:

    On RearSecurityOn do
    gpio,12,1
    EndOn
    On RearSecurityOff do
    gpio,12,0
    EndOn

    On RearSecurity#Switch do
    If [RearSecurity#Switch]=0
    gpio,12,0
    else
    gpio,12,1
    EndIf
    EndOn

    On OutdoorLightsOn do
    gpio,5,1
    EndOn
    On OutdoorLightsOff do
    gpio,5,0
    EndOn

    On OutdoorLights#Switch do
    If [OutdoorLights#Switch]=0
    gpio,5,0
    else
    gpio,5,1
    EndIf
    EndOn

    On RearSocketOn do
    gpio,4,1
    EndOn
    On RearSocketOff do
    gpio,4,0
    EndOn

    On RearSocket#Switch do
    If [RearSocket#Switch]=0
    gpio,4,0
    else
    gpio,4,1
    EndIf
    EndOn

    On WifiRelayOn do
    gpio,15,1
    EndOn
    On WifiRelayOff do
    gpio,15,0
    EndOn

    On WifiRelay#Switch do
    If [WifiRelay#Switch]=0
    gpio,15,0
    else
    gpio,15,1
    EndIf
    EndOn

    Can you see anything wrong?

  • try this, it is untested but should work

    On RearSecurityOn do
    gpio,12,1
    EndOn

    On RearSecurityOff do
    gpio,12,0
    EndOn

    On RearSecurity#Switch do
    If [RearSecurity#Switch]=0
    RearSecurityOff
    else
    RearSecurityOn
    EndIf
    EndOn

    On OutdoorLightsOn do
    gpio,5,1
    EndOn

    On OutdoorLightsOff do
    gpio,5,0
    EndOn

    On OutdoorLights#Switch do
    If [OutdoorLights#Switch]=0
    OutdoorLightsOff
    else
    OutdoorLightsOn
    EndIf
    EndOn

    On RearSocketOn do
    gpio,4,1
    EndOn

    On RearSocketOff do
    gpio,4,0
    EndOn

    On RearSocket#Switch do
    If [RearSocket#Switch]=0
    RearSocketOff
    else
    RearSocketOn
    EndIf
    EndOn

    On WifiRelayOn do
    gpio,15,1
    EndOn

    On WifiRelayOff do
    gpio,15,0
    EndOn

    On WifiRelay#Switch do
    If [WifiRelay#Switch]=0
    WifiRelayOff
    else
    WifiRelayOn
    EndIf
    EndOn

    If you are not using espeasy v2 these rules may not work. With the lights turning all on from 1 switch, it sounds like you have either the gpio pins not configured properly, or you are using the wrong idx value.

    • I made an error in the first rules and didn’t add the event command, I have updated it below

      On RearSecurityOn do
      gpio,12,1
      EndOn

      On RearSecurityOff do
      gpio,12,0
      EndOn

      On RearSecurity#Switch do
      If [RearSecurity#Switch]=0
      event,RearSecurityOff
      else
      event,RearSecurityOn
      EndIf
      EndOn

      On OutdoorLightsOn do
      gpio,5,1
      EndOn

      On OutdoorLightsOff do
      gpio,5,0
      EndOn

      On OutdoorLights#Switch do
      If [OutdoorLights#Switch]=0
      event,OutdoorLightsOff
      else
      event,OutdoorLightsOn
      EndIf
      EndOn

      On RearSocketOn do
      gpio,4,1
      EndOn

      On RearSocketOff do
      gpio,4,0
      EndOn

      On RearSocket#Switch do
      If [RearSocket#Switch]=0
      event,RearSocketOff
      else
      event,RearSocketOn
      EndIf
      EndOn

      On WifiRelayOn do
      gpio,15,1
      EndOn

      On WifiRelayOff do
      gpio,15,0
      EndOn

      On WifiRelay#Switch do
      If [WifiRelay#Switch]=0
      event,WifiRelayOff
      else
      event,WifiRelayOn
      EndIf
      EndOn

      Hopefully, these rules will now work for you

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.