Blynk gets stuck on Ready/Ping When I use with other Librarys

Hello, I have issues connecting when I include other librarys and use them.
I’m using a Arduino UNO with ESP8266 Shield. When I un-comment:
I’ll place the full code at the bottom.

DistanceMeter USSF(trigPinF, echoPinF);
DistanceMeter USSB(trigPinB, echoPinB);

LiquidCrystal_I2C lcd(0x27, 16, 2);

Blynk stops working as in it get stuck on Ready (Ping: 23ms) and does it over and over again.
The other tabs are blank, I’ve moved most the code over to the first tab and commented out the rest

But if I comment the those, the connection works and prints Done! into the serial.
[Turns out I can only put one image.]

14:58:03.328 -> [99] 
14:58:03.328 ->     ___  __          __
14:58:03.328 ->    / _ )/ /_ _____  / /__
14:58:03.328 ->   / _  / / // / _ \/  '_/
14:58:03.328 ->  /____/_/\_, /_//_/_/\_\
14:58:03.328 ->         /___/ v1.1.0 on Arduino Uno
14:58:03.328 -> 
14:58:03.328 ->  #StandWithUkraine    https://bit.ly/swua
14:58:03.372 -> 
14:58:03.372 -> 
14:58:03.854 -> [611] Connecting to TessWifi
14:58:07.080 -> [3826] AT version:1.7.5.0(Oct  9 2021 09:26:04)
14:58:07.080 -> SDK version:3.0.5(b29dcd3)
14:58:07.080 -> compile time:Oct 15 2021 18:05:30
14:58:07.080 -> Bin version(Wroom 02):1.7.5
14:58:07.080 -> OK
14:58:15.338 -> [12036] +CIFSR:STAIP,"192.168.89.17"
14:58:15.338 -> +CIFSR:STAMAC,"68:c6:3a:a5:51:b3"
14:58:15.338 -> [12037] Connected to WiFi
14:58:25.775 -> [22438] Ready (ping: 26ms).
14:58:26.444 -> Done!

And here’s the full code…


//LCD
#include <avr/interrupt.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//Ultrasonic Easyuino API
#include <Easyuino.h>
using Easyuino::DistanceMeter;


//Defines and Pins
//====================
//Motor
#define motor1F 9
#define motor1B 6
#define motor2F 5
#define motor2B 3

//UltraSS
#define trigPinF 11
#define echoPinF 10
#define trigPinB 8
#define echoPinB 7
DistanceMeter USSF(trigPinF, echoPinF);
DistanceMeter USSB(trigPinB, echoPinB);

//LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
// addr,en,rw,rs,d4,d5,d6,d7,bl,blpol
// addr can be 0x3F or 0x27

#define breaksecs 30  //break out
//====================


//Start of Blynk Code
//====================
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "[Removed]"
#define BLYNK_DEVICE_NAME "[Removed]"
#define BLYNK_AUTH_TOKEN "[Removed]"

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TessWifi";
char pass[] = "[Removed]";

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(12, 13);  // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

BlynkTimer timer;

int Trigger = 0;
BLYNK_WRITE(V0) {
  Trigger = param.asInt();  // assigning incoming value from pin V0 to a variable
}
int X = 0;
BLYNK_WRITE(V8) {
  X = param.asInt();
}
int Y = 0;
BLYNK_WRITE(V9) {
  Y = param.asInt();
}
int RunitsF = 0;
BLYNK_WRITE(V10) {
  RunitsF = param.asInt();
}

void myTimerEvent() {
  //Serial.println("Test");
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
  //Blynk.syncVirtual(V0);
  //MDrive(1);
  //MRUnit();
}
//End of Blynk Code
//====================

void setup() {


  //Start of Blynk Setup
  //====================
  // Debug console
  Serial.begin(115200);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(100);
  /*
  Serial.println("Connect to Wifi");
  Blynk.connectWiFi(ssid, pass);
  Serial.println("Connected o Wifi");
  Blynk.config(auth, "blynk.cloud", 80);
  Serial.println("Start Server Connection");
  Blynk.connect();
  Serial.println("Connected?");*/

  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
  //Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
  timer.setInterval(250L, myTimerEvent);
  Serial.println("Done!");
  //====================
  //End of Blynk Setup

/*
  //LCD
  //====================
  lcd.init();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.begin(16, 2);  // 16 characters, 2 lines
  lcd.backlight();   // turn backlight on
  lcd.setBacklight(100);
  lcd.print("Ready");
  //====================


  //Motors
  //====================
  pinMode(motor1F, OUTPUT);
  pinMode(motor2B, OUTPUT);
  pinMode(motor1F, OUTPUT);
  pinMode(motor2B, OUTPUT);
  //====================

  //USensor
  //====================
  USSF.begin();
  USSB.begin();
  //====================
  MBrake();*/
}

