Receive garbage data from BT when i use mouse.move()

Hi

I want to control my mouse cursor via bluetooth with mpu-6050. Without mouse.move() function i receive data with some delay(500ms) and i don't know why. I don't use delay() I setup same baudrate(38400) for bluetooth module. When i use mouse.control i receive garbage data. https://gyazo.com/e0236565856d079ddbb788693c369790

This is the part of code for sender:

Serial1.print((int)angle_x);
         Serial1.print("a,");
          Serial1.print((int)angle_y);
         Serial1.print("b,");
        Serial1.print(buton);
        Serial1.print("c,");

Receiver:

if (Serial1.available())  {
      char c = Serial1.read();
      if (c == ',') {
        if (readString.length() > 1) {
          int n = readString.toInt();
           if (readString.indexOf('a') > 0) {
           angle_x = n;
          }
        if (readString.indexOf('b') > 0) {
          angle_y = n;
          }
           if (readString.indexOf('c') > 0) {
            button = n;
          }
          readString = "";
      }
      }
      else {
        readString += c;
      }
    }

This is the part of code for sender

This is part of the answer:

You need to change ...

PaulS: This is part of the answer:

You need to change ...

What i need to change in my code? If i comment mouse.move() everything is ok. I don't think is a problem with the sender.

What i need to change in my code?

The bit where you only posted some of it.

PaulS:
The bit where you only posted some of it.

Sender:

#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"
#include <SoftwareSerial.h>
SoftwareSerial BTserial(4, 5); // RX | TX
MPU6050 accelgyro(0x68);

int b1 = 7;
int b2 = 10;
int b3 = 15;


int16_t ax, ay, az, gx, gy, gz;
int x = 50;
int state;


int maxx = 0, mayy, mazz, mgxx, mgyy, mgzz; //medie acceleratie
int offaxx = 0, offayy = 0, offazz = 0, offgxx = 0, offgyy = 0, offgzz = 0; //offset
double gxangle, gyangle, gzangle;
int z = 0;
float RADIANS_TO_DEGREES = 180 / 3.14159;
uint32_t timer;
int buton1 = 0, but1 = 0, lastbuton1 = 0;


void setup() {

  pinMode(b1, INPUT);
  pinMode(b2, OUTPUT);
  pinMode(b3, INPUT_PULLUP);


  // Serial.begin(9600);
  BTserial.begin(38400);

  //  Mouse.begin();


  accelgyro.initialize();
  accelgyro.setXAccelOffset(-3733);
  accelgyro.setYAccelOffset(-2726);
  accelgyro.setZAccelOffset(2176);
  accelgyro.setXGyroOffset(-8);
  accelgyro.setYGyroOffset(-69);
  accelgyro.setZGyroOffset(-54);
}

void loop() {


  if (state == 0) {
    masurare();
    state++;
  }


  if (state == 1) {
    state++;
    calibrare();
    timer = millis();
  }


  if (state == 2) {
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

    double gxrate = gx / 131.0; 
    double gyrate = gy / 131.0;
    double gzrate = gz / 131.0;

    double axrate = ax / 16384.0; 
    double ayrate = ay / 16384.0;
    double azrate = az / 16384.0;

    double dt = double (millis() - timer) / 1000;


    gxangle += gxrate * dt;
    gyangle += gyrate * dt;
    gzangle += gzrate * dt;
    timer = millis();


    double ayangle = atan(-1 * axrate / sqrt(pow(ayrate, 2) + pow(azrate, 2))) * RADIANS_TO_DEGREES;
    double axangle = atan(ayrate / sqrt(pow(axrate, 2) + pow(azrate, 2))) * RADIANS_TO_DEGREES;



    //anglex=const*(last_angle+gyro_angle*dt)+(1-const)*accel_angle
    double angle_x = 0.97 * (angle_x + gxangle) + 0.03 * axangle;
    double angle_y = 0.97 * (angle_y + gyangle) + 0.03 * ayangle;
    button();
 


      BTserial.print(angle_x);
      BTserial.print("a,");
      BTserial.print(angle_y);
      BTserial.print("b,");
      BTserial.print(but1);
      BTserial.print("c,");

   
  }
}


