BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Hc-05 + Blink (Multiple Problems)

I am currently trying to control 3 servo’s which have different functions. So, currently im trying to read joystick values, but multiple problems arise.

  1. Random And Frequent Login Timeouts
  2. Package Too Big
    Although increasing write interval of hc 05 alleviates the problem a little bit. And the frequency of login timeout’s decreases.
    And yes i have also removing redundancy of (including and creating its instance 2 times) software serial library and nothing changes.
    Board Used: Arduino Uno + Hc-05
    Android Version: 8.0.0
    EMUI Version: 8.0.0
/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  Note: This only works on Android!
        iOS does not support Bluetooth 2.0 Serial Port Profile
        You may need to pair the module with your smartphone
        via Bluetooth settings. Default pairing password is 1234

  Feel free to apply it to any other example. It's simple!

  NOTE: Bluetooth support is in beta!

  You can receive x and y coords for joystick movement within App.

  App project setup:
    Two Axis Joystick on V1 in MERGE output mode.
    MERGE mode means device will receive both x and y within 1 message
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(5,6); // RX, TX
    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

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

SoftwareSerial SerialBLE(5,6); // RX, TX
#include <Servo.h>

Servo myservoKICKER;
Servo myservoLEFTWHEEL;
Servo myservoRIGHTWHEEL;
int pos;
BLYNK_WRITE(V1) {
  int xAxis =param[0].asInt();
  int yAxis= param[1].asInt();
  
  Serial.print("X = ");
  Serial.print(xAxis);
  Serial.print("Y = ");
  Serial.println(yAxis);
  if (xAxis > 400 && xAxis < 600 && yAxis > 400 && yAxis < 600)
      {
          myservoLEFTWHEEL.detach();
          myservoRIGHTWHEEL.detach();
          myservoKICKER.detach();
      }

      // FORWARDS FAST
      if (xAxis > 400 && xAxis < 600 && yAxis > 1018 && yAxis <= 1023)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (180);
          myservoRIGHTWHEEL.write (0);
      }

      // BACKWARDS FAST
      if (xAxis > 400 && xAxis < 600 && yAxis >= 0 && yAxis < 5)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (0);
          myservoRIGHTWHEEL.write (180);
      }

      // LEFT FAST
      if (xAxis >= 0 && xAxis < 5 && yAxis > 400 && yAxis < 600)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (0);
          myservoRIGHTWHEEL.write (0);
      }

      // RIGHT FAST
      if (xAxis > 1018 && xAxis <= 1023 && yAxis > 400 && yAxis < 600)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (180);
          myservoRIGHTWHEEL.write (180);
      }

      // FORWARDS MEDIUM
      if (xAxis > 400 && xAxis < 600 && yAxis > 750 && yAxis < 1018)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (110);
          myservoRIGHTWHEEL.write (70);
      }

      // BACKWARDS MEDIUM
      if (xAxis > 400 && xAxis < 600 && yAxis > 5 && yAxis < 250)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (70);
          myservoRIGHTWHEEL.write (110);
      }

      // LEFT MEDIUM
      if (xAxis > 5 && xAxis < 250 && yAxis > 400 && yAxis < 600)
      {
          myservoRIGHTWHEEL.attach(10);
  
          myservoRIGHTWHEEL.write (70);
      }

      // RIGHT MEDIUM
      if (xAxis > 750 && xAxis < 1018 && yAxis > 400 && yAxis < 600)
      {
          myservoLEFTWHEEL.attach(9);
  
          myservoLEFTWHEEL.write (110);
      }

      // FORWARDS SLOW
      if (xAxis > 400 && xAxis < 600 && yAxis > 600 && yAxis < 750)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (100);
          myservoRIGHTWHEEL.write (80);
      }

      // BACKWARDS SLOW
      if (xAxis > 400 && xAxis < 600 && yAxis > 250 && yAxis < 400)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (80);
          myservoRIGHTWHEEL.write (100);
      }

      // LEFT SLOW
      if (xAxis > 250 && xAxis < 400 && yAxis > 400 && yAxis < 600)
      {
          myservoRIGHTWHEEL.attach(9);
  
          myservoRIGHTWHEEL.write (80);
      }

      // RIGHT SLOW
      if (xAxis > 600 && xAxis < 750 && yAxis > 400 && yAxis < 600)
      {
          myservoLEFTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (100);
      }      

      //  FORWARDS LEFT FAST
      if (xAxis >= 0 && xAxis < 5 && yAxis > 1018 && yAxis <= 1023)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (115);
          myservoRIGHTWHEEL.write (0);
      }

      // FORWARDS RIGHT FAST
      if (xAxis > 1018 && xAxis <= 1023 && yAxis > 1018 && yAxis <= 1023)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (180);
          myservoRIGHTWHEEL.write (65);
      }

      // BACKWARDS LEFT FAST
      if (xAxis >= 0 && xAxis < 5 && yAxis >= 0 && yAxis < 5)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (65);
          myservoRIGHTWHEEL.write (180);
      }

      // BACKWARDS RIGHT FAST
      if (xAxis > 1018 && xAxis <= 1023 && yAxis >= 0 && yAxis < 5)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (0);
          myservoRIGHTWHEEL.write (115);
      }

      //  FORWARDS LEFT MEDIUM
      if (xAxis > 5 && xAxis < 400 && yAxis > 600 && yAxis < 1018)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (105);
          myservoRIGHTWHEEL.write (0);
      }

      // FORWARDS RIGHT MEDIUM
      if (xAxis > 600 && xAxis < 1018 && yAxis > 600 && yAxis < 1018)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (180);
          myservoRIGHTWHEEL.write (75);
      }

      // BACKWARDS LEFT MEDIUM
      if (xAxis > 5 && xAxis < 400 && yAxis > 5 && yAxis < 400)
      {
           myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (75);
          myservoRIGHTWHEEL.write (180);
      }

      // BACKWARDS RIGHT MEDIUM
      if (xAxis > 600 && xAxis < 1018 && yAxis > 5 && yAxis < 400)
      {
          myservoLEFTWHEEL.attach(9);
          myservoRIGHTWHEEL.attach(10);
  
          myservoLEFTWHEEL.write (0);
          myservoRIGHTWHEEL.write (105);
      }
}
BLYNK_WRITE(V2){ // Fast Kicker Pin
  int FastKick= param.asInt();
  Serial.print(FastKick);
  if(FastKick == 1)
      {
          myservoKICKER.attach(11);
          delay(100);
          myservoKICKER.write (90);
          delay(200);
          myservoKICKER.write (160);
          delay(200);
          myservoKICKER.detach();
      }      

}
BLYNK_WRITE(V3){ //Slow Kicker Pin
  int SlowKick=param.asInt();
  if(SlowKick == 1)
      {
          myservoKICKER.attach(11);
          delay(100);

          for (pos = 160; pos >= 90; pos -= 1) 
          {     
              myservoKICKER.write (pos);            
              delay(5);                      
          }

          myservoKICKER.write (160);
          delay(200);
          myservoKICKER.detach();
      }   
}
BLYNK_WRITE(V4){ //WHEEL CALIBRATION
  int WheelCalibration=param.asInt();
  if(WheelCalibration == 1)
      {
          myservoLEFTWHEEL.attach(2);
          myservoRIGHTWHEEL.attach(3);
          delay(100);          
          myservoLEFTWHEEL.write (90);
          myservoRIGHTWHEEL.write (90);
          delay(30000);
          
      }   
}
BLYNK_WRITE(V5){ //KICKER 90 DEGREE CALIBRATION
  int KickerCalibration= param.asInt();
  if(KickerCalibration == 1)
      {
          myservoKICKER.attach(11);
          delay(100);
          myservoKICKER.write (90);
          delay(200);
          myservoKICKER.detach();
      }   
}


