Author Topic: ESP8266: Taming the GPIO2 jitter  (Read 1505 times)

0 Members and 1 Guest are viewing this topic.

Offline tjkolevTopic starter

  • Contributor
  • Posts: 17
  • Country: us
ESP8266: Taming the GPIO2 jitter
« on: October 31, 2025, 01:07:37 am »
Greetings!

I had some pieces around, and decided to make a battery powered, low power, switch notifier - pantry door got opened and such. Using an ESP8266 ESP01-S module. I've used the module before, and I am aware of its shortcomings, and that it's not really intended for this usage. But it had worked for me. This time though conditions are different, and I got stuck.

I will most likely ditch this setup. But if you think I can do a minor change (add a diode, a cap) to salvage it - I can try. However, my main goal with this post is to get some help in understanding what's happening.

Latching relay: https://api.pim.na.industrial.panasonic.com/file_stream/main/fileversion/263704
The "Yellow" and "Pink" tags refer to the oscilloscope probes.
Using a PNP transistor on GPIO2, which starts HIGH. Program makes GPIO2 LOW to open the transistor, and activate the relay.

This is how I started:


This works. The relay is two coil latching one. L1 closes and L2 opens S1. L1 is activated by the external switch, and L2 - by the MCU when it completes its task. At the end no power is consumed. The problem is if S2 is kept closed for whatever reason, L1 pulls a good 220mA. Sub-optimal. I figured I enforce some "pulse" switching for L1.


Part of it works as expected. L1 activates, and if the S2 is kept closed only small current is pulled from the battery via R2 (~12mA). The whole thing is short lived, so it's acceptable. However it doesn't "live". I hear the relay clicking twice, and the MCU not powered. At about 50ms GPIO2 starts jittering. A well known deficiency. It will return to HIGH after 50ms or so. And when it hits LOW it activates L2, which powers off the MCU.


I figured I add a capacitor to "keep" the jitter at HIGH.


In the above I added the single C9, but I tried two positions - C9A and C9B. Not much difference. The relay buzzes for less than a second, and nothing turns on.

This is what I am seeing with C9A:


And this is with C9B:


What is going on? Notice that these pulses start way before the GPIO2's "native" jitter. The MCU doesn't get to that. Adding the C9 somehow unbalances the whole R2-C3-L1-L2-D1-T1-C9 chain... I would appreciate any explanation.

Disclaimer: There's a small chance I may have mis-identified the oscilloscope images.

Thank you for any comments.
tjk :)
« Last Edit: October 31, 2025, 01:29:14 am by tjkolev »
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3379
  • Country: au
Re: ESP8266: Taming the GPIO2 jitter
« Reply #1 on: October 31, 2025, 01:43:08 am »
Part of it works as expected. L1 activates, and if the S2 is kept closed only small current is pulled from the battery via R2 (~12mA).
If S2 is not momentary then R2+C3 is certainly a good idea.
R2 does not need to be as small as 330, as it is there to discharge C3 when S2 is open.

The whole thing is short lived, so it's acceptable. However it doesn't "live". I hear the relay clicking twice, and the MCU not powered. At about 50ms GPIO2 starts jittering.
A well known deficiency. It will return to HIGH after 50ms or so. And when it hits LOW it activates L2, which powers off the MCU.
In the above I added the single C9, but I tried two positions - C9A and C9B. Not much difference. The relay buzzes for less than a second, and nothing turns on.
If GPIO2 has chatter as the MCU powers up, then some form of low pass filter is a good idea.

For that, C9A is better placed B-E on the PNP, along with a B-E resistor so that C9A starts at 0V and discharges to 0V when VCC is off.
R1 does not need to be as low as 330, it just needs to be able to saturate PNP to drive the relay coil.
C9B should not be needed.
The PNP can be a P-MOSFET, to give you even more choice on RC values.


 
The following users thanked this post: tjkolev

Online aeg

  • Frequent Contributor
  • **
  • Posts: 471
  • Country: us
Re: ESP8266: Taming the GPIO2 jitter
« Reply #2 on: October 31, 2025, 01:46:23 am »
That's not jitter, it's a glitch. Use GPIO4 or GPIO5 instead.
 

Offline tjkolevTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: ESP8266: Taming the GPIO2 jitter
« Reply #3 on: October 31, 2025, 02:07:14 am »
@aeg,

You are correct!  :) As I said - I am aware of the problems. The esp-01 doesn't break out GPIO4/5. That's why I am considering ditching it. But I'd like to try some fixes - like the ones PCB.Wiz suggests.
 

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: fr
    • kripton2035 schematics repository
Re: ESP8266: Taming the GPIO2 jitter
« Reply #4 on: October 31, 2025, 07:55:52 am »
never use gpio00 and gpio02 on an esp8266 or face the consequences !
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3379
  • Country: au
Re: ESP8266: Taming the GPIO2 jitter
« Reply #5 on: October 31, 2025, 08:41:50 am »
@aeg,

You are correct!  :) As I said - I am aware of the problems. The esp-01 doesn't break out GPIO4/5. That's why I am considering ditching it. But I'd like to try some fixes - like the ones PCB.Wiz suggests.

You can add another PNP / Digital transistor, and create a VCC rise blanking delay, so the GPIO2 relay trigger action after boot is faster.

eg 22k/22k/2.2uF and BC857C, sims to give about 73ms leading edge blanking from Vcc rise.  Scale from there as needed.
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3379
  • Country: au
Re: ESP8266: Taming the GPIO2 jitter
« Reply #6 on: October 31, 2025, 07:32:21 pm »
More details : It would be best to avoid trying to drive the relay from the regulated side, as that puts the relay current impulse on the MCU VCC.
Better would be to drive the relay CT from VBAT and pull either side low.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6926
  • Country: es
Re: ESP8266: Taming the GPIO2 jitter
« Reply #7 on: October 31, 2025, 07:56:26 pm »
It's a lot easier to implement a rc filter by replacing the pnp bjt with a p-fet.

Put a a diode in parallel to set the polarity preference.
A short pulse in the diode flow will take effect almost instantly, while it will take a lot more in the opposite direction (30-50ms in this example).

Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline tjkolevTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: ESP8266: Taming the GPIO2 jitter
« Reply #8 on: November 02, 2025, 03:34:04 pm »
Holy smoking fuse PCB.Wiz!

I did your suggestions and it's working! Freaking electronics dark magic.

Thank you!

2689277-0
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6926
  • Country: es
Re: ESP8266: Taming the GPIO2 jitter
« Reply #9 on: November 02, 2025, 06:00:29 pm »
1000uF is like killing flies with cannons.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline tjkolevTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: ESP8266: Taming the GPIO2 jitter
« Reply #10 on: November 02, 2025, 06:08:41 pm »
1000uF is like killing flies with cannons.
:D

I had some pieces around, ...
That's what I have. Perhaps 90% of my components are what I've de-soldered from electronics I was throwing out. Whatever works...

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->