void loop() {
  //Blynk!
  //====================
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!

  timer.run();
  //====================
  //End of Blynk
  //MUnit(0,0,0);
}

Any fixes?

These should always be the first three lines of your sketch, at least with the Blynk library version you are using, followed by your Blynk library includes.

How are you powering your motors?

BTW, when you post serial output please copy/paste the text and use triple backticks, rather than posting screenshots.

Pete.

1 Like

I moved them up nothing has changed

A motor driver board with external batteries. It uses pwm for control.

It’s happening again this time by
WidgetTerminal terminal();
When I enable and use it gets stuck in ping/ready. The serial monitor is the same as the first post.

Here’s the updated code with terminal enabled:

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""

/*
//LCD
//#include <avr/interrupt.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//Ultrasonic Easyuino API
#include <Easyuino.h>
using Easyuino::DistanceMeter;
*/

//Defines and Pins
//====================================================================================================
//Motor
#define motor1F 9
#define motor1B 6
#define motor2F 5
#define motor2B 3

//UltraSS
#define trigPinF 11
#define echoPinF 10
#define trigPinB 8
#define echoPinB 7
//DistanceMeter USSF(trigPinF, echoPinF);
//DistanceMeter USSB(trigPinB, echoPinB);

//LCD
//LiquidCrystal_I2C lcd(0x27, 16, 2);
// addr,en,rw,rs,d4,d5,d6,d7,bl,blpol
// addr can be 0x3F or 0x27

#define breaksecs 15  //break out
//====================================================================================================



//GValues
//====================================================================================================
boolean StartStop = false;
boolean BoxLoad = false;
int BHZz = 1000;
//====================================================================================================



//Start of Blynk Code
//====================================================================================================
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings


#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// Your WiFi credentials.
// Set password to "" for open networks.

char ssid[] = "";
char pass[] = "";
/*
char ssid[] = "(2.4G)";
char pass[] = "";
*/

// or Software Serial on Uno, Nano...
#define NEOSWSERIAL_EXTERNAL_PCINT
#include <NeoSWSerial.h>
NeoSWSerial EspSerial(12, 13);  // RX, TX
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(12, 13);  // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

WidgetTerminal terminal(V15);
BlynkTimer timer;

int Rsteer = 0;
BLYNK_WRITE(V3) {
  Rsteer = param.asInt();  // assigning incoming value from pin V0 to a variable
}
int Speed = 0;
BLYNK_WRITE(V2) {
  Speed = param.asInt();  // assigning incoming value from pin V0 to a variable
}
int Trigger = 0;
BLYNK_WRITE(V0) {
  Trigger = param.asInt();  // assigning incoming value from pin V0 to a variable
}
int X = 0;
BLYNK_WRITE(V8) {
  X = param.asInt();
}
int Y = 0;
BLYNK_WRITE(V9) {
  Y = param.asInt();
}
int RunitsF = 0;
BLYNK_WRITE(V10) {
  RunitsF = param.asInt();
}
BLYNK_WRITE(V15) {
  String TempStringTerm = param.asString();
  if (String("Stop") == param.asStr()) {
    StartStop = false;
    terminal.println("Stopping");
  } else if (String("Start") == param.asStr()) {
    StartStop = true;
    terminal.println("Starting");
  } else if (String("Full") == param.asStr()) {
    BoxLoad = true;
    terminal.println("Set to Full");
  } else if (String("Empty") == param.asStr()) {
    BoxLoad = false;
    terminal.println("Set to Empty");
  } else if (TempStringTerm.indexOf("Hz Set") != -1){
    TempStringTerm.remove(0,6);
    BHZz = TempStringTerm.toInt();
  }
}


//End of Blynk Code
//================================================================================



