Using ESP8266 with BLYNK

Hi everyone,

I recently created a POWER/SWR meter with arduino and using an LCD 16x4 I print the Forward power / Reflected power and SWR. There are also a few menus to change units (W to dBm and to mW).

I have been trying to use Blynk app Android with 2 gauge graphs to display the values I read and I also setup an LED on pin 13.

I integrated the BlynkSimpleShieldEsp8266_SoftSer on my code and it does not work very well. Here is what I get:

[99] Blynk v0.3.1
[600] Connecting to Freebox-CQ…CQ…CQ
[7854] IP: +CIFSR:STAIP,“192.168.1.10”
+CIFSR:STAMAC,“18:fe:34:d7:5f:db”

OK
[7885] Connected to WiFi
[14931] Ready (ping: 111ms).
[25098] Login timeout
[35765] Ready (ping: 94ms).
[49041] Login timeout
[59958] Ready (ping: 112ms).
[70123] Login timeout
[81005] Ready (ping: 113ms).
[92276] Login timeout
[103008] Ready (ping: 73ms).
[115607] Login timeout
[126422] Ready (ping: 111ms).
[137663] Login timeout
[148642] Ready (ping: 111ms).
[159292] Login timeout
[170233] Ready (ping: 71ms).
[181995] Login timeout
[192886] Ready (ping: 110ms).
[203075] Login timeout
[213625] Ready (ping: 71ms).
[224352] Login timeout
[235360] Ready (ping: 111ms).
[245525] Login timeout
[256400] Ready (ping: 111ms).
[267445] Login timeout
[278017] Ready (ping: 71ms).
[288449] Login timeout
[299424] Ready (ping: 71ms).
[310308] Login timeout
[321293] Ready (ping: 111ms).
[331947] Login timeout
[342494] Ready (ping: 71ms).
[353395] Login timeout
[364335] Ready (ping: 91ms).
[374501] Login timeout
[385080] Ready (ping: 111ms).
[404771] Login timeout
[415678] Ready (ping: 112ms).
[425843] Login timeout
[436480] Ready (ping: 71ms).
[450607] Login timeout
[461485] Ready (ping: 110ms).
[471667] Login timeout
[482526] Ready (ping: 111ms).
[493176] Login timeout
[503894] Ready (ping: 45ms).

Lots of Login timeouts, and as a result my display freezes for a few minutes and then comes back with updated values.

My hardware is:
Arduino NANO
LCD display 16x4
ESP-12 Wifi module connected to pinss 2 and 3 as SoftwareSerial (with 3.3V)

I wonder also if it is possible to read the info I have on the LCD? I am using bar graphs and it would be nice to see the same as I have in the LCD connected to the arduino NANO.

Any help would be appreceated.

Thanks
Filipe Lopes

BTW here is my code, a bit long but maybe someone can have a look at it:

//******************************* INITIALIZATION *******************************
//******************************************************************************
//#define BLYNK_DEBUG

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(EspSerial);
char auth[] = "";

#include <LiquidCrystal.h>
#include <math.h>

#define IN_FWD    A0  // analog input for left channel
#define IN_REFL   A1  // analog input for right channel

#define T_PEAKHOLD   1000           // msec peak hold time before return
#define T_pepHOLD    500        // msec pep hold time before return

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

byte  fill[6]={ 0x20,0x00,0x01,0x02,0x03,0xFF };      // character used to fill (0=empty  5=full)
byte  peak[7]={ 0x20,0x00,0x04,0x05,0x06,0x07,0x20 }; // character used to peak indicator
int   lmax[5];                                        // level max memory
int   dly[5];                                         // delay & speed for peak return
long  lastT = 0;
long  lastT1=0;                                        // update display timer1
long  lastT2=0;                                        // update display timer2
long  lastTpep = 0;                                   // update PEP display

int   anF = 0;                            // analog read forward power
int   anR = 0;                            // analog read reflected power
int T_REFRESH1;                           // msec bargraph refresh rate

unsigned long   pow_fwd = 0;              // power forward (watts)
unsigned long   pow_ref = 0;              // power reflected (watts)

unsigned int   pow_fwd_max = 0;           // power forward max (for peak hold)
unsigned int   pow_ref_max = 0;           // power reflected max (for peak hold)

byte lcdNumCols = 16; // -- number of columns in the LCD

//const int Pin_Backlight = 13;
const int Pin_Mode_Button_Type = 5;
const int Pin_Mode_Button_Band = 4;
//const int Pin_Mode_Button_Unit = 3;
//const int Pin_Mode_Button_Mode = 2;
const int Pin_Mode_Button_Resolution = 1;

int buttonPushCounter_Type = 0;
int buttonPushCounter_Band = 0;
int buttonPushCounter_Unit = 0;
int buttonPushCounter_Mode = 0;
int buttonPushCounter_Resolution = 0;

int buttonState_Type = 0;
int buttonState_Band = 0;
int buttonState_Unit = 0;
int buttonState_Mode = 0;
int buttonState_Resolution = 0;

