1

So I am making a football playing robot which consists of 3 servo motors. Currently,i am only checking only a single servo(myservoKicker)which is operated via button in the blynk app and trying to read x and y values from joysticks in blynk. I am using wifi communication. I have seen that wifi.begin never properly starts as the serial.print("Blynk Connected") after it does not run, plus on my blynk app the project constantly connects and disconnects. Note: The code for steering other servo's is not implemented yet and is just a stub. Board: DoIt ESP32 Devkit V1 30 GPIO Blynk: 0.6.1 myservoKicker connected to pin 13

#include <ESP32Servo.h>
#include <SPI.h>
#include <Ethernet.h>
#include <ETH.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiScan.h>
#include <WiFiServer.h>
#include <WiFiSTA.h>
#include <WiFiType.h>
#include <WiFiUdp.h>
#include <BlynkSimpleEsp32.h>

Servo myservoKICKER;
Servo myservoLEFTWHEEL;
Servo myservoRIGHTWHEEL;
int pos;

char auth[] = "9Itekdu3vf_B_3YmNxxHu9G3Bs_1IWs9";
char ssid[] = "RO IMRAN RO";
char pass[] = "xxxxxxxxxxx";
char localserver[16]= "192.168.1.1";
BLYNK_WRITE(V1) 
{
    int xAxis = param[0].asInt();
    int yAxis = param[1].asInt();

    // Do something with x and y
    Serial.print("X = ");
    Serial.print(xAxis);
    Serial.print("; Y = ");
    Serial.println(yAxis);


}
BLYNK_WRITE(V4){                                        //WHEEL CALIBRATION
    int WheelCalibration=param.asInt();
    if(WheelCalibration == 1)
    {
        myservoLEFTWHEEL.attach(26);
        myservoRIGHTWHEEL.attach(27);
        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(13);
        delay(100);
        myservoKICKER.write (90);
        delay(200);

    }   
}


void setup(){
    // Attach servos to pins               
    myservoLEFTWHEEL.attach(26);                        //1
    myservoRIGHTWHEEL.attach(27);                       //2
    myservoKICKER.attach(13);                           //3


    // detach servos to avoid jitter on power up
    myservoLEFTWHEEL.detach();
    myservoRIGHTWHEEL.detach();
    myservoKICKER.detach();

    Serial.begin(115200);
    delay(10);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid,pass);
    int wifi_ctr = 0;
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("WiFi connected"); 
    Blynk.begin("9Itekdu3vf_B_3YmNxxHu9G3Bs_1IWs9",ssid,pass);
    Serial.println("Blynk connected"); 
}

void loop()
{
    Blynk.run();
}
gbg
  • 528
  • 3
  • 11
  • 1st - try to set option EraseFlash -> Sketch+WiFi Settings 2nd - try to set WiFi.hostname() before WiFi.begin() – gbg Feb 12 '20 at 13:36
  • the Blynk.begin does WiFi.begin. so remove your WiFi.begin – Juraj Feb 12 '20 at 14:53
  • Your code is not indented properly, which makes it confusing and hard to follow. – StarCat Feb 12 '20 at 15:01
  • just focus on this bit of code: – Informal Limits Lad Feb 12 '20 at 17:19
  • Serial.begin(115200); delay(10); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid,pass); int wifi_ctr = 0; while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected"); Blynk.begin("9Itekdu3vf_B_3YmNxxHu9G3Bs_1IWs9",ssid,pass); Serial.println("Blynk connected"); } – Informal Limits Lad Feb 12 '20 at 17:19
  • Did you erase "Sketch+WiFi Settings"? Did you call WiFi.hostname(...);? – gbg Feb 12 '20 at 18:39
  • @gbg, how is it relevant? if the wifi settings are deleted they will be stored again, since the sketch passes the ssid and password. and what with hostname? Blynk doesn't care about hostname – Juraj Feb 14 '20 at 17:04
  • @Juraj WiFI.hostname() - sets hostname for DHCP query. My WiFi router does not answer on DHCP query without the hostname set, so, the ESP does'n connect to the WiFi. – gbg Feb 14 '20 at 20:06
  • @gbg, hostname is always set somehow – Juraj Feb 14 '20 at 20:09
  • 1
    @Juraj, IDK, in my case, without this line, connection fails – gbg Feb 14 '20 at 20:13

0 Answers0