void setup() {
  /*
  PCICR |= B00000100;   //Turn on ISR for PD
  PCMSK1 |= B00000000;  //ISR PC for Pin A0 and A1 [No in use at the moment]
  PCMSK2 |= B00010100;  //ISR PD for Pin D2 and D4
  pinMode(2, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
 */

  //Start of Blynk Setup
  //================================================================================
  // Debug console
  Serial.begin(115200);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(500);
  //Blynk.config(BLYNK_AUTH_TOKEN, "blynk.cloud", 80);
  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
  //Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
  timer.setInterval(1000L, myTimerEvent);
  Serial.println("Done!");
  //================================================================================
  //End of Blynk Setup


  //Motors
  //================================================================================
  pinMode(motor1F, OUTPUT);
  pinMode(motor2B, OUTPUT);
  pinMode(motor1F, OUTPUT);
  pinMode(motor2B, OUTPUT);
  //================================================================================


  /*
  //LCD
  //================================================================================
  lcd.init();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.begin(16, 2);  // 16 characters, 2 lines
  lcd.backlight();   // turn backlight on
  lcd.setBacklight(100);
  lcd.print("Ready");
  //================================================================================
  

  //USensor
  //================================================================================
  USSF.begin();
  USSB.begin();
  //================================================================================
  */

  MBrake();
}

void myTimerEvent() {
  //Serial.println("Test");
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
  if (BoxLoad) {
    tone(A2, BHZz);
  } else {
    noTone(A2);
  }
  if (StartStop) {
    //Serial.println("StartStop");
    Blynk.syncVirtual(V0, V2);
    //MDrive(1);
    MRUnit();
  }
}

void loop() {
  
  //Blynk!
  //================================================================================
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
  HitCheck();
  timer.run();
  //================================================================================
  //End of Blynk
  //MUnit(0,0,0);
  
}

void MBrake() {
  digitalWrite(motor1F, 0);
  digitalWrite(motor1B, 0);
  digitalWrite(motor2F, 0);
  digitalWrite(motor2B, 0);
}

void MUnit(int units, int throttle, int Steering) {
  //terminal.println("Moving");
  int countF = 0;
  int countR = 0;
  int pasF = digitalRead(A0);
  int pasR = digitalRead(A1);
  MDrive(0, 255 * constrain(throttle, -1, 1), Steering);  // Jump Start Motors
  delay(50);                                              // Jump Starting
  MDrive(0, throttle, Steering);                          // Set to main speed
  if (abs(Steering) == 255)                               // steering only
  {
    while (countF <= units && countR <= units) {
      switch (millis() / 1000) {
        case breaksecs:  //If code Runs for x number of seconds Break
          units = 0;
          break;
        default:
          if (pasR == digitalRead(A1)) {
            pasR = digitalRead(A1);
          } else {
            pasR = digitalRead(A1);
            countR++;
          }
          if (pasF == digitalRead(A0)) {
            pasF = digitalRead(A0);
          } else {
            pasF = digitalRead(A0);
            countF++;
          }
      }
    }
  } else  // Forward and backward with some steering
  {
    while (countF <= units || countR <= units) {
      switch (millis() / 1000) {
        case breaksecs:  //If code Runs for x number of seconds Break
          units = 0;
          break;
        default:
          if ((millis() / 1000) % 2) {
            switch (constrain(throttle, -1, 1))  //Wall detection
            {
              case -1:
                if (RangeB() <= 10) {
                  //terminal.println("Wall Detected Stopping");
                  MBrake();
                  units = 0;
                } else if (RangeB() <= 50) {
                  //terminal.println("Slowing down");
                  MDrive(0, -60, Steering);
                }
                break;
              case 1:
                if (RangeF() <= 10) {
                  //terminal.println("Wall Detected Stopping");
                  MBrake();
                  units = 0;
                } else if (RangeF() <= 50) {
                  //terminal.println("Slowing Down");
                  MDrive(0, 60, Steering);
                }
                break;
              default:
                break;
            }
          }
          if (pasR == digitalRead(A1)) {
            pasR = digitalRead(A1);
          } else {
            pasR = digitalRead(A1);
            countR++;
          }
          if (pasF == digitalRead(A0)) {
            pasF = digitalRead(A0);
          } else {
            pasF = digitalRead(A0);
            countF++;
          }
      }
      if (countF >= units) {
        digitalWrite(motor1F, 0);
        digitalWrite(motor1B, 0);
      }
      if (countR >= units) {
        digitalWrite(motor2F, 0);
        digitalWrite(motor2B, 0);
      }
    }
  }
  MBrake();
}