int lastButtonState_Type = 0;
int lastButtonState_Band = 0;
int lastButtonState_Unit = 0;
int lastButtonState_Mode = 0;
int lastButtonState_Resolution = 0;

float Value = 0.0;
int Analog_Input_Port_FWD = 0;
int Analog_Input_Port_REF = 1;
int Battery_Input_Port = 5;
float Voltage = 0.0;
float VoltageREF = 0.0;
float Power_dBm = 0.0;
float Power_dBm_REF = 0.0;
float Power_mW = 0.0;
float Power_mW_REF=0.0;
float Power_W = 0;
float Power_W_peak=0.0;
float Power_W_REF=0.0;
float SWR = 0;
float SWR_ratio = 0;
int SWRDis = 0;
float SWR_FWD = 0.0;

float SWR_REF = 0.0;
float Battery = 0.0;
float Batt = 0.0;
const float Coupling_Coeff_HF = 0;
/*
const float Coupling_Coeff_HF = 48;
const float Coupling_Coeff_6m = 57.5;
const float Coupling_Coeff_4m = 54.7;
const float Coupling_Coeff_2m = 48.5;
const float Coupling_Coeff_70cm = 39.2;
*/
unsigned long BacklightTime = 0;

byte block[8][8] =
{
  { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }, // define character for fill the bar
  { 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 },
  { 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C },
  { 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E },

  { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, // define character for peak level
  { 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 },
  { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 },
  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
};

//******************************************************************************
//******************************* SETUP ****************************************
//******************************************************************************

void setup() {
  
  Serial.begin(115200);
  
  // Set ESP8266 baud rate
  // 9600 is recommended for Software Serial
  EspSerial.begin(9600);
  delay(100);
  Blynk.begin(auth, wifi, "Freebox-CQ..CQ..CQ", "");
  delay(50);

  

  lcd.begin (16, 4);

  for ( int i = 0 ; i < 8 ; i++ )
    lcd.createChar( i, block[i] );

  lcd.clear();

//  pinMode(Pin_Backlight, OUTPUT);
  
  lcd.setCursor(0,0);
  lcd.print("SWR POWER meter");
  lcd.setCursor(0,1);
  lcd.print("      by       ");
  lcd.setCursor(0,2);
  lcd.print("");
  lcd.setCursor(0,3);
  lcd.print("F4VPX-F4AJS V1.5");
  
  delay(1000);
  lcd.clear();
  //delay (500); 
  

  pinMode(Pin_Mode_Button_Type, INPUT);
  pinMode(Pin_Mode_Button_Band, INPUT);
  //pinMode(Pin_Mode_Button_Unit, INPUT);
  //pinMode(Pin_Mode_Button_Mode, INPUT);
  //pinMode(Pin_Mode_Button_Resolution, INPUT);

}

//******************************************************************************
//******************************* LOOP *****************************************
//******************************************************************************

void loop() {
  
  

  
  //BUTTON 1 MODE ---------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  buttonState_Type = digitalRead(Pin_Mode_Button_Type);
  if (buttonState_Type != lastButtonState_Type)  {
    if (buttonState_Type == HIGH) {
      buttonPushCounter_Type++;
    }
    lcd.clear();
  }

  lastButtonState_Type = buttonState_Type;

  if (buttonPushCounter_Type == 5) {
    buttonPushCounter_Type = 0;
    lcd.clear();
  }



  buttonState_Type = digitalRead(Pin_Mode_Button_Type);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState_Type == LOW) {
    // turn LED on:
 //   digitalWrite(Pin_Backlight, HIGH);
    BacklightTime = millis ();
  }
  else if (((millis() -  BacklightTime) > 60000)) {
    // turn LED off:
//    digitalWrite(Pin_Backlight, LOW);
  }




  //BUTTON 2 W dBm mW   ---------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  buttonState_Band = digitalRead(Pin_Mode_Button_Band);
  if (buttonState_Band != lastButtonState_Band)  {
    if (buttonState_Band == HIGH) {
      buttonPushCounter_Band = buttonPushCounter_Band + 10;
    }
    lcd.clear();
  }

  lastButtonState_Band = buttonState_Band;

  if (buttonPushCounter_Band == 30) {
    buttonPushCounter_Band = 0;
    lcd.clear();
  }


  buttonState_Band = digitalRead(Pin_Mode_Button_Band);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState_Band == LOW) {
    // turn LED on:
    //digitalWrite(Pin_Backlight, HIGH);
    BacklightTime = millis ();
  }
  else if (((millis() -  BacklightTime) > 60000)) {
    // turn LED off:
    //digitalWrite(Pin_Backlight, LOW);
  }


