Monday, April 6, 2015

Zero-wire auto-reset for esp8266/Arduino

A little over a year ago I developed a zero-wire auto-reset solution for Arduino.  After I started using Arduino for the esp8266, I realized I could do the same thing with the ESP-01.

Flashing the esp8266

In order to download code to the esp8266 after reset, GPIO0 and GPIO15 must be low, and GPIO2 must be high.  The ESP-01 has GPIO15 grounded, and GPIO2 is set high after reset.  GPIO0 is pulled up to Vcc after reset, so in order to download code to the flash, this must be pulled low.  Although esptool-ck supports using RTS and DTR for flashing the esp8266, many cheap USB-TTL modules don't break out those lines.  With USB-TTL modules that break out DTR, the DTR line should be connected to GPIO0 in order to pull the line low after reset.  Otherwise DTR needs to be grounded with a jumper or by connecting a push-button switch to ground.

The circuit

The auto-reset circuit I used on the esp8266 is a simplified version of the circuit I used with the pro mini.  It consists of just a 7.5K resistor between Rx and RST, and a 4.7uF capacitor between RST and Vcc.  The values are not critical, as long as the RC constant is between 10ms and 100ms, so if what you have on hand is a 15K resistor and 1uF capacitor, that should work fine.  A serial break signal is 250ms long, which is why I suggest a an RC constant of less than 100ms to allow the capacitor to discharge and trigger a reset before the break signal ends.  If the RC constant is less than 10ms, a sequence of zero bytes transmitted to the esp8266 could unintentionally trigger a reset.  At 9600bps, each bit is 104.2us long, so 8 zero bits plus the start bit would last 938us.  Several zero-bytes in a row, even with the high voltage of the stop bit in between, could trigger a reset.  The esptool default upload speed is 115.2kbps, so unwanted resets are quite unlikely.

The  auto-reset circuit has an added benefit of improving the stability of the esp8266 module.  The RST pin on the esp8266 is extremely sensitive.  Before I added the auto-reset circuit, simply touching a probe from my multimeter to the RST pin would usually reset the module, even when I tried adding a 15K pullup resistor to Vcc.  I would also get intermittent "espcomm_sync failed" messages when trying to upload code.  Since adding the auto-reset circuit, I can probe the RST pin without triggering a reset, and my uploads have been error-free.

Getting the updated esptool-ck

By the time you are reading this, Ivan may have already integrated my patch for esptool-ck.  If the issue is still open, then you can download the updated esptool-ck.  Extract the esptool.exe into hardware\tools\esp8266.  This version also includes support for 921.6kbps uploads, which can be enabled by modifying putting esp01.upload.speed=921600 in hardware\esp8266com\esp8266\boards.txt.


  1. How do u calculate the RC timeout?
    what is the equation?

    1. Multiply the resistance in Ohms by the capacitance in Farads. Where I used a 4.7uF cap and a 7.5K resitor, that would be:
      4.7x10^-6 x 7.5x10^3 == 4.7 * 7.5 * 10^-3 == 0.03525 seconds
      or roughly 35ms.

  2. This might be a stupid question. When ever i connect a capacitor and resistor to the Rx pin I get unable to communicate.

    Does it matter what type of capacitor you use, film or ceramic?

    If film does it have to be a certain way round?

  3. Thought i'd add that i figured out how to do it. This method did not work for me reliably. Your other method with the diode did.

    Thats TRX - 7.5K - RST, RST - 4.7uF - GND, TRX - Diode - RST.

    I've combined it with the ATTiny85 idea from, so I now have a reset and program function with just TX, RX, GND. Can program my ESPs,using an audio cable! I've had to add a send break command to the which was easy enough.

    The one thing i've found is that no all USB-Serial converters can send breaks. I only have one type that can, an FTDI cheap Chinese one. My adafruit one for raspberry pi that can to 961000 does not do it, neither does another module I have.

    I used a scope to check their outputs when i send a break, so they definitely do not do it.

    1. When you say it didn't work reliably, were you getting hangs during uploads? I've been thinking that even at higher baud rates, a stream of data with >50% zero bits could discharge the RST below the threshold voltage. With the diode, the stop bit after each byte would re-charge the capacitor.

      I suspect the problem sending break is likely a driver rather than a hardware problem. The cheap (<$1 ea) pl2303hx USB-serial modules I use have no trouble generating a break under Windows 7 and Linux.

  4. I think your first statement is the right one, it was hanging at 93%. I found your diode design, and that works flawlessly. I have no problems sending a break on my cheap adapters, but i wanted it for the device that can do 921600!, these ones don't work past 115200 . Good idea with drivers. I will try it on a PC at some point.

  5. Andrew Melvin:

    Can you please give a full solution about the audio cable?
    What do you mean?
    Schematics would be nice

    Or did you mean that becase u just need 3 cables u did a usb to pl connection?

    I'm a bit confused
    Please elaborate

    I also have a ch340 (cheap chines usb ttl)

    1. I've not set it up, but if all you need is TX,RX,GND you can use an audio jack, and an audio cable to connect a USB-Serial device to the ESP and program it. I've not got an schematics, as i don't (yet) have any software to do it. on the list.

  6. Hi Ralph,
    I love the idea with just 2 components extra. This will be a big benefit for easy using esp8266 like an arduino
    I can see that Igor (iggr) has not merged your github request. Although he has already merged other ones. Is it possible that you add his suggestion to upload the change to github. By that he can just merge by pressing the merge button.
    The benefit for me is that I am able to continue using his build for arduino. I would love to add this solution to
    Regards, Jeroen Beemster

  7. This comment has been removed by the author.

  8. Hi Ralph,
    Another question: I have bought lately a set of (ceramic) capacitors with 50 different values. The one you mentioned is not in it.

    With the calculation you decribed I tried to find another type of capacitor:
    0.1µF capacitor and a 330KΩ resistor gives a result of 33MSec. Is that correct?
    Jeroen Beemster

  9. Hi Again Ralph,
    It seems that your version of esptool.exe that can be downloaded from your site is outdated.
    I am using the version of sandeepmistry/esp8266-Arduino. When I replace the esptool.exe the bare minimum sketch is not compiling anymore.

    I would love to try your solution. Now i am on a dead end. Could you help in one way or another.

    1. I thought Ivan would have integrated my patch by now, but it seems not.
      You could clone the latest esptool-ck, apply the patch I posted, and build your own.

      Nevertheless, the binary I posted should still work with newer versions of the IDE unless I accidentally used dynamic instead of static linking. I'll try to take a look over the next couple days.

  10. There is very little information available the last few years on the ESP8266 auto reset which I find strange as it is almost a prerequisite to do serious debugging. I had to use a 10ms RC; higher values gave constant problems with this auto reset. I also connect DTR to CH-PD and keep RST pulled-up to 3.3V: in case of reset from sleep this seems to be a preferred solution.