Blynk app only sends for a second

Hi,
I tried differend things, button, joystick, reading writing… and i have the issue that the app only sends data for a second and than stops until a new command is given.
example: i try to read the joystick reading in the serial monitor and when i hold the joystick up i see like 5 to 10 values in the serial monitor and then it stops while still holding the stick up. Then if i release the joystick and start again i get only about that amount of readings. It keeps reading if i constantly change the values but not if i keep it on the same place.
Any solutions?

That’s how the Joystick widget works. It sends new x,y coordinates when the position changes.
There is really no need for it to work any other way, as you can do the rest in code.

The Button widget works in a similar way - by default it send a 1 when the button is pressed and a 0 when it is released. In Switch mode it will send a 1 when activated and a 0 when deactivated.

Pete.

i also had the same problem with the on and off switch, not button, my motors turned for a second or so and then stopped. I could ‘reset’ it by puttong it on off again and then on.

I’m not familiar with that widget.

I think your issue is your code.

Pete.

i mean button, but what if i want to use the joystick to steer a car but if the values dont change the car will stop driving?

Not if you write your code correctly. The value from the joystick should be stored in a variable and sent to the controller as needed.

Pete.

But that has to be in the loop then, and ive heard that blynk people dont like code in the loop?

No, if you need something to repeat then you can use a timer.

A lot depends on the hardware you are using and the libraries you are using to control that hardware.
As you’ve not shared any information on those things you’re unable to get any significant pointers from the forum members.

Maybe you should try searching the forum for other people that are using the same hardware and libraries?

Pete.

Hi part of my project is a line follower, this code is the control with a joystick, which works fine, and tuning the PID parameters while it is driving. I only want to make it to follow a line when a virtual button is switched on, yes it is on switch not hold, because of the size of the car. The problem is that it oly moves for a fraction of a second when it turn the button on. Does anyone know why?

Alse when i toggle the button my project disconect and reconnects again realy fast, this happens everythime.

It is a nodemcu that gets enough current sot that is not the problem.

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "4ccb3ce22f794f34a9dfb44208843a20"; 
char ssid[] = "telenet-apn-497da";      
char pass[] = "bscso5zxhoeg"; 
int sensor[5]; //maak een array met 5 variabelen 
int gewenste_snelheid; 
int PWM_links = D3; // pwm h-brug links 
int PWM_rechts = D4; //pwm h-brug rechts 

int snelheid_links; // snelheid linker motor 
int snelheid_rechts;// snelheid rechter motor 

int DIR_links = D0; //direction pin h-brug links 
int DIR_rechts = D8;//direction pin h-brug rechts

void lees_sensorwaarden(void); 
void bereken_PID(void);
void motor_control(void); 

double x, y, abswx, abswy;


double Kp, Ki, Kd;
double Setpoint, Input, PID_waarde; 
int error; 
PID myPID(&Input, &PID_waarde, &Setpoint, Kp, Ki, Kd, DIRECT); 