/*
  //BUTTON 3 UNITS, dBm, mW, W   ---------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  buttonState_Unit = digitalRead(Pin_Mode_Button_Unit);
  if (buttonState_Unit != lastButtonState_Unit)  {
    if (buttonState_Unit == HIGH) {
      buttonPushCounter_Unit = buttonPushCounter_Unit + 100;
    }
    lcd.clear();
  }

  lastButtonState_Unit = buttonState_Unit;

  if (buttonPushCounter_Unit == 400) {
    buttonPushCounter_Unit = 100;
  }



  buttonState_Unit = digitalRead(Pin_Mode_Button_Unit);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState_Unit == LOW) {
    // turn LED on:
    digitalWrite(Pin_Backlight, HIGH);
    BacklightTime = millis ();
  }
  else if (((millis() -  BacklightTime) > 60000)) {
    // turn LED off:
    digitalWrite(Pin_Backlight, LOW);
  }
*/
 
  unsigned int value = 0;
  float a = 0.0;
  int i = 0;
  
  
  switch(buttonPushCounter_Type+buttonPushCounter_Band+buttonPushCounter_Unit) 
  {
                                                                                                                                                 
  case 0: 
      
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      Calculation_SWR();   
      T_REFRESH1 = 45;   
      graph_W(T_REFRESH1);
      
      lcd.setCursor(0,1);
      lcd.print( "FWD");
      lcd.setCursor(8,1);
      lcd.print( "W");
      lcd.setCursor(0,3);
      lcd.print( "REF");
      lcd.setCursor(8,3);
      lcd.print( "W");
      if(pow_fwd == 0 || (pow_ref > pow_fwd ))
          {
          lcd.setCursor(13,2);
          lcd.print("swr");
          lcd.setCursor(12,3);
          lcd.print("-.--");
          }
      else{
          lcd.setCursor(13,2);
          lcd.print( "swr");
          lcd.setCursor(12,3);
          lcd.print(SWR);
          }

      lcd.setCursor(4,1);
      lcd.print("    ");
      lcd.setCursor(4,1);
      lcd.print(pow_fwd_max);
      
      lcd.setCursor(4,3);
      lcd.print("   ");
      lcd.setCursor(4,3);
      lcd.print(pow_ref_max);

  break;

  
  case 1:
      
      lcd.setCursor(0,1);
      lcd.print("PWR ");
      lcd.setCursor(4,1);
            
  break;
  
  case 11:
      
      lcd.setCursor(0,1);
      lcd.print("PWR ");
      lcd.setCursor(4,1);
            
  break;
  
  case 21:
      
      lcd.setCursor(0,1);
      lcd.print("PWR ");
      lcd.setCursor(4,1);
            
  break;


  case 2:
      
      Calculation_Voltage();
      Calculation_Voltage_REF();
      lcd.setCursor(0,0);
      lcd.write("AD8307 Voltage ");
      lcd.setCursor(0,1);
      lcd.print("Fwd: ");
      lcd.print(Voltage,4);
      lcd.print(" V");
      lcd.setCursor(0,2);
      lcd.print("Rev: ");
      lcd.print(VoltageREF,4);
      lcd.print(" V");
      
      delay(50);
  break;

  case 12:
      
      Calculation_Voltage();
      Calculation_Voltage_REF();
      lcd.setCursor(0,0);
      lcd.write("AD8307 Voltage ");
      lcd.setCursor(0,1);
      lcd.print("Fwd: ");
      lcd.print(Voltage,4);
      lcd.print(" V");
      lcd.setCursor(0,2);
      lcd.print("Rev: ");
      lcd.print(VoltageREF,4);
      lcd.print(" V");
      
      delay(50);
  break;
  
  case 22:
      
      Calculation_Voltage();
      Calculation_Voltage_REF();
      lcd.setCursor(0,0);
      lcd.write("AD8307 Voltage ");
      lcd.setCursor(0,1);
      lcd.print("Fwd: ");
      lcd.print(Voltage,4);
      lcd.print(" V");
      lcd.setCursor(0,2);
      lcd.print("Rev: ");
      lcd.print(VoltageREF,4);
      lcd.print(" V");
      
      delay(50);
  break;


  
  case 3:
     
      Calculation_Battery();
      lcd.setCursor(0,0);
      lcd.print("Input Voltage :");
      lcd.setCursor(5,1);
      lcd.print(Batt,2);
      lcd.setCursor(10,1);
      lcd.print("V");
      delay(50);
  break;

  case 13:
     
      Calculation_Battery();
      lcd.setCursor(0,0);
      lcd.print("Input Voltage :");
      lcd.setCursor(5,1);
      lcd.print(Batt,2);
      lcd.setCursor(10,1);
      lcd.print("V");
      delay(50);
  break;
  
  case 23:
     
      Calculation_Battery();
      lcd.setCursor(0,0);
      lcd.print("Input Voltage :");
      lcd.setCursor(5,1);
      lcd.print(Batt,2);
      lcd.setCursor(10,1);
      lcd.print("V");
      delay(50);
  break;

  

  case 4:
      
      Calculation_SWR();
      lcd.setCursor(0,0);
      lcd.print("SWR Calc : ");
      
      if (SWR > 3) {
        lcd.setCursor(0,1);
        lcd.print("SWR > 3 !");
      }
      else{
      lcd.setCursor(0,1);
      lcd.print(SWR);
      lcd.print("         ");
      }
      delay(50);
  break;

  case 14:
      
      Calculation_SWR();
      lcd.setCursor(0,0);
      lcd.print("SWR Calc : ");
      
      if (SWR > 3) {
        lcd.setCursor(0,1);
        lcd.print("SWR > 3 !");
      }
      else{
      lcd.setCursor(0,1);
      lcd.print(SWR);
      lcd.print("         ");
      }
      delay(50);
  break;

  
  case 24:
      
      Calculation_SWR();
      lcd.setCursor(0,0);
      lcd.print("SWR Calc : ");
      
      if (SWR > 3) {
        lcd.setCursor(0,1);
        lcd.print("SWR > 3 !");
      }
      else{
      lcd.setCursor(0,1);
      lcd.print(SWR);
      lcd.print("         ");
      }
      delay(50);
  break;


  
/*
  case 1:// W  25ms
      //Serial.println(buttonPushCounter_Type+buttonPushCounter_Band+buttonPushCounter_Unit);
      WATT();
      T_REFRESH = 25;
      showbar(T_REFRESH);
      lcd.setCursor(12, 1);
      lcd.print("25ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;
*/
/*
  case 11:// W  25ms
      
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      lcd.setCursor(12, 1);
      lcd.print("25ms");
      lcd.setCursor(4, 1);
      lcd.print("    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W ");
      
  break;


  case 21:// W  50ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 25;
      showbar(T_REFRESH);
      lcd.setCursor(12, 1);
      lcd.print("50ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;


  case 31:// W  75ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 25;
      showbar(T_REFRESH);
      lcd.setCursor(12, 1);
      lcd.print("75ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;

  
  case 41:// W  100ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 25;
      showbar(T_REFRESH);
      lcd.setCursor(11, 1);
      lcd.print("100ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;


  case 101:// W  25ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 25;
      showbar(T_REFRESH);
      lcd.setCursor(12, 1);
      lcd.print("25ms");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;
*/
  
  case 10:// dBm 
        
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      Calculation_SWR();   
      T_REFRESH1 = 45;   
      graph_dBm(T_REFRESH1);
      
      lcd.setCursor(0,1);
      lcd.print( "FWD");
      lcd.setCursor(0,3);
      lcd.print( "REF");
      if(Power_dBm == -75 || (Power_dBm_REF > Power_dBm ))
          {
          lcd.setCursor(13,2);
          lcd.print( "swr");
          lcd.setCursor(12,3);
          lcd.print("-.--");
          }
      else{
          lcd.setCursor(13,2);
          lcd.print( "swr");
          lcd.setCursor(12,3);
          lcd.print(SWR);
          }

      //lcd.setCursor(12,1);
      //lcd.print("25ms");
      lcd.setCursor(9,1);
      lcd.print("dBm");
      lcd.setCursor(4,1);
      lcd.print("     ");
      lcd.setCursor(4,1);
      lcd.print(Power_dBm,1);
      lcd.setCursor(9,3);
      lcd.print("dBm");
      lcd.setCursor(4,3);
      lcd.print("     ");
      lcd.setCursor(4,3);
      lcd.print(Power_dBm_REF,1);

      

  break;

  case 20:// mW

      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_mW();
      Calculation_SWR();   

      
      if(Power_mW >= 9999)
      {
        lcd.setCursor(0,0);
        lcd.print( "                 ");
        lcd.setCursor(0,0);
        lcd.print( "  PWR > 9999mW  ");
        lcd.setCursor(0,2);
        lcd.print( "                 ");
        lcd.setCursor(0,3);
        lcd.print( "                 ");
        lcd.setCursor(0,1);
        lcd.print( "Pse CHANGE SCALE ");

      }
      else {     
        T_REFRESH1 = 45;   
        graph_mW(T_REFRESH1);
        lcd.setCursor(0,1);
        lcd.print( "                 ");
        lcd.setCursor(0,1);
        lcd.print( "FWD");
        lcd.setCursor(0,3);
        lcd.print( "REF");
        //lcd.setCursor(12,1);
        //lcd.print("25ms");
        lcd.setCursor(10,1);
        lcd.print("mW");
        //lcd.setCursor(4,1);
        //lcd.print("     ");
        lcd.setCursor(4,1);
        lcd.print(Power_mW,1);
        lcd.setCursor(9,3);
        lcd.print("mW");
        lcd.setCursor(4,3);
        lcd.print("     ");
        lcd.setCursor(4,3);
        lcd.print(Power_mW_REF,1);
        
            if(pow_fwd == 0 || (pow_ref > pow_fwd ))
          {
          lcd.setCursor(13,2);
          lcd.print( "swr");
          lcd.setCursor(12,3);
          lcd.print("-.--");
          }
      else{
          lcd.setCursor(13,2);
          lcd.print( "swr");
          lcd.setCursor(12,3);
          lcd.print(SWR);
          }
      }
  break;
  /*
    
  case 301:// mW 25ms
      //Serial.println(buttonPushCounter_Type+buttonPushCounter_Band+buttonPushCounter_Unit);
      T_REFRESH = 25;
      showbar(T_REFRESH);
      Conversion_W_to_mW();
      lcd.setCursor(12, 1);
      lcd.print("25ms");
      lcd.setCursor(4, 1);
      lcd.print(Power_mW,1);
      lcd.print(" ");
      lcd.setCursor(8, 1);
      lcd.print("mW");
      
  break;

  
  case 111:// W  25ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 25;
      showbar(T_REFRESH);
      lcd.setCursor(12, 1);
      lcd.print("25ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;

  
  case 121://  W  50ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 50;
      showbar(T_REFRESH);
      lcd.setCursor(12, 1);
      lcd.print("50ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;

  
  case 131:// W  75ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 75;
      showbar(T_REFRESH);
      lcd.setCursor(12, 1);
      lcd.print("75ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;


  case 141://  W  100ms
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      T_REFRESH = 100;
      showbar(T_REFRESH);
      lcd.setCursor(11, 1);
      lcd.print("100ms    ");
      lcd.setCursor(4, 1);
      lcd.print(Power_W,0);
      lcd.setCursor(8, 1);
      lcd.print("W");
      
  break;


  case 211:// dBm 25ms
     
      T_REFRESH = 25;
      showbar(T_REFRESH);
      Conversion_W_to_dBm();
      lcd.setCursor(4, 1);
      lcd.print(Power_dBm);
      lcd.setCursor(8, 1);
      lcd.print("dBm");
      lcd.setCursor(12, 1);
      lcd.print("25ms    ");

  break;


  case 221:// dBm 50ms
     
      T_REFRESH = 50;
      showbar(T_REFRESH);
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      lcd.setCursor(4, 1);
      lcd.print(Power_dBm);
      lcd.setCursor(8, 1);
      lcd.print("dBm");
      lcd.setCursor(12, 1);
      lcd.print("50ms    ");
      
  break;


  case 231:// dBm 75ms
     
      T_REFRESH = 75;
      showbar(T_REFRESH);
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      lcd.setCursor(4, 1);
      lcd.print(Power_dBm);
      lcd.setCursor(8, 1);
      lcd.print("dBm");
      lcd.setCursor(12, 1);
      lcd.print("75ms    ");
      
  break;


  case 241:// dBm 100ms
     
      T_REFRESH = 100;
      showbar(T_REFRESH);
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      lcd.setCursor(4, 1);
      lcd.print(Power_dBm);
      lcd.setCursor(8, 1);
      lcd.print("dBm");
      lcd.setCursor(11, 1);
      lcd.print("100ms    ");
      
  break;
*/
/*
  case 311:// mW 25ms
     
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_mW();
      lcd.setCursor(4, 1);
      lcd.print(Power_mW,1);
      lcd.print("  ");
      lcd.setCursor(11, 1);
      lcd.print("mW");
      lcd.setCursor(12, 2);
      lcd.print("25ms");
      
  break;
*/
/*
  case 321:// mW 50ms
     
      T_REFRESH = 50;
      showbar(T_REFRESH);
      Conversion_W_to_mW();
      lcd.setCursor(4, 1);
      lcd.print(Power_mW,1);
      lcd.print(" ");
      lcd.setCursor(8, 1);
      lcd.print("mW");
      lcd.setCursor(12, 1);
      lcd.print("50ms    ");
      
  break;


  case 331:// mW 75ms
     
      T_REFRESH = 75;
      showbar(T_REFRESH);
      Conversion_W_to_mW();
      lcd.setCursor(4, 1);
      lcd.print(Power_mW,1);
      lcd.print(" ");
      lcd.setCursor(8, 1);
      lcd.print("mW");
      lcd.setCursor(12, 1);
      lcd.print("75ms    ");
      
  break;


  case 341:// mW 100ms
     
      T_REFRESH = 100;
      showbar(T_REFRESH);
      Conversion_W_to_mW();
      lcd.setCursor(4, 1);
      lcd.print(Power_mW,1);
      lcd.print(" ");
      lcd.setCursor(8, 1);
      lcd.print("mW");
      lcd.setCursor(11, 1);
      lcd.print("100ms    ");
     
  break;
  */
  
  
}
Blynk.run();
}

