Led widget with esp8266, reseting board

Hi
I am experimenting on using Blynk with Sparkfun esp8266 thing Dev and Feather Huzzah esp8266 Wifi. All is working as it should and I am impressed by Blynk.

The only problem I found is with the Led widget. In my code I declared the

WidgetLED led1(V1)

and the function
void checkPin()
{
if (digitalRead(13)) {
led1.on();
Serial.println(“Led on”);
} else {
led1.off();
Serial.println(“Led off”);
}
}

As soon as the script try to execute the checkpin() the 2 boards start resetting continuously.
If I remove the led1.on() and led1.off(), then the program execute as it should.

Hello. Please post full sketch.

‘’’
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include “ESP8266WiFi.h”
#include “BlynkSimpleEsp8266.h”

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";

WidgetLED led1(V1);

void setup()
{
  Serial.begin(9600);
 Blynk.begin(auth, "dlink-2", "pass");


  pinMode(13, INPUT_PULLUP);
  // Attach INT to our handler
  attachInterrupt(digitalPinToInterrupt(13), checkPin, CHANGE);
}

void checkPin()
{

  if (digitalRead(13)) {
    led1.on();
    Serial.println("Led on");
   } else {
    led1.off();
    Serial.println("Led off");
  }
}

void loop()
{
  Blynk.run();
}

‘’’

the first 3 lines of the program are

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h>'''

@mauricep please use </> for code formatting.

Dmitriy, where can I find the format code

@mauricep when adding comment there is a sing “</>”. Are you sure those 13 pin is not used with other libraries or something like that?

I tried different pin whit the same results. Nothing is connected to the board and I only access it through the a widget button connected to the GP13 pin

Not sure this will help. But can you try adding

  while (Blynk.connect() == false) {
    // Wait until connected
  }

after

Blynk.begin(auth, "dlink-2", "pass");

@mauricep also try to comment

void checkPin()
{

if (digitalRead(13)) {
//led1.on();
Serial.println("Led on");
} else {
//led1.off();
Serial.println("Led off");
}
}

So we can make sure problem is really in blynk.

Thanks Dmitriy, I will give it a try before coming back

I already tried to comment the 2 lines led11.on() and led1.off() and the program start to work as it should.

Hm… I have only 1 suggestion at the moment. This method checkPin() is executed many times during short period of time. Is that true for your case?

If you do led.on(), led.off() too often ESP may be not able to handle such many requests in short time and it can go down.

I am using the widget button as a switch so it is in standby mode most the time.

I added the while statement and retried with the same result: the board goes offline , then restart.

If I comment the 2 lines the checkpin() function work as it should and report the debug line (Serial.println( "On or off) on the serial monitor

@vshymanskyy any ideas?

I have the feeling that the error comes from the led1.XXX() .
I will continue to play around with Blynk and if I find something I will be back.

By the way I would like to thanks for the time you took to try to solve the problem and say that I really appreciate Blynk

1 Like

@mauricep

For future:
All the code sections should be formatted. Please edit all your posts containing code.

Wrap the code by adding 3 Backtick: ``` symbols:

Example:

 ``` cpp <--put 3 backticks BEFORE your code starts  (cpp means C++ language) 

   //Put your code here
   //..................
   //..................

 ``` <--insert 3 backticks AFTER your code

I have a Sparkfun Thing that I run a basic project on. If you are trying to use the builtin LED on that board, I am pretty sure it is GP5, not 13. Try that and see if it works
Good Luck

In fact I am using the pin 13 on the esp to start an interrupt, not for controling a led on the board

Thanks for your reply

Hi all, I think ESP cannot send data to WiFi while it’s in the interrupt context.
You should defer the action to the main loop somehow, raise a flag variable for example…