int startknop;
void rechtdoor(){
  digitalWrite(DIR_links, LOW);
  digitalWrite(DIR_rechts, LOW);
}
void achteruit(){
  digitalWrite(DIR_links, HIGH);
  digitalWrite(DIR_rechts, HIGH);
}
void rechts(){
  digitalWrite(DIR_links, HIGH);
  digitalWrite(DIR_rechts, LOW);
}
void links(){
  digitalWrite(DIR_links, LOW);
  digitalWrite(DIR_rechts, HIGH);
}
BLYNK_WRITE(V0) //Geeft Kp, Ki, Kd, de waarden die in de Blynk app ingevoerd worden
{ 
 Kp = param.asInt(); 
} 
BLYNK_WRITE(V1) 
{ 
 Ki = param.asInt(); 
} 
BLYNK_WRITE(V2) 
{ 
 Kd = param.asInt(); 
} 
BLYNK_WRITE(V3)
{
  startknop = param.asInt();

  
}
BLYNK_WRITE(V6) {
   x = param[0].asInt();
   y = param[1].asInt();
abswx = abs(x);
abswy = abs(y);

if(x<300 && x>-300 && y>0){ //rechtdoor
  rechtdoor();
  analogWrite(PWM_links, y);
  analogWrite(PWM_rechts, y);
  Serial.println("rechtdoor");
  }
else if(x<300 && x>-300 && y<0){//achteruit
  achteruit();
  analogWrite(PWM_links, abswy);
  analogWrite(PWM_rechts, abswy);
  Serial.println("achteruit");
  }
else if(y<300 && y>-300 && x>0){//rechts
  rechts();
  analogWrite(PWM_links, x);
  analogWrite(PWM_rechts, x  );
  Serial.println("rechts");
  }

else if(y<300 && y>-300 && x<0){//links
  links();
  analogWrite(PWM_links, abswx);
  analogWrite(PWM_rechts, abswx);
 Serial.println("links");
  }  
  else{
    analogWrite(PWM_links, 0);
    analogWrite(PWM_rechts, 0);
  }
}
BLYNK_WRITE(V8)
{
  gewenste_snelheid = param.asInt();
}
void setup() { 



pinMode(D1, INPUT); 
pinMode(D2, INPUT); 
pinMode(D5, INPUT); 
pinMode(D6, INPUT); 
pinMode(D7, INPUT); 

pinMode(PWM_links, OUTPUT); //PWM Pin Links 
pinMode(PWM_rechts, OUTPUT); //PWM Pin Rechts 
pinMode(DIR_links, OUTPUT); //DIR Links 
pinMode(DIR_rechts, OUTPUT); //DIR rechts 
Input = error; 
Setpoint = 0; 
myPID.SetMode(AUTOMATIC); //PID regelaar aanzetten

// Debug console 
Serial.begin(9600); 
Blynk.begin(auth, ssid, pass); //verbind met de Blynk server via internet 
} 

void loop(){ 
Blynk.run();

if(startknop==HIGH){

    lees_sensorwaarden(); 
    bereken_PID(); 
    motor_control();
  }

}


 
void lees_sensorwaarden() 
{ 
sensor[1] = digitalRead(D1); 
sensor[2] = digitalRead(D2); 
sensor[3] = digitalRead(D5); 
sensor[4] = digitalRead(D6);
sensor[5] = digitalRead(D7); 

  if ((sensor[1] == 1) && (sensor[2] == 1) && (sensor[3] == 1) && (sensor[4] == 1) && (sensor[5] == 0))
    error = 4;
  else if ((sensor[1] == 1) && (sensor[2] == 1) && (sensor[3] == 1) && (sensor[4] == 0) && (sensor[5] == 0))
    error = 3;
  else if ((sensor[1] == 1) && (sensor[2] == 1) && (sensor[3] == 1) && (sensor[4] == 0) && (sensor[5] == 1))
    error = 2;
  else if ((sensor[1] == 1) && (sensor[2] == 1) && (sensor[3] == 0) && (sensor[4] == 0) && (sensor[5] == 1))
    error = 1;
  else if ((sensor[1] == 1) && (sensor[2] == 1) && (sensor[3] == 0) && (sensor[4] == 1) && (sensor[5] == 1))
    error = 0;
  else if ((sensor[1] == 1) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[4] == 1) && (sensor[5] == 1))
    error = -1;
  else if ((sensor[1] == 1) && (sensor[2] == 0) && (sensor[3] == 1) && (sensor[4] == 1) && (sensor[5] == 1))
    error = -2;
  else if ((sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 1) && (sensor[4] == 1) && (sensor[5] == 1))
    error = -3;
  else if ((sensor[1] == 0) && (sensor[2] == 1) && (sensor[3] == 1) && (sensor[4] == 1) && (sensor[5] == 1))
    error = -4;
  else if ((sensor[1] == 1) && (sensor[2] == 1) && (sensor[3] == 1) && (sensor[4] == 1) && (sensor[5] == 1))
    if (error == 4) error = 5;
  else if ( error == 5) error = 5;
    else error = -5;
// als geen enkele sensor de lijn ziet (van de lijn af) zal de error 5 of 5 worden afhankelijk aan welke kant de sensor het laatst gezien is
}

void bereken_PID(){
myPID.SetTunings(Kp, Ki, Kd);
myPID.Compute(); //berekent PID_waarde
}
void motor_control() {
   // Motorsnelheid berekenen
int snelheid_links = gewenste_snelheid - PID_waarde; //PID_waarde zal negatief zijn als de error negatief is
int snelheid_rechts = gewenste_snelheid + PID_waarde;

constrain(snelheid_links, 0, 1023); // begrens de snelheid tot de maximale PWM waarde
constrain(snelheid_rechts, 0, 1023);

analogWrite(PWM_links, snelheid_links); //Links Motor snelheid
  analogWrite(PWM_rechts, snelheid_rechts); //Rechts Motor Snelheid

digitalWrite(DIR_rechts, LOW); // zorg dat de motoren vooruit draaien
digitalWrite(DIR_links, LOW);
}


