Instructables :How to use virtual pins?

Here is a simple guide on how to get started with virtual pins :smile:

I was wondering that the readme doc should be enough, but I saw that there are still some people like me trying to figure out the basics and working their way along…
I hope making basic tutorials like this is not a waste of time… Atleast until you guys release a full doc or basic tutorials :laughing:

1 Like

Hi, I’ve a question, because even I would buy form ESP8266 ESP-1, I wanted to know if there’s already pre-loaded with the firmware, or I have to flash me, thanks in advance

Hey! The esp8266 come with preloaded firmware–aka the AT firmware.
However it depends on where you get your board, some might come with third party firmware as the NODE MCU and lua script
Mine had another flavor from a chinese team called ai-thinker
Basically you can rewrite the firmware directly using the arduino IDE! Note that you need to install relevant Libraries

Maybe this will be helpful… I made an instructable on how to get started with esp8266 and blynk

Thanks for the info :slight_smile: so hopefully I can load the firmware via arduino without the use of other forms?
Now I look at the guide :slight_smile:

Yeah. But you GPIO0 must be low! At first it can be tricky but don’t give up, with some attempts you will be able to upload it. And if someday you want to use AT firmware or node mcu you can flash it again!
I noticed you want to buy esp-01, it does not have a lot of gpio and adc, so using it as standalone mcu might be limited but its great using as wifi shield for arduino(with at firmware). Consider esp-12 if you want to use esp8266 as standalone and get breadboard friendly one

Hello, I recently ordered an EPS-07, would you be kind enough to help me with links since there are many guides around? If I am not mistaken is similar to the ESP-12 … I’m afraid to burn it immediately

Hi… You can google the ESP8266 ESP-07 pin out diagram. It is basically similar to esp-12 and they work at 3.3V logic… This is very important especially for VCC and RX connections!!!
I made an instructable on how to get started with these boards
here are some links that may be helpful… Again, anything you try is at your own risk as I have not experimented with esp07 :cry:

http://www.esp8266.com/index.php

Hope this helps

Thanks for sharing.
I noted that the virtual LED turn on time has about one second delay after pushing the button widget. Seems like a long delay. Is this normal?
Cheers!

@favstuff

It could be issues with your code in case your execution loop takes too long, otherwise this is not normal. Please try ping cloud.blynk.cc. Usually result should be below 100ms.

Thank you Dmitriy.
Sorry, here’s the code:

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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] ="xxxxxx";

int ledPin2=2; // assign widget LED to tie with gpio pin 2

// ====================================================== 

void setup()
{
  
  Serial.begin(9600);
  Blynk.begin(auth, "o", "j8r");
 
pinMode (ledPin2,OUTPUT); // assign ledPin2 as output

}


void loop()
{
   Blynk.run();
   
  int led2value = digitalRead (ledPin2);  // note digitalRead used although this is output pin.
  if (led2value==HIGH){  // if value is HIGH, turn OFF virtual LED 2
    Blynk.virtualWrite (ledPin2,LOW);}  // note syntax is Blynk.virtualWrite
    else {
      Blynk.virtualWrite (ledPin2,HIGH);}
    }

I’m a newb, so please feel free to give feedback.
Thanks.

@favstuff

I wonder how that code works at all for you =). Problem here - loop execution is very quick. So within 1 second your code will be executed 50-100 times at least. So that’s why you have such delay. It could be hard for your ESP to send so many request so quickly so this is reason for delay.

Have a look at this sketch. You could do the same within some interval, let’s say every 100 ms… Or you could add variable in main loop and send virtualWrite only when led2value changed.

int prev = HIGH;
void loop()
{
  Blynk.run();
  int led2value = digitalRead (ledPin2); 
  if (led2value != prev){  
    Blynk.virtualWrite (ledPin2,led2value);}  
    
      
      prev = led2value;
    
}

Thanks. I’m not quite sure I can see the difference between my code and the one you wrote (due to my poor knowledge). They both toggle the states when led2value changed. I am glad to at least know the problem is due to my code and I will experiment based on your input.
Interestingly, my code does work through many trials and errors. I was having the problem of booting up during power on with gpio2 connected to led, so I tied gpio2 to 3V and hence the reverse logic.
The issue that I still have currently apart from the led light up delay is that after booting, the led turns ON, regardless of whether I set ledPin2 to high or low at setup. I’m out of ideas how to fix this.
Anyway, thanks a lot.

The difference is - my code sends virtualWrite only when led2value was changed, while your code sends virtualWrite every time even led2value wasn’t changed.

Excellent! I think I see the subtle difference now.
Going to play with it later.
Thanks!

You are a genius man… Respect

1 Like