Blynk Email and Push Notifications

I’m attempting to use the Push Notification arduino example sketch (on Blynk’s documentation page) with my Photon but I’m running into issues with this command:

attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);

The Photon doesn’t recognize “digitalPinToInterrupt(2)” syntax.

I’ve tried the following which will all complie:

attachInterrupt(D2, notifyOnButtonPress, CHANGE);
attachInterrupt(2, notifyOnButtonPress, CHANGE);
attachInterrupt(V2, notifyOnButtonPress, CHANGE);

but still am unable to Push a Notification when I press the button…My Photon also freezes up if I press the button too many times repeatedly but I believe this is due to the 1 Push msg per minute limit.

Any suggestions would be much appreciated!
Thanks,

-Jp-

For the time being you need to set the pinMode() for your interrupt pins and with buttons you have to have pull-resistors for the inactive/open posittion of your button to prevent floating signals.

And for the pin naming, try to use the labels printed on the device (saves you some confusion ;-))

Scruff,

I’m not using an actual button (therefore I don’t require pull-resistors) but a virtual button within the Blynk app linked to that pin. Thanks for the response though…
-======================================================-
Ok so I’ve had a little more time to play with this and here is my discovery:

I can run this code with out the particle Photon freezing up:

#include "blynk/blynk.h"
#define BLYNK_PRINT Serial

 volatile int state = LOW;

void setup()
{
 Serial.begin(9600);
 Blynk.begin(auth);
 attachInterrupt(D7, notifyOnButtonPress, CHANGE);
}

void notifyOnButtonPress()
{
state = !state;
}

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

But the below code will freeze up the Photon and it will no longer respond to commands (and stays solid cyan after the button press, instead of “breathing cyan”) :

#include "blynk/blynk.h"
#define BLYNK_PRINT Serial

void setup()
{
 Serial.begin(9600);
 Blynk.begin(auth);
 attachInterrupt(D7, notifyOnButtonPress, CHANGE);
}

void notifyOnButtonPress()
{
Blynk.notify("Yaaay... button is pressed!");
}

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

This leads me to think that the Blynk.notify() command doesn’t play well with the attachInterupt() command??? What do you think the issue could be?

8 posts were split to a new topic: [SOLVED]Spark Core Blinking green, how to get Tinker back (/deep update)

Interrupt Service Routines need to be short and fast otherwise they mess up the system.
If you are calling functions from within them, you’d need to know what they are doing.
Especially if they are doing things that rely on interrupts themselves you might run into troubles.

I think I found away around it! see below code that worked for me:

void setup()
{
 Serial.begin(9600);
Blynk.begin(auth);  
attachInterrupt(D6, notifyOnButtonPress, RISING);
}

void notifyOnButtonPress()
{
state = !state;
}

void loop()
{
Blynk.run();
if (state == HIGH) 
{
 Blynk.notify("Yaaay... button is pressed!");
 delay (200);
 state = LOW;
  }
}

GOOD LUCK! :smile:

1 Like

Good to hear that it works for you now.

One point I’d add would be pinMode(D6, INPUT_PULLDOWN); before attachInterrupt() to avoid floating signals.

And maybe rather write state = HIGH; in your ISR. Buttons are bound to bounce and hence you might get “random” results with one button press.