I’d suggest that you edit your post (using the pencil icon at the bottom of the post) and remove the duplications, then add some explanation about which virtual button it is that you’re having difficulty with.

Pete.

Ifs it is a button on the app then do you have it set to switch or push (I think you need switch)

@Timchone Please do not create multiple topic concerning similar issues… I merged them both together.

Thanks but that is not the problem.

And we won’t understand what the problem is unless you provide some explanation about which button it is that you’re having difficulty with, and what you’re trying to achieve (in more detail than you’ve already provided).

Pete.

1 Like

Hi all, I have done a couple of projects with Blynk and i really like it, but im struggeling mith my current one. Is it possible to make a virtual button that switches everything on and off?

It depends what “everything is”…:wink: if it is connected to your device you can do virtual write that turns pin1 low, pin2 low, and so on however many pins you have.

1 Like

I have a car that has 3 modes, one is moving it whith the joystick and this works and the other one is following a line while the button is on. Now the only thing that happens is my nodemcu disconnecting and connecting again when changing that button state. Any ideas?

      #include <PID_v1.h>
#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "4ccb3ce22f794f34a9dfb44208843a20"; 
char ssid[] = "telenet-apn-497da";      
char pass[] = "bscso5zxhoeg"; 
int sensor[5]; //maak een array met 5 variabelen 
int gewenste_snelheid; 
int PWM_links = D3; // pwm h-brug links 
int PWM_rechts = D4; //pwm h-brug rechts 

int snelheid_links; // snelheid linker motor 
int snelheid_rechts;// snelheid rechter motor 

int DIR_links = D0; //direction pin h-brug links 
int DIR_rechts = D8;//direction pin h-brug rechts

void lees_sensorwaarden(void); 
void bereken_PID(void);
void motor_control(void); 

double x, y, abswx, abswy;


double Kp, Ki, Kd;
double Setpoint, Input, PID_waarde; 
int error; 
PID myPID(&Input, &PID_waarde, &Setpoint, Kp, Ki, Kd, DIRECT); 

int startknop;
void rechtdoor(){
  digitalWrite(DIR_links, LOW);
  digitalWrite(DIR_rechts, LOW);
}
void achteruit(){
  digitalWrite(DIR_links, HIGH);
  digitalWrite(DIR_rechts, HIGH);
}
void rechts(){
  digitalWrite(DIR_links, HIGH);
  digitalWrite(DIR_rechts, LOW);
}
void links(){
  digitalWrite(DIR_links, LOW);
  digitalWrite(DIR_rechts, HIGH);
}
BLYNK_WRITE(V0) //Geeft Kp, Ki, Kd, de waarden die in de Blynk app ingevoerd worden
{ 
 Kp = param.asInt(); 
} 
BLYNK_WRITE(V1) 
{ 
 Ki = param.asInt(); 
} 
BLYNK_WRITE(V2) 
{ 
 Kd = param.asInt(); 
} 
BLYNK_WRITE(V3)
{
  startknop = param.asInt();

  
}
BLYNK_WRITE(V6) {
   x = param[0].asInt();
   y = param[1].asInt();
abswx = abs(x);
abswy = abs(y);

if(x<300 && x>-300 && y>0){ //rechtdoor
  rechtdoor();
  analogWrite(PWM_links, y);
  analogWrite(PWM_rechts, y);
  Serial.println("rechtdoor");
  }
else if(x<300 && x>-300 && y<0){//achteruit
  achteruit();
  analogWrite(PWM_links, abswy);
  analogWrite(PWM_rechts, abswy);
  Serial.println("achteruit");
  }
else if(y<300 && y>-300 && x>0){//rechts
  rechts();
  analogWrite(PWM_links, x);
  analogWrite(PWM_rechts, x  );
  Serial.println("rechts");
  }

else if(y<300 && y>-300 && x<0){//links
  links();
  analogWrite(PWM_links, abswx);
  analogWrite(PWM_rechts, abswx);
 Serial.println("links");
  }  
  else{
    analogWrite(PWM_links, 0);
    analogWrite(PWM_rechts, 0);
  }
}
BLYNK_WRITE(V8)
{
  gewenste_snelheid = param.asInt();
}
void setup() { 



pinMode(D1, INPUT); 
pinMode(D2, INPUT); 
pinMode(D5, INPUT); 
pinMode(D6, INPUT); 
pinMode(D7, INPUT); 

pinMode(PWM_links, OUTPUT); //PWM Pin Links 
pinMode(PWM_rechts, OUTPUT); //PWM Pin Rechts 
pinMode(DIR_links, OUTPUT); //DIR Links 
pinMode(DIR_rechts, OUTPUT); //DIR rechts 
Input = error; 
Setpoint = 0; 
myPID.SetMode(AUTOMATIC); //PID regelaar aanzetten

// Debug console 
Serial.begin(9600); 
Blynk.begin(auth, ssid, pass); //verbind met de Blynk server via internet 
} 