//******************************************************************************
//******************************* SUB-ROUTINES *********************************
//******************************************************************************


void Calculation_Voltage() {
  Value = analogRead(Analog_Input_Port_FWD);
  //Serial.print("ANALOG A0 ");
  //Serial.println(analogRead(Analog_Input_Port_FWD));
  Voltage = (Value * 5.0) / 1024;
  //Serial.print("VOLTAGE ");
  //Serial.println(Voltage);
}

void Calculation_Voltage_REF() {
  Value = analogRead(Analog_Input_Port_REF);
  VoltageREF = (Value * 5.0) / 1024;
}

void Calculation_Power_dBm() {
  Calculation_Voltage();
  Calculation_Voltage_REF();
  Power_dBm = (Voltage - 2.355) / 0.025;
  Power_dBm_REF = (VoltageREF - 2.355) / 0.025;
  //Serial.print("Power_dBm ");
  //Serial.println(Power_dBm);
}

void Conversion_dBm_to_mW() {
  Power_mW = (pow(10, (Power_dBm / 10)));
  Power_mW_REF = (pow(10, (Power_dBm_REF / 10)));
}

void Conversion_dBm_to_W() {
  Power_W = (pow(10, (Power_dBm / 10))) / 1000;
  Power_W_REF = (pow(10, (Power_dBm_REF / 10))) / 1000;
}

