Get data from hardware - Virtual Pins

Hi guys, in this opportunity I want to ask you about virtual pins.
I’m trying to Getting data from hardware
In my case I’m using an ESP8266-01 hardware with two IO pins
in this case the ESP8266-01 has GPIO0 and GPIO2

This is the way that I Understand the use of virtual pins

ESP8266-01 Virtual Pins
GPIO0 - Present V0 - Present
GPIO1 - Not present in this hardware V1 - Not present
GPIO2 - Present V2 - Present
GPIO3 - Not present in this hardware V3 - Not present

if this is correct (I hope)
I use the GPIO0 in the APP with a pulse button to refer to GPIO0
to refer to the GPIO2 must I use the Virtual pin V2?

I want to use GPIO0 to control a light,
and use the GPIO2 to read the state of the light
for to know if the light is on or off the V2 will send data to the APP

So in the APP I will have a pulse button and a led
the pulse button to control and the led for read the data from V2

Is this correct?


Virtual pins are separate entities and do not relate to harware pins.
You can assign widgets to either hardware pins OR any virtual pins.
Hardware pin control does just that without software intervention. (Simple control of on/off, pwm output, adc reading etc}
Virtual pin control infers the use of related software routines, in the form of a reading response if data is being sent (Button / Slider / Terminal etc) or sending data to widgets ( led, value, LCD, terminal)

Reading data sent by the app uses BLYNK_WRITE(V’pin no’) as in for example

        String pinData = param.asStr();  // data comingin
        slidV21val = param.asInt();
        const char* slid_dat =  pinData.c_str(); 

If you only have two gpio pins, you can still use as many Virtual pins as you like.
The above reading of the app widget could be a button or a slider using V21 etc, then you can do want you want with it. If you set a gpio as an output you could control it according to what has been received and any conditions that might need to be met. ie. your GPIO0.

In your program you would set GPIO2 as an input.
This would be fed by some connection to the light source. (hardwired, LDR etc)
The level sensed by GPIO2 now needs to be sent to the app, and displayed in some format.

You want to use the LED widget. Ok… select it and assign any available Virtual pin number.
Assign a name to the led widget …

WidgetLED led1(0) //note that led widget in app has V0 assigned to it

You can now switch the app’s led on or off by using within your program. or led1.on()

For testing … in the BLYNK_WRITE, if the received value is 1 from the button, switch the light on. Then sense your GPIO2 pin, and according to the conditions, use led1.on() of .off().

Similarly you could use the LCD widget and send “Light is on (Off)”. etc.
Remember you also have the adc pin, which can either be directly used and displayed in a Value box, or the data could be sent to a Virtual pin via software.
I use the hard version to take a reading every 5 secs. In my ESP12, the reading is reversed, so for a scale of 0 - 100, in the app set up of a Value box, adc0 is selected as the pin, and the range value set as 100 /~/ 0. Where /~/ represents the selection of the bridging wire between the boxes. The time is set for how often it it is required to be read.

You could also display the signal strength that the esp receiving, which can be useful.
Have a value button on say V30, set to 1 second or whatever, then in your program …

         Blynk.virtualWrite(V30, WiFi.RSSI()  );

Hope this helps a little


I’m waiting my two new ESP8266-12 for practice Virtual pins
I think that I need more practice in the code part too, for better understanding

Thanks Roffey