[SOLVED] ESP8266 Wifi Shield + Virtual Pin

Hey guys,
first of all, I want to say that I was searching the forum for similar problems (like: here ) but I just cannot get it to work properly.

Since I am new to all this, I followed this instruction to set up my ESP8266 as a Wifi Shield to use it with blynk.

As in the instruction I have an Arduino Uno and the ESP8266.

I can control any Digital Output of my Board via the Blynk App (e.g. the LED at D13 with a Button). But I cannot use the Virtual Pins. Either I have a mistake in my Code or something is wrong with my software/ hardware setup.

Here is my Code (please be aware that I use the 0.3.4 library as in the instructions, because I didn’t manage to get it run with the 0.3.7 - neither hardware nor software serial). In order to test the Virtual Pins, I want to control a LED connected to Digital 2.

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>

#define EspSerial Serial

ESP8266 wifi(EspSerial);

char auth[] = "###";

int vvalue; //global value for blynk widget

void setup()
{
  pinMode(2,OUTPUT);

  Serial.begin(9600);
  delay(10);

  EspSerial.begin(115200);
  delay(10);

  Blynk.begin(auth, wifi, "KDG-7B24B", "###");
}

BLYNK_WRITE(V1)
{
  vvalue = param.asInt();
}

void loop()
{
  Blynk.run();
  if (vvalue)
  digitalWrite(2,HIGH);
  else
  digitalWrite(2,LOW);
}

I tried the getData example, but it does not display anything in my Serial Monitor. It always just shows these information:

[19] Blynk v0.3.4
[520] Connecting to KDG-7B24B
ATE0
AT+CWMODE?
AT+CWJAP="KDG-7B24B","###"
AT+CIFSR
[5576] IP: +CIFSR:STAIP,"192.168.0.208"
+CIFSR:STAMAC,"###"

OK
AT+CIPMUX=0
[5598] Connected to WiFi
AT+CIPCLOSE
AT+CIPSTART="TCP","blynk-cloud.com",8442
AT+CIPSEND=37
 ###[10749] Ready (ping: 13ms).
AT+CIPSEND=5

After that it just keeps sending AT+CIPSEND=5 every couple of seconds.

I have a project with a Button to Virtual Pin V1. But nothing happens when I press it. My button with LED13 still works tho.

Before you answer, please consider that I am new to this and try to make it as clear as possible. I really appreciate your help! Thank you so much!

PS: The wiring of the ESP8266 is also according to the instructions in the link above. Might the problem be there?

Thanks!!!
Chris

Initialize your ‘vvalue’ in BLYNK_WRITE(V1), and make other commands that have to do with it in BLYNK_WRITE(V1). Also, this makes no sense:

if (vvalue)
  digitalWrite(2,HIGH);
  else
  digitalWrite(2,LOW);

It should be something like:

if (vvalue == HIGH) {

  digitalWrite(2, HIGH);
}

 else {

  digitalWrite(2, LOW);

}

Try this:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>

#define EspSerial Serial

ESP8266 wifi(EspSerial);

char auth[] = "###";

void setup() {

  pinMode(2,OUTPUT);

  Serial.begin(9600);
  delay(10);

  EspSerial.begin(115200);
  delay(10);

  Blynk.begin(auth, wifi, "KDG-7B24B", "###");
}

BLYNK_WRITE(V1) {
  
  int vvalue = param.asInt();

  if (vvalue == HIGH) {
    
    digitalWrite(2,HIGH);

  }
  
  else {
    
    digitalWrite(2,LOW)

  }
  
}

void loop() {
  
  Blynk.run();

}

Hey marcofusco,

thank you for your help.

Unfortunately, it still does not do anything when I press the button for V1 in the app :sob:

//EDIT I am sorry, I had a messed up hardware setup. It is working!!! Thank you :wink:

I guess that was my issue all the time xD :smiley:

Chris

No problem! Try your original sketch too. Did that work? I’m curious. Either way I’m glad you got things sorted out.

Marco

how you fix it? i have same problem. I used esp8266 hardser? You use a hardser or softser? thank you before :slight_smile:

I had my test LED wired incorrectly :confused::grin:
I am using hardware serial.