Introduction: Sonoff Programmer, USB Serial With 3.3v Regulator

About: Engineer, retired. Have always had an interest in electronics, often related to radio control. This evolved into a part time business that I still practice. I do some voluntary work in schools to encourage …

As I started exploring the wonderful world of ESP8266s and home automation using re-programming of Sonoff devices I realised I needed a Sonoff specific programmer. For more information on the home automation system I use - see: Powerful Standalone Home Automation System - Pi, Sonoff, ESP8266 and Node-Red

The problem is that the Sonoff devices need to be powered for programming and the standard USB to serial converters do not have the capability to supply the current required. The FTDI chip specification says maximum 50ma from its 3v3 regulator. The CP2102 chip rates its 3.3v regulator at 100ma. This is still not enough to power an ESP8266. I could not find specifications for the other types.

So we need to add a 3.3v regulator, and preferably one with a capability >250ma. The AMS1117 3.3 regulator (as used on the NodeMCU) will have capability to spare. So I designed a small PCB to add to a CP2102 serial converter to add the 3.3v regulator and have a pinout that would plug into the PCB holes of the Sonoff in-line switch and S20 mains socket switch. It can also be used with the other Sonoff devices. In some cases some ‘Dupont’ cables will be required and in some there is a need to solder a connection for the programmer and/or GPIO 0. See the Sonoff-Tasmota Wiki for details.

If you don’t have access to PCB making equipment it should be possible to use stripboard and through hole versions of the components. In the case of the larger capacitors (4.7uf and 22uF) it may be easier to use tantalum versions.

Parts required:

  • 6 pin CP2102 micro USB module as in the picture above.
  • PCB (from attached artwork)
  • AMS1117 3.3 (20off for £0.99 on ebay)
  • 0805 ceramic capacitors >6v working voltage):
    • 2 off 0.1uf
    • 1 off 4.7uF
    • 1 off 22uF
  • 0.1” Pin header right angle (you may get these with the CP2102 module)

I would have liked to have used the NodeMCU programming system that I incorporated into my Programmer/breakout board for the ESP12. This has the benefit of avoiding the need for pressing reset etc. in order to program – just download like any Arduino device. Unfortunately this Nodemcu system does not work with the Sonoff Tasmota firmware.

The Sonoff devices are put into programming mode using the device's button and powering up the board with this pressed.

Step 1: Circuit Board

I have attached the PCB artwork. Check it prints at the correct size and adjust the picture format/size if necessary. The board size is 0.65" x 1.2" (excluding the small alignment squares on the corners). Also note the artwork is the track-side view.

My approach to PCB making is to print the artwork twice onto tracing paper (I use a laser printer). I then overlay these to double the contrast and cover any small imperfections in the printing. I punch holes in the edge of the upper layer, place Sellotape across the holes, align and then press on the holes to stick in place. I have a UV exposure unit. Prior to having this I used a UV black light that worked fine with spray coated PCBs and should work with the positive photoresist boards. I use weak sodium hydroxide solution (drain cleaner) to develop and Di-Sodium Peroxodisulphate Hexahydrate to etch. Take special precautions with the chemicals, especially the sodium hydroxide that attacks flesh instantly. I then expose again and develop to get rid of the film over the tracks and finish off with some immerse tin (quite expensive – and limited shelf life). The latter step is optional.

I drilled the header holes at 0.9mm.

For component placement see photo below. I use solder paste. I place and solder components in approximate height order, first with just one joint to hold each one and then finishing the rest of the joints. So I place a component, add a small blob of paste on one pin/pad, and solder. Then repeat this for all the components. Then apply paste to all the un-soldered pins and solder these. I leave through-hole parts until after the SMD parts have been be completed.

With the SMD parts soldered then add the pin header. Lastly solder short pieces of single core wire (or header pins) to the CP2102 module's 5v, GND, TX and RX pins and then place the new PCB on top and solder in place. See photo below:

Step 2: Programming Sonoff Devices

For programming Sonoff devices we need to ensure the ESP8266 has GPIO 0 low during the power on (and a least a few seconds afterwards). GPIO 0 is connected to the device push button.

My sequence for programming is as follows:

Open the Arduino IDE.

Under Tools check the settings are as on the Wiki.

Make any edits required to user_config.h . I set the Wifi SSID and password and MQTT broker address and timezone/daylight savings details.

Click ‘verify’ to check it compiles OK.

Connect the USB serial converter (on its own) to the PC. Note the Port number.

Now disconnect the USB serial lead from the PC and connect it to the Sonoff switch. Check the ground and 3v3 connections are the right way around (ground is connected to the ground plane on the Sonoff PCB).

Hold the programmer so the contacts are secure while also pressing the button:

Now plug the USB lead into the PC (powers up the device), check the port number is correct (in Tools), then click download. I continue to hold the button throughout the programming because I don’t want to disturb the connections. When done you should see a screen as below:

The procedure is similar with the Sonoff Basic:

I hope you find this useful. It makes programming the Sonoff devices a breeze and without any worries of brownouts due to insufficient power on the 3v3 supply. You can also leave it connected while doing initial setting up and checking via the Arduinio serial monitor.

Look out for further instalments of ESP8266 related instructables.