void Calculation_Battery() {
  Battery = analogRead(Battery_Input_Port);
  Batt = (((Battery * 5.00) / 1024.0));
}


void Calculation_SWR() {
  Calculation_Voltage();
  Calculation_Voltage_REF();
  SWR_FWD = Voltage;
  SWR_REF = VoltageREF;
  SWR_ratio = pow_fwd_max / pow_ref_max;
  SWR = abs ((1 + sqrt(SWR_ratio)) / (1 - sqrt(SWR_ratio))) ;
}




void graph_W  (int T_REFRESH1)
{
     //if (( millis()<lastT1 ) and (FirstLoop == 0))  return;
     //lastT1 = millis() + T_REFRESH1;
    
    pow_fwd = Power_W;
    pow_ref = Power_W_REF;

    anF = map( pow_fwd,0,2500,0,80 );    // 80 = 16 x 5 colums, full scale 2000w
    anR = map( pow_ref,0,300,0,60 );     // 80 = 16 x 5 colums, full scale 125 w
       
    bar( 0,anF,T_REFRESH1 );
    barREF( 2,anR,T_REFRESH1 );                  

  // update PEP¨meter ?
  
  if (pow_fwd >= pow_fwd_max) {             // we have a peak !
        lastTpep = millis();
        pow_fwd_max = pow_fwd;
        pow_ref_max = pow_ref;
         }
    
  if (millis() > (lastTpep + T_pepHOLD))  { // clear the peak after hold time
          pow_fwd_max = pow_fwd; 
          pow_ref_max = pow_ref; 
         }
}

