Help blynk + mcp23017

hello, I got a code that the mcp23017 responds for blynk, but it is unstable, the led and the blynk button are on by themselves why is it?

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include "Adafruit_MCP23017.h"
Adafruit_MCP23017 mcp;

char auth[] = "";
char ssid[] = "";
char pass[] = "";

// Set your LED and physical button pins here
//const int ledPin = 2;
//const int btnPin1 = 3;

BlynkTimer timer;
void checkPhysicalButton();

int ledState1 = LOW;
int btnState1 = HIGH;

int ledState2 = LOW;
int btnState2 = HIGH;

// Every time we connect to the cloud...
  // Request the latest state from the server

  // Alternatively, you could override server state using:
  //Blynk.virtualWrite(V2, ledState);

// When App button is pushed - switch the state
  ledState1 = param.asInt();
  mcp.digitalWrite(0, ledState1);
  ledState1 = param.asInt();
  mcp.digitalWrite(2, ledState2);

void checkPhysicalButton()
  if (mcp.digitalRead(9) == LOW) {
    // btnState is used to avoid sequential toggles
    if (btnState1 != LOW) {

      // Toggle LED state
      ledState1 = !ledState1;
      mcp.digitalWrite(0, ledState1);

      // Update Button Widget
      Blynk.virtualWrite(V1, ledState1);
    btnState1 = LOW;
  } else {
    btnState1 = HIGH;

void setup()
  // Debug console
  Blynk.begin(auth, ssid, pass);
////////////saidas mcp//////////////  

mcp.pinMode(0, OUTPUT);
mcp.pinMode(1, OUTPUT);


mcp.pinMode(8, INPUT);
mcp.pinMode(9, INPUT);

  //pinMode(ledPin, OUTPUT);
  //pinMode(btnPin, INPUT_PULLUP);
  mcp.digitalWrite(0, ledState1);
  mcp.digitalWrite(1, ledState2);
  // Setup a function to be called every 100 ms
  timer.setInterval(100L, checkPhysicalButton);

void loop()

What EXACTLY does this mean

Is this still using the bare chip, or a board like the Waveshare?


good night, actually i’m still using the chip …
I commented that it hadn’t worked before, but with a simple LED code and button it worked, but in the blynk he gets a little crazy

I’m not sure how you expect people to take that information and turn it into something meaningful - then offer you any type of feedback about how you might overcome that problem.


good morning, what i meant is that the leds flash even without pressing the button on the blynk, that’s why i said they are crazy.
sorry the way i express myself, i’m brazilian and i need to translate all the text and sometimes it doesn’t come out as expected

Maybe a problem with the way you’ve implemented the hardware?
If you don’t have the correct pull ups/downs then the inputs might be floating.
May also be a voltage stabilisation issue?