void masurare() {
  long axx = 0, ayy = 0, azz = 0, gxx = 0, gyy = 0, gzz = 0;
  int i = 0;
  while (i < (x + 51)) {
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

    if (i > 50 && i <= x + 50) {
      axx = axx + ax;
      ayy = ayy + ay;
      azz = azz + az;
      gxx = gxx + gx;
      gyy = gyy + gy;
      gzz = gzz + gz;
    }

    if (i == (x + 50)) {
      maxx = axx / x;
      mayy = ayy / x;
      mazz = azz / x;
      mgxx = gxx / x;
      mgyy = gyy / x;
      mgzz = gzz / x;
    }

    i++;
    delay(2);
  }
}

void calibrare() {

  offaxx = -maxx / 8;
  offayy = -mayy / 8;
  offazz = (16384 - mazz) / 8; //Accelerometrul va detecta mereu 1g(16384) pe verticala

  offgxx = -mgxx / 4;
  offgyy = -mgyy / 4;
  offgzz = -mgzz / 4;

  while (z == 0) {
    int y = 0;

    accelgyro.setXAccelOffset(offaxx);
    accelgyro.setYAccelOffset(offayy);
    accelgyro.setZAccelOffset(offazz);
    accelgyro.setXGyroOffset(offgxx);
    accelgyro.setYGyroOffset(offgyy);
    accelgyro.setZGyroOffset(offgzz);

    masurare();
    //Calibrare accelerometru
    if (abs(maxx) <= 8) y++;
    else {
      offaxx = offaxx - maxx / 8;
    }

    if (abs(mayy) <= 13)  y++;
    else {
      offayy = offayy - mayy / 8;
    }


    if (abs(16384 - mazz) <= 13) y++;
    else {
      offazz = offazz + (16384 - mazz) / 8;
    }

    //Calibrare giroscop
    if (abs(mgxx) <= 2) y++;
    else {
      offgxx = offgxx - mgxx / 5;
    }

    if (abs(mgyy) <= 2) y++;
    else {
      offgyy = offgyy - mgyy / 5;
    }

    if (abs(mgzz) <= 2) y++;
    else {
      offgzz = offgzz - mgzz / 5;
    }
    if (y == 6) {
      z = 1;
      digitalWrite(b2, HIGH);
      delay(1000);
      digitalWrite(b2, LOW);
      delay(1000);
      digitalWrite(b2, HIGH);
      delay(1000);

      digitalWrite(b2, LOW);
      delay(1000);
      digitalWrite(b2, HIGH);
      delay(1000);
      digitalWrite(b2, LOW);
    }
  }
}

void button() {
  but1 = 0;
  buton1 = digitalRead(b1);
  if (buton1 != lastbuton1) {
    if (buton1 == 1) {
      but1 = buton1;
    }
  }
  lastbuton1 = buton1;
}

Receiver:

#include <Mouse.h>


char c = ' ';
int x_angle = 0, y_angle = 0, button = 0;
String readString;
int a = 0, b = 0;
void setup() {
  //  Serial.begin(9600);
  Serial1.begin(38400);
  Mouse.begin();
}

void loop() {
  a = y_angle / 5;
  b = x_angle / 5;
[b]  //  Mouse.move(a, b,0);[/b] [i]If i comment this line i'll receive all values[/i]
  Serial.print(x_angle);
  Serial.print("\t");
  Serial.print(y_angle);
  Serial.print("\n");


  if (Serial1.available())  {

    char c = Serial1.read();
    if (c == ',') {
      if (readString.length() > 1) {
        int n = readString.toInt();
        if (readString.indexOf('a') > 0) {
          x_angle = n;
        }
        if (readString.indexOf('b') > 0) {
          y_angle = n;
        }
        if (readString.indexOf('c') > 0) {
          button = n;
        }
        readString = "";
      }
    }
    else {
      readString += c;
    }
  }

}

Without mouse.move https://gyazo.com/3769001b2df681b817103b21675ec816

With mouse.move https://gyazo.com/0434d2fb30f42f11d5b952fbbce90611

I really need help. The only change in my code is mouse.move function

L.E.: if i use mouse.move(0,0) i have the same problem. Maybe mouse.move interfere with rx/tx?