Error with virtualWrite

Hello, I try to use the virtualWrite command in a script and the command work one time in two. The objective is to set at 0 two virtual pins, V6 and V7, when I click on the virtual pin V8 (on a vertical step).
The two virtual pins set 9 score variables in terms of the last virtual pin (innings).
I use an Arduino Mega with a HC-05 bluetooth module. And I have a local server 0.41.14 on java8 on a Raspberry Pi 2 B but I try on the Blynk’s servers and it’s the same thing.

(sorry for the mistakes i’m a french student)


//-------------Blynk-------------//

#define BLYNK_USE_DIRECT_CONNECT

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>

char auth[] = "X7XRIjkJ0RncKxrH_J-Zw4o7qZW4JU4L";

//-----------Variables-----------//

int mancheNumber = 1;

int SM1H = 0;
int SM2H = 0;
int SM3H = 0;
int SM4H = 0;
int SM5H = 0;
int SM6H = 0;
int SM7H = 0;
int SM8H = 0;
int SM9H = 0;

int SM1V = 0;
int SM2V = 0;
int SM3V = 0;
int SM4V = 0;
int SM5V = 0;
int SM6V = 0;
int SM7V = 0;
int SM8V = 0;
int SM9V = 0;

//-----------Fonctions-----------//

void refrechMancheNum(int x)
{
  mancheNumber = x;
}

void refrechScoreH(int x)
{
  if (mancheNumber == 1)
  {
    SM1H = x;
  }
  if (mancheNumber == 2)
  {
    SM2H = x;
  }
  if (mancheNumber == 3)
  {
    SM3H = x;
  }
  if (mancheNumber == 4)
  {
    SM4H = x;
  }
  if (mancheNumber == 5)
  {
    SM5H = x;
  }
  if (mancheNumber == 6)
  {
    SM6H = x;
  }
  if (mancheNumber == 7)
  {
    SM7H = x;
  }
  if (mancheNumber == 8)
  {
    SM8H = x;
  }
  if (mancheNumber == 9)
  {
    SM9H = x;
  }
}

void refrechScoreV(int x)
{
  if (mancheNumber == 1)
  {
    SM1V = x;
  }
  if (mancheNumber == 2)
  {
    SM2V = x;
  }
  if (mancheNumber == 3)
  {
    SM3V = x;
  }
  if (mancheNumber == 4)
  {
    SM4V = x;
  }
  if (mancheNumber == 5)
  {
    SM5V = x;
  }
  if (mancheNumber == 6)
  {
    SM6V = x;
  }
  if (mancheNumber == 7)
  {
    SM7V = x;
  }
  if (mancheNumber == 8)
  {
    SM8V = x;
  }
  if (mancheNumber == 9)
  {
    SM9V = x;
  }
}

void printa () //print function to check if the script work
{
  Serial.print(SM1H);
  Serial.print(" ");
  Serial.print(SM2H);
  Serial.print(" ");
  Serial.print(SM3H);
  Serial.print(" ");
  Serial.print(SM4H);
  Serial.print(" ");
  Serial.print(SM5H);
  Serial.print(" ");
  Serial.print(SM6H);
  Serial.print(" ");
  Serial.print(SM7H);
  Serial.print(" ");
  Serial.print(SM8H);
  Serial.print(" ");
  Serial.print(SM9H);

  Serial.print(" - ");

  Serial.print(SM1V);
  Serial.print(" ");
  Serial.print(SM2V);
  Serial.print(" ");
  Serial.print(SM3V);
  Serial.print(" ");
  Serial.print(SM4V);
  Serial.print(" ");
  Serial.print(SM5V);
  Serial.print(" ");
  Serial.print(SM6V);
  Serial.print(" ");
  Serial.print(SM7V);
  Serial.print(" ");
  Serial.print(SM8V);
  Serial.print(" ");
  Serial.println(SM9V);
}

//--------Fonctions Blynk--------//

BLYNK_WRITE(V6) //Score H
{
  int sh = param.asInt();
  refrechScoreH(sh);
  printa();
}

BLYNK_WRITE(V7) //Score V
{
  int sv = param.asInt();
  refrechScoreV(sv);
  printa();
}

BLYNK_WRITE(V8) //Numéro de la manche
{
  Blynk.virtualWrite(V6, 0);
  Blynk.virtualWrite(V7, 0);
  int m = param.asInt();
  refrechMancheNum(m);  
}

void setup()
{
  DebugSerial.begin(9600);
  DebugSerial.println("Waiting for connections...");
  
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

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

I don’t understand why you have the BLE module connected to serial and are sending your debug data to the software serial port.
Do you have an FTDI connected to pins 2 & 3?

Pete.

I continued to search and I understand that the error occurs when I have the “Wasn’t online yet” message on mobile, so now I must discover why.

If you sorted-out your serial setup then you’d have much more information about what is (or isn’t) happening with your connection.

Pete

I don’t understand how to sort-out. And can void be a problem ? Because when the void function printa() is called there is a problem but when I comment it (//printa()) all works good.

I understood, printa() communicate on TX and RX, as the HC-05. Thanks for your help this subject is resolved.