void MRUnit() {
  switch (Trigger) {
    case false:
      break;
    case true:
      Serial.println("Starting Motor");
      Blynk.syncVirtual(V10);
      MUnit(RunitsF, Speed, Rsteer);
    default:
      break;
  }
}

void MDrive(boolean Debug, int j, int k) {
  switch (Debug) {
    case 1:
      Blynk.syncVirtual(V8, V9);  //Debug remote drive //Very laggy
      j = Y;
      k = X;
    default:
      int A = 0, B = 0, C = 0, D = 0;

      if (j == 0) {
        A = 0, B = 0, C = 0, D = 0;
      } else {

        //Forward Backwards
        A = constrain(j, 0, 255);
        C = constrain(j, 0, 255);
        B = abs(constrain(j, -255, 0));
        D = abs(constrain(j, -255, 0));

        //Steering
        A = A - (abs(constrain(k, -255, 0)) * constrain(A, 0, 1));
        C = C - (abs(constrain(k, 0, 255)) * constrain(C, 0, 1));
        B = B - (abs(constrain(k, -255, 0)) * constrain(B, 0, 1));
        D = D - (abs(constrain(k, 0, 255)) * constrain(D, 0, 1));
      }
      analogWrite(motor1F, A);
      analogWrite(motor1B, B);
      analogWrite(motor2F, C);
      analogWrite(motor2B, D);
      break;
  }
}

void HitCheck() {
  if (pulseIn(2, LOW)) {
    switch (StartStop) {
      case true:
        StartStop = false;
        //terminal.println("Falsed");
        break;
      case false:
        StartStop = true;
        //terminal.println("Trued");
        break;
    }
  } else if (pulseIn(4, LOW)) {
    switch (BoxLoad) {
      case true:
        BoxLoad = false;
        //terminal.println("Tone");
        break;
      case false:
        BoxLoad = true;
        //terminal.println("NoTone");
        break;
    }
  }
}

int RangeB() {
  long pulseDuration;  //variable needed by the ultrasound sensor code
  int Distance;        // Ultrasound distance in cm

  // this main code runs repeatedly:
  // 1. Produce a 15us (micro-second) HIGH pulse in Trig to trigger the sensor...
  digitalWrite(trigPinF, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPinF, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPinF, LOW);

  // 2. Use pulseIn() function to measure the duration of the HIGH pulse in Echo
  // every 58 us is an obstacle distance of 1 cm

  pulseDuration = pulseIn(echoPinF, HIGH);
  Distance = pulseDuration / 58;
  return Distance;
}

int RangeF() {
  long pulseDuration;  //variable needed by the ultrasound sensor code
  int Distance;        // Ultrasound distance in cm

  // this main code runs repeatedly:
  // 1. Produce a 15us (micro-second) HIGH pulse in Trig to trigger the sensor...
  digitalWrite(trigPinB, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPinB, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPinB, LOW);

  // 2. Use pulseIn() function to measure the duration of the HIGH pulse in Echo
  // every 58 us is an obstacle distance of 1 cm

  pulseDuration = pulseIn(echoPinB, HIGH);
  Distance = pulseDuration / 58;
  return Distance;
}

WidgetTerminal terminal(vPin) is the old way of doing this. You’d be better just doing virtual writes to the vPin instead.

Pete.

1 Like

I am going to to do that since the terminal doesn’t work anyways.

But I’m still not sure why blynk.begin() would get stuck when using terminal or other librarys like LiquidCrystal_I2C or Easyuino.

Is there a why to manually connect to the network without using blynk.begin()?
The only manually connection option is only when code to the ESP itself…

I have no idea. I’m not familiar with these libraries and the Uno.
TBH, the Uno + ESP-01 would be my last choice of hardware to use with an IoT product like Blynk.

Yes, you can manually establish the network connection then use Blynk.config and Blynk.connect, but this isn’t really an option with your choice of hardware.

Pete.

1 Like

Noted.

My project is done now, thanks for the help.

Dave did you manage to figure this out ? Started to happen to me but only when I tried to add a display ?