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.
- Random And Frequent Login Timeouts
- 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();
}