ESP8266 resets the code

I have an ESP8266 and an OLED display powered by a lithium battery. They are connected directly to the battery without any regulators. The problem is that when the battery dies and I recharge it, the code seems to disappear. ESP is just booting up like an empty sketch. I can see this by the blue light on the ESP that shows the serial data is being transmitted. Whenever I boot it up after the battery dies, nothing happens. The only fix is to upload the code once again, but it's not very convenient to do it every day. Is there a fix for that? What can I do to prevent the code from being erased after battery death?

What type? A Lithium primary battery or a Li-ion or Li-Po pack?

Do you mean you have not added any regulator to the circuit? Could your ESP board have a built-in regulator that is being used?

This should never happen. It does not happen with my ESP sensors (Wemos D1 mini boards) which are powered by Li-ion batteries and Li-Po packs connected to the 5V pin.


This is my basic setup, so there is one capacitor to secure everything and a button to turn everything on and off.
Here are two gifs showing the difference whenever the code runs normally:
normal

And after the death of the batteries:
dead
I have this problem reoccurring with this setup, and I have no idea what causes it.

Not a good idea, as you have discovered.

mmmmm....3.3v driven by (up to) 4.2v....ouch. :upside_down_face:

The single flash of the blue led indicates that the chip may have gone into upload mode instead of run mode.

If you recharge the batteries at this point, and reset the ESP, does the sketch start running again?

The absolute max voltage for ESP 8266 is around 3.6V, I think, so 4.2V from fully charged batteries could have damaged it. I seem to remember, from my early experiences with ESP8266, that voltages over 3.3V cause an increase in current consumption. So I would definitely recommend you use a regulator, to protect the ESP and keep current consumption normal. I would suggest MCP1700-3302 or HT7333. Both will need a couple of caps as shown in their datasheets. Your existing cap will probably work ok as one of those caps.

Even after the recharge of the batteries or connecting esp to a stable FTDI adapter, it boots into this weird mode, not doing anything. I have a few MCP1700-3302 at home, and I tried using them, but at around 3.3 volts, the regulator wasn't outputing enough power for an esp and a display. That's why I chose not to use the regulator.

I also thought it could have been damaged, but the weird thing is that after reuploading the code, it works normally. I've seen people use it up to 5v and it still somehow survived (I'm not testing that), so I thought maybe 4.2v would be ok.

well, ......... NO.

Can you post a schematic showing how the ESP-01 is connected? Perhaps the boot mode pins are floating.

MCP1702 is rated up to 250mA. ESP-01 uses about 80mA on average, the OLED maybe 30mA. The ESP will draw high current for very short bursts but a good size cap should smooth that out. So MCP1700 should be ok. Did you add the necessary caps when you tried the MCP1700?

If you need a regulator with higher current, I have been recommended HT7833. But I think MCP1700 should be fine.

Here are the connections for my esp01:
RX, TX - only connected during the upload
VCC - 4.2V
GPIO 0 - Display SDA (during the upload, I connect it to GND)
RESET - 4.2V
CH_PD - 4.2V
GPIO 2 - Display SCK
GND - GND

Yeah, before I installed the cap, my esp was rebooting every 5 seconds, so I had to add a 10 uF cap. It successfully stops random reboots and provides smooth voltage.

Maybe when the battery is discharged, this pin isn't registering as high, so the ESP keeps going into upload mode?

After the batteries are charged, nothing changes. I'll try to use this setup with a voltage regulator, and see if this still happens.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.