void setup()
{
  // put your setup code here, to run once:
  myservoLEFTWHEEL.attach(9);   //1
  myservoRIGHTWHEEL.attach(10);  //2
  myservoKICKER.attach(11);   //3
  
  // detach servos to avoid jitter on power up
  myservoLEFTWHEEL.detach();
  myservoRIGHTWHEEL.detach();
  myservoKICKER.detach();
  
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");
}

void loop()
{
  Blynk.run();
}


This is how the errors are shown
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.6.1 on Arduino Uno

[89] Connecting…
[3229] Login timeout
[5229] Connecting…
[8349] Login timeout
[10349] Connecting…
[13469] Login timeout
[15469] Connecting…
[20589] Connecting…
X = 519Y = 517
X = 512Y = 512
X = 519Y = 516
X = 40Y = 0
[21199] Packet too big: 14647
[25709] Connecting…
[25950] Packet too big: 12544
[30829] Connecting…
[35949] Connecting…
X = 688Y = 1011
[36072] Ready (ping: 1ms).
X = 395Y = 1023
X = 98Y = 668
[36355] Invalid HW cmd: v
Waiting for connections…
[44408] Connecting…
[47528] Login timeout
[49528] Connecting…
[52648] Login timeout
[54648] Connecting…
[57768] Login timeout
[59768] Connecting…
[62888] Login timeout
[64888] Connecting…
[68008] Login timeout
[70008] Connecting…
[73128] Login timeout
[75128] Connecting…
[78248] Login timeout
[80248] Connecting…
[83368] Login timeout
[85368] Connecting…
[88488] Login timeout
[90488] Connecting…
[93608] Login timeout
[95608] Connecting…
[98728] Login timeout
[100728] Connecting…
[103848] Login timeout
[105848] Connecting…
[108968] Login timeout
[110968] Connecting…
X = 508Y = 519
X = 0Y = 532
X = 91Y = 835
[114089] Login timeout
[116089] Connecting…
X = 512Y = 512
X = 1006Y = 528
X = 385Y = 0
X = 512Y = 0
[116358] Packet too big: 2304
[121210] Connecting…
[124331] Login timeout
[126331] Connecting…

I have just realised, the login timeout and other problems are due to huge number of commands added in BLYNK_WRITE(V1).
Is there anyway i can do the comparisons outside the scope?