void graph_mW  (int T_REFRESH1)
{
     //if (( millis()<lastT1 ) and (FirstLoop == 0))  return;
     //lastT1 = millis() + T_REFRESH1;
    
    pow_fwd = Power_mW;
    pow_ref = Power_mW_REF;

    anF = map( pow_fwd,0,9999,0,80 );    // 80 = 16 x 5 colums, full scale 2000w
    anR = map( pow_ref,0,300,0,60 );     // 80 = 16 x 5 colums, full scale 125 w
       
    bar( 0,anF,T_REFRESH1 );
    barREF( 2,anR,T_REFRESH1 );                  

  // update PEP¨meter ?
  
  if (pow_fwd >= pow_fwd_max) {             // we have a peak !
        lastTpep = millis();
        pow_fwd_max = pow_fwd;
        pow_ref_max = pow_ref;
         }
    
  if (millis() > (lastTpep + T_pepHOLD))  { // clear the peak after hold time
          pow_fwd_max = pow_fwd; 
          pow_ref_max = pow_ref; 
         }
}

void graph_dBm  (int T_REFRESH1)
{
     //if (( millis()<lastT1 ) and (FirstLoop == 0))  return;
     //lastT1 = millis() + T_REFRESH1;
    
    pow_fwd = Power_dBm;
    pow_ref = Power_dBm_REF;

    anF = map( pow_fwd,-70,70,0,80 );    // 80 = 16 x 5 colums, full scale 2000w
    anR = map( pow_ref,-70,50,0,60 );     // 80 = 16 x 5 colums, full scale 125 w
       
    bar(0,anF,T_REFRESH1);
    barREF(2,anR,T_REFRESH1);                  

  // update PEP¨meter ?
  
  if (pow_fwd >= pow_fwd_max) {             // we have a peak !
        lastTpep = millis();
        pow_fwd_max = pow_fwd;
        pow_ref_max = pow_ref;
         }
    
  if (millis() > (lastTpep + T_pepHOLD))  { // clear the peak after hold time
          pow_fwd_max = pow_fwd; 
          pow_ref_max = pow_ref; 
         }
}


void  bar  ( int row, int lev,int T_REFRESH1 )
{
  //lcd.write( row ? ' ' : ' ' );
  lcd.setCursor( 0, row );

  for ( int i = 0 ; i < 16 ; i++ )
  {
    int f = constrain( lev      - i * 5, 0, 5 );
    int p = constrain( lmax[row] - i * 5, 0, 6 );
    if ( f )
      lcd.write( fill[ f ] );
    else {
      lcd.write( peak[ p ] );
    }
  }
  if ( lev > lmax[row] )
  {
    lmax[row] = lev;
    dly[row]  = -(T_PEAKHOLD) / T_REFRESH1;              // Starting delay value. Negative=peak don't move
  }
  else
  {
    if ( dly[row] > 0 )
      lmax[row] -= dly[row];

    if ( lmax[row] < 0 )
      lmax[row] = 0;
    else
      dly[row]++;
  }
}

