(SOLVED)ESP8266 resets when using Blynk.virtualWrite inside the interrupt routine

Hello All,

I am using a push button thru interrupt in ports D6 and D7 in nodemcu, I put a capacitor and debounce routine also. All is working fine as expected, but when I insert a line with Blynk.virtualWrite to send a status to Blynk, the ESP reset at this stage. I tested with differents nodemcu and seems the same.

here is a part of the code involved in this:


 attachInterrupt(digitalPinToInterrupt(D6), onChange1, FALLING);

void onChange1() {

    boolean debounce1 = false; //ignora leitura falsa
   //se tiver trigger rapido e falso dentro do limite, vai ignorar
  if((millis() - lastDebounceTime1) <= debounceDelay1) {
    debounce1 = true;
  lastDebounceTime1 = millis();
  if(debounce1) return;  
     if (led1 == 0) {
        digitalWrite(D3, HIGH);
        led1 = 1;      
        Serial.println("LED-1 off");      
        Blynk.virtualWrite(V7, HIGH); <===== here is the issue when I insert the virtualWrite.
      if (led1 == 1) {
        digitalWrite(D3, LOW);   
        led1 = 0; 
        Serial.println("LED-1 on"); 
     // Blynk.virtualWrite(V7, LOW); <==== the same

Have anyone seen this behavior?



Are you sure you need the debounce routine in the software with a capacitor in place? I’d remove it. A cap should be enough from my experience (hardware debounce trumps software if you ask me) :slight_smile:

Yes interrupts are very messy with ESP’s, even SerialPrint() can crash the device. There are 2 solutions, detach the interrupt as soon as it has been called and then reattach when the function completes. Plus try setting a flag from the interrupt and no more. Then with a timer, check for the flag and do the Serial.print() and virtualWrite().

Guys, I just removed all of my libs, then installed the Arduino IDE 1.8.4 (I was in 1.8.3), installed blynk lib and all worked.

Also I will implement “detach/reattach”.

Thanks for the help.


1 Like