Blynk interfering with reading pin on Particle Photon

So,
I have a program that controls my clothes dryer on my Photon, it uses an lcd shield and Blynk for control.
Here’s the problem, if I use Blynk it will stop the photon from reading the on/off button. Any idea what could be happnening? I’ve set up a simple demo app that elicits the same behavior.

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"

// This #include statement was automatically added by the Particle IDE.
#include "LiquidCrystal/LiquidCrystal.h"

#define BLYNK_PRINT Serial
char auth[] = "authgoeshere";

int start_stop_button = A5;
LiquidCrystal lcd(2, 1, 6, 5, 4, 3);


void setup() 
{
// Blynk.begin(auth); //uncomment these lines to turn blynk on/off
pinMode(start_stop_button, INPUT);
lcd.begin(16, 2);
lcd.clear();
}
void loop() 
{
   // Blynk.run(); //uncomment these lines to turn blynk on/off
    lcd.setCursor(0,0);
    lcd.print("Button");
int reading = digitalRead(start_stop_button);
if (reading == HIGH){
    lcd.setCursor(0,1);
    lcd.print("    pressed");
}

if (reading == LOW){
    lcd.setCursor(0,1);
    lcd.print("not pressed");
}
}

At first it works, then if I put the blynk app to write the button output to a5, the blynk button works, but the physical button won’t. Then if I have blynk write to a different output (say v1), the physical button won’t work. It will keep not working for some indeterminate number of resets of the photon. Eventually, the photon will start reading the physical buttons again. However, if I turn blynk off (comment out start and run lines), and reboot, the photon will read the physical button immediately. The same behavior happens in my dryer code too (which I’m happy to share, but it’s much longer, and much much harder to read).

Thanks,
JR

Hi,

Sorry I’m a little confused by what your saying.

It looks like your code is setting A5 as an input to read from the button, I assume you have an external pull up for this or it doesn’t need one.

You also say that you use Blynk to write to A5, so your trying to use A5 as an input and an output at the same time? A look at the how the Blynk app is configured might help.

Also in your main loop it looks like you are writing the lcd every time through the loop, it would be better to keep track of the old button state so you only write to the lcd when something has changed.

Thans,
Nick

A5 is an input, there’s a physical button, with a pulldown resistor.

I’ve probably added some unnecessary detail in my original post. The upshot is:
When Blynk runs, the Photon can’t read the physical button.

It doesn’t matter if I’m using Blynk to write to A5 or not, with Blynk the physical button just doesn’t work.

Please check the example to see how to use physical button with Blynk:

https://github.com/blynkkk/blynk-library/tree/master/examples/More/ButtonInterrupt

Thanks Pavel, I’ll try that tomorrow. Is this a new feature? I didn’t have this problem until today.

@pavel
I’m trying to get the button interrupt code to work, but it won’t compile. Build.particle just gives: testing_start_stop_button.cpp:83:42: error: 'digitalPinToInterrupt' was not declared in this scope

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
// This #include statement was automatically added by the Particle IDE.
#include "LiquidCrystal/LiquidCrystal.h"

#define BLYNK_PRINT Serial
char auth[] = "auth";

WidgetLED led1(V1);

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);

  // Make pin 2 HIGH by default
  pinMode(A5, INPUT);
  // Attach INT to our handler
  attachInterrupt(digitalPinToInterrupt(A5), checkPin, CHANGE);
}

void checkPin()
{
  // Invert state, since button is "Active LOW"
  if (digitalRead(2)) {
    led1.off();
  } else {
    led1.on();
  }
}

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

@vshymanskyy please take a look