void loop(){ 
Blynk.run();

if(startknop==HIGH){

    lees_sensorwaarden(); 
    bereken_PID(); 
    motor_control();
  }

}


 
void lees_sensorwaarden() 
{ 
sensor[1] = digitalRead(D1); 
sensor[2] = digitalRead(D2); 
sensor[3] = digitalRead(D5); 
sensor[4] = digitalRead(D6);
sensor[5] = digitalRead(D7); 

       if ((sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[4] == 0) && (sensor[5] == 1))
    error = 4;
  else if ((sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[4] == 1) && (sensor[5] == 1))
    error = 3;
  else if ((sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[4] == 1) && (sensor[5] == 0))
    error = 2;
  else if ((sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 1) && (sensor[4] == 1) && (sensor[5] == 0))
    error = 1;
  else if ((sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 1) && (sensor[4] == 0) && (sensor[5] == 0))
    error = 0;
  else if ((sensor[1] == 0) && (sensor[2] == 1) && (sensor[3] == 1) && (sensor[4] == 0) && (sensor[5] == 0))
    error = -1;
  else if ((sensor[0] == 0) && (sensor[2] == 1) && (sensor[3] == 0) && (sensor[4] == 0) && (sensor[5] == 0))
    error = -2;
  else if ((sensor[0] == 1) && (sensor[1] == 1) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[5] == 0))
    error = -3;
  else if ((sensor[0] == 1) && (sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[5] == 0))
    error = -4;
  else if ((sensor[0] == 0) && (sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[5] == 0))
    if (error == -4) error = -5;
    else error = 5;

    Input = error;
// als geen enkele sensor de lijn ziet (van de lijn af) zal de error 5 of 5 worden afhankelijk aan welke kant de sensor het laatst gezien is
}

void bereken_PID(){
myPID.SetTunings(Kp, Ki, Kd);
myPID.Compute(); //berekent PID_waarde
}
void motor_control() {
   // Motorsnelheid berekenen
int snelheid_links = gewenste_snelheid - PID_waarde; //PID_waarde zal negatief zijn als de error negatief is
int snelheid_rechts = gewenste_snelheid + PID_waarde;

constrain(snelheid_links, 0, 1023); // begrens de snelheid tot de maximale PWM waarde
constrain(snelheid_rechts, 0, 1023);

analogWrite(PWM_links, snelheid_links); //Links Motor snelheid
  analogWrite(PWM_rechts, snelheid_rechts); //Rechts Motor Snelheid

digitalWrite(DIR_rechts, LOW); // zorg dat de motoren vooruit draaien
digitalWrite(DIR_links, LOW);
}

Which button state?

Pete.

Yep. You have too much stuff in the loop().

void loop(){ 
Blynk.run();

if(startknop==HIGH){

    lees_sensorwaarden(); 
    bereken_PID(); 
    motor_control();
  }

}

Oh, and why the second account? @Koekpils, @Timchone

Bit of a crappy thing to do, creating a new account (if you’re the same person - if not then I apologise)

But try commenting out each of the functions and see if the problem still exists.

void loop(){ 
Blynk.run();

if(startknop==HIGH){

    lees_sensorwaarden(); 
    bereken_PID(); 
    //motor_control();
  }

}

I think maybe motor control and if so then maybe a problem with an output.