Chat here is you are connecting ESP-xx type modules to existing AVR based Arduino

Moderator: igrr

User avatar
By SetUp
#61259 Hi everyone,

I have following issue: I connected an ESP-01 on GPIO 2 to a relay (opto isolated, low-level trigger) and coded the logic in the ESP via the Arduino IDE.
Everything works fine, but now and then the relay is flickering. The ESP does not reset and I'm confident that this is not related to the PSU (which is supplying up to 2000mA on the 3.3V lane).
The ESP is up to date with the latest Espressif NONOS firmware & patch (2.0.0_16_08_10).

I tried to isolate the ESP on a breadboard and hooked it up just to a LED. The LED is also flickering after a while, during it's LOW state.

I also replaced the ESP-01 with another ESP-01 and experienced the same results with the other chip.

Does anyone have the same problem? Is there a solution? Like this it's unreliable to let the ESP control relays. I could help my self with a capacitor on the output pin, but I rather go for a cleaner solution.

Cheers,
S
User avatar
By SetUp
#61409 I narrowed the problem down and apparently it lies in the code - and now I'm kinda stuck.

My loop code is calling a function of type bool. Which obviously shall return TRUE / FALSE.

Whenever there is high CPU demand (i.e. when a client is connecting to the web interface of the ESP) this function returns bogus data, instead of 1s and 0s, I get 144, 23 or 188 in the boolean variable if I cast it to int.

That's exactly the moment when the relay starts flickering, because that function tells the relay to be on or off.

Trying to debug this I also noticed that from time to time the function gets not executed till a return statement, it just goes down to a point, skips the rest and restarts the loop. So I'm wondering how is this possible? I suppose that it's related to the asynchronous way of execution inside the ESP.

But no clue on how to fix it. Any suggestions?