void  barREF  ( int row, int lev, int T_REFRESH1)
{
  //lcd.write( row ? ' ' : ' ' );
  lcd.setCursor( 0, row );

  for ( int i = 0 ; i < 11 ; i++ )
  {
    int f = constrain( lev      - i * 5, 0, 5 );
    int p = constrain( lmax[row] - i * 5, 0, 6 );
    if ( f )
      lcd.write( fill[ f ] );
    else {
      lcd.write( peak[ p ] );
    }
  }
  if ( lev > lmax[row] )
  {
    lmax[row] = lev;
    dly[row]  = -(T_PEAKHOLD) / T_REFRESH1;              // Starting delay value. Negative=peak don't move
  }
  else
  {
    if ( dly[row] > 0 )
      lmax[row] -= dly[row];

    if ( lmax[row] < 0 )
      lmax[row] = 0;
    else
      dly[row]++;
  }
}

@flopes Blynk recommends you use SoftSerial when using Arduino with ESP but those in the know seem to have chosen HardSerial.

I have all the timeout issues with Softserial and it is only for Serial Monitor use. You are supposed to use rx and tx on the Nano to connect the ESP and hook up FTDI to the SoftSerial pins (2 and 3 in your case). You don’t need the hassle of hooking up wires to pins 2 and 3 as the HardSerial will give you Serial Monitor access.

So you sketch will start:

//#define BLYNK_DEBUG           // MUST BE COMMENTED OUT
#define BLYNK_PRINT Serial
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>

#define EspSerial Serial // Set ESP8266 Serial object
ESP8266 wifi(EspSerial);

// etc

void setup()
{
  Serial.begin(115200); // Set console baud rate
  delay(10);

  EspSerial.begin(9600);  // Set ESP8266 baud rate
  delay(10);
// etc
}

Hello @Costas

thanks for the fast reply.

It works much better as you explained to me. Thank you for that. The only thing I noticed is that my graphs and values in the LCD gets slower once I connect the APP on my phone. I changed the reading frequency from 250ms to 1s and it is a bit better but the values do not change as fast as they should on the Blynk graphs. Do you know a way to read the values continuously without setting up a delay on Blynk app for each graph?

Another question, on my sketch I use the variables pow_fwd_max and pow_ref_max to register the max for a very little time like 25ms to display it on my lcd so the values can be read properly. Do you know how can I send these variables to Blynk to display them as in my LCD?

thanks.

I will look at your sketch shortly regarding your graphs etc but I don’t have any graphs myself. Blynk do have a virtual LCD which I do use.

So in your definitions you have WidgetLCD lcd(V0); if you pick V0.

Then in a function you have lcd.print(0, 0, String); but it must be a String not an integer. Let me know if you need code to convert from int to String and to ensure left or right alignment on the virtual LCD.

Can I use the Blynk.virtualWrite(31, pow_fwd_max); as in the code bellow? Because in the Blynk app I have a VALUE display for V31 and nothing happens.

Here is what I have and the code bellow:

  case 0: 
      
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      Calculation_SWR();   
      T_REFRESH1 = 45;   
      graph_W(T_REFRESH1);
      
      lcd.setCursor(0,1);
      lcd.print( "FWD");
      lcd.setCursor(8,1);
      lcd.print( "W");
      lcd.setCursor(0,3);
      lcd.print( "REF");
      lcd.setCursor(8,3);
      lcd.print( "W");
      if(pow_fwd == 0 || (pow_ref > pow_fwd ))
          {
          lcd.setCursor(13,2);
          lcd.print("swr");
          lcd.setCursor(12,3);
          lcd.print("-.--");
          }
      else{
          lcd.setCursor(13,2);
          lcd.print( "swr");
          lcd.setCursor(12,3);
          lcd.print(SWR);
          }

      lcd.setCursor(4,1);
      lcd.print("    ");
      lcd.setCursor(4,1);
      lcd.print(pow_fwd_max);

      
      Blynk.virtualWrite(31, pow_fwd_max);
 
      lcd.setCursor(4,3);
      lcd.print("   ");
      lcd.setCursor(4,3);
      lcd.print(pow_ref_max);

  break;

That should work fine yes. I assume it does display the correct value on your LCD?

Yes on my LCD everything works fine.

I now changed the code and I am trying to get info via V0 V1 and V2, none work:

  case 0: 
      
      Calculation_Power_dBm();
      Power_dBm=Power_dBm+Coupling_Coeff_HF;
      Conversion_dBm_to_W();
      Calculation_SWR();   
      T_REFRESH1 = 45;   
      graph_W(T_REFRESH1);
      
      lcd.setCursor(0,1);
      lcd.print( "FWD");
      lcd.setCursor(8,1);
      lcd.print( "W");
      lcd.setCursor(0,3);
      lcd.print( "REF");
      lcd.setCursor(8,3);
      lcd.print( "W");
      if(pow_fwd == 0 || (pow_ref > pow_fwd ))
          {
          lcd.setCursor(13,2);
          lcd.print("swr");
          lcd.setCursor(12,3);
          lcd.print("-.--");
          }
      else{
          lcd.setCursor(13,2);
          lcd.print( "swr");
          lcd.setCursor(12,3);
          lcd.print(SWR);
          
          Blynk.virtualWrite(2, SWR);
          }

      lcd.setCursor(4,1);
      lcd.print("    ");
      lcd.setCursor(4,1);
      lcd.print(pow_fwd_max);

      
      Blynk.virtualWrite(0, pow_fwd_max);
 
      lcd.setCursor(4,3);
      lcd.print("   ");
      lcd.setCursor(4,3);
      lcd.print(pow_ref_max);
      
      Blynk.virtualWrite(1, pow_ref_max);

btw these variables are declared as follows:

unsigned int   pow_fwd_max = 0;           // power forward max (for peak hold)
unsigned int   pow_ref_max = 0;           // power reflected max (for peak hold)
float SWR = 0;

I have no idea why it’s not working, it should by all means. There is one little difference with (working) code from me, I do it as follows:

Blynk.virtualWrite(V13, humid);
Blynk.virtualWrite(V14, temp);

Maybe add the "V"in front of it? It shouldn’t make any difference as far as I know though, but that is the only thing I can think off since your LCD works fine.

-edit-

You could try making a regular INT of it, but I doubt that’s it.

Surely an unsigned int is different to an int even though the former is a subset of the latter?

I think virtualWrite needs a regular int.

Ok, thanks I will try it but now I am getting this info on the serial monitor and nothing works:

AT+CIPCLOSE
AT+CIPSTART=“TCP”,“cloud.blynk.cc”,8442
AT+CIPCLOSE
AT+CIPSTART=“TCP”,“cloud.blynk.cc”,8442

Have you tried unplugging the Nano and plugging it back in again?

I think your ESP may have locked up (flooded). I use wdt on my Nano’s but you will need to load optiboot.

Weired because I did not do anything… I saw some messages of overflow before this happened. Now it does not work at all, I tried a different Arduino NANO and another ESP12 and I have the same problem!

Could it be that Blynk server blocked me for some overflow reason?

I get the same message:
[9] Blynk v0.3.1
[509] Connecting to Freebox-CQ…CQ…CQ
ATE0
[1520] Failed to disable Echo
AT+CIPCLOSE
AT+CIPSTART=“TCP”,“cloud.blynk.cc”,8442

Failed to disable echo sometimes means your Arduino nano can’t talk to the ESP. I had that once, it was a wire that was bad.

Have you tried using your ESP directly without an Arduino with a USB->serial adapter (something like this http://www.robotshop.com/ca/en/ft232rl-usb-serial-adapter.html )

That way you could manually try connecting to the blynk cloud to see if the ESP itself is the problem.

Ok so somehow it started working again… no idea what I did …

@Lichtsignaal I tried what you proposed using the V1 V2 and no, doesnt work. Also changed to INT and still the same.
I have a pushbutton on Blynk to turn on LED on pin 13 and it works perfectly, almost no latency going through the H+ network.

Ok, that is weird, but ok. I’d begin troubleshooting at a basic if I were you.

I’d upload a new sketch with only basic parameters, form an example upload and send a value to a vPin to see if that works. Something like:

void blabla()
{
  Blynk.virtualWrite(V1, analogRead(A0));
}

just to see if stuff works with all your factors accounted for, e.g. App version, cloud server etc. This will btw return a random number between 0 and 1023.

@Lichtsignaal it was a good idea to test as you said. So I tested the code bellow without any response in Blynk!!


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

// Set ESP8266 Serial object
#define EspSerial Serial

ESP8266 wifi(EspSerial);

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

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(9600);
  delay(10);

  Blynk.begin(auth, wifi, "Freebox-CQ..CQ..CQ", "xxxxx");
}
void blabla()
{
  Blynk.virtualWrite(1, 1);
}
void loop()
{
  Blynk.run();
}

I get this in the arduino debbug window:

Sketch uses 16,940 bytes (55%) of program storage space. Maximum is 30,720 bytes.
Global variables use 738 bytes (36%) of dynamic memory, leaving 1,310 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0

And I get this on the serial monitor:

[9] Blynk v0.3.1
[509] Connecting to Freebox-CQ…CQ…CQ
ATE0
AT+CWMODE?
AT+CWJAP=“Freebox-CQ…CQ…CQ”,“xxxxx”
AT+CIFSR
[7797] IP: +CIFSR:STAIP,“192.168.1.47”
+CIFSR:STAMAC,“18:fe:34:d7:58:f2”

OK
AT+CIPMUX=0
[7938] Connected to WiFi
AT+CIPCLOSE
AT+CIPSTART=“TCP”,“cloud.blynk.cc”,8442
AT+CIPSEND=37

any other ideas??

You have to set a timer to fire off the void blabla() every so-and-so seconds, otherwise nothing will happen at all.

-edit-

The not-in-sync message is usually something about your hardware or USB not good. Have you tried rebooting? I’ve blown up my USB ports on my Mac and need to reboot often for them to keep functioning, really annoying…

I read somewhere that due to the fact that we have something connected to PIN0 it may give us this message.

Oh here is the link : http://www.instructables.com/id/A-solution-to-avrdude-stk500getsync-not-in-syn/

I will try yo setup a timer and test it again. The weiredest is that The gauge graphics in Blynk work ok, they get the values in A0 and A1 also the LED configured on pin13 but not the virtual write…

Hmm, that is indeed silly. I’d love to hear if that Pin0 thing does something for you. I’m running out of ideas really fast right now, sorry :frowning: