Mouse Diagonal Smoothing

I got my pro micro mpu9250 to work as a hands free mouse fairly well (x, -x, y, -y) however, diagonally it steps any idea how to smooth it out?

//

#include<Wire.h>
#include<Mouse.h>
//#include<Keyboard.h>

const int MPU=0x68;  // I2C address of the MPU-6050
int16_t GyX, GyY, GyZ, AcX, AcY, AcZ, BAcX, BAcY, BAcZ, TAcX, TAcY, TAcZ;

int buttonGyro = 6;
int buttonAccel = 4;
int buttonState = 0;

int gyroLock = 0;
int AccelLock = 0;
int AccelLockToggle = 0;
int AccelLockSide = 0;
int GyroLockToggle = 0;
int GyroLockSide = 0;
int i = 0;
int i2 = 0;
int w = 0, a = 0, j = 0;
int threshold = 20;
int X, Y, Z;
int minX, maxX, minY, maxY, minZ, maxZ;
int accelLock = 0;
int TGY = 0;
void setup(){

  pinMode(buttonGyro, INPUT);
  digitalWrite(buttonGyro, HIGH);
  pinMode(buttonAccel, INPUT);
  digitalWrite(buttonAccel, HIGH);
  
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(1);
  Mouse.begin();
}
void loop(){
  gyroLock = digitalRead(buttonGyro);
  if (gyroLock == LOW) {
    if (GyroLockSide == 0) {
      GyroLockSide = 1;
      if (GyroLockToggle == 0) {
        GyroLockToggle = 1;
      }
      else {
        GyroLockToggle = 0;
      }
    }
  }
  else {
    if (GyroLockSide == 1) {
      GyroLockSide = 0;
    }
  }
  if (GyroLockToggle == 0) {
    Wire.beginTransmission(MPU);
    Wire.write(0x43);  // starting with register 0x3B (ACCEL_XOUT_H)
    Wire.endTransmission(false);
    Wire.requestFrom(MPU,6,true);// request a total of 14 registers
    GyX = Wire.read()<<8|Wire.read();
    GyY = Wire.read()<<8|Wire.read();
    GyZ = Wire.read()<<8|Wire.read();// 0x48
    if (AccelLockToggle == 1) {
      Mouse.move( -GyZ / 1000, GyX / 1000, 0 );
    }
    else {
      Mouse.move( -GyZ / 2000, GyX / 2000, 0 );
    }
    TGY -= GyY / 1000;
    if (AccelLockToggle == 1) {
      if (TGY > 1000) {
        //Keyboard.write('d');
      }
      else if (TGY < -1000) {
        //Keyboard.write('a');
      }
    }
    else {
      TGY = 0;
    }
    if (GyX > 2000 || GyY > 2000 || GyZ > 2000) {
      accelLock = 0;
    }
    else {
      accelLock = 1;
    }
  }
  AccelLock = digitalRead(buttonAccel);
  if (AccelLock == LOW) {
    if (AccelLockSide == 0) {
      AccelLockSide = 1;
      if (AccelLockToggle == 0) {
        AccelLockToggle = 1;
      }
      else {
        AccelLockToggle = 0;
      }
    }
  }
  else {
    if (AccelLockSide == 1) {
      AccelLockSide = 0;
    }
  }
  if (AccelLockToggle == 1) {
    if (true) {
      if (i == 0) {
        Wire.beginTransmission(MPU);
        Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
        Wire.endTransmission(false);
        Wire.requestFrom(MPU, 6, true);  // request a total of 14 registers
        BAcX=Wire.read()<<8|Wire.read();// 0x3B     
        BAcY=Wire.read()<<8|Wire.read();
        BAcZ=Wire.read()<<8|Wire.read();// 0x40
        i = 1;
        minX = BAcX;
        maxX = BAcX;
        minY = BAcY;
        maxY = BAcY;
        minZ = BAcZ;
        maxZ = BAcZ;
        BAcX /= 500;
        BAcY /= 500;
        BAcZ /= 500;
      }
      Wire.beginTransmission(MPU);
      Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
      Wire.endTransmission(false);
      Wire.requestFrom(MPU, 6, true);  // request a total of 14 registers
      AcX=Wire.read()<<8|Wire.read();// 0x3B     
      AcY=Wire.read()<<8|Wire.read();
      AcZ=Wire.read()<<8|Wire.read();// 0x40
      if (AcX < minX) {
        minX = AcX;
      }
      else if (AcX > maxX) {
        maxX = AcX;
      }
      if (AcY < minY) {
        minY = AcY;
      }
      else if (AcY > maxY) {
        maxY = AcY;
      }
      if (AcZ < minZ) {
        minZ = AcZ;
      }
      else if (AcZ > maxZ) {
        maxZ = AcZ;
      }
//      for (i2 = 0; i2 < 20; i2++) {
//        Serial.println(" ");
//      }
//      Serial.print("Min-X: ");
//      Serial.print(minX);
//      Serial.print(" | Max-X: ");
//      Serial.print(maxX);
      AcX /= 500;
      TAcX = AcX;
      AcX -= BAcX;
      BAcX = TAcX;
      AcY /= 500;
      TAcY = AcY;
      AcY -= BAcY;
      BAcY = TAcY;
      AcZ /= 500;
      TAcZ = AcZ;
      AcZ -= BAcZ;
      BAcZ = TAcZ;
      Y = -AcX;
      X = -AcY;
      Z = AcZ;
      Y = 0;
      //Serial.print(X);Serial.print(" ");
      //Serial.print(Y);Serial.print(" ");
      //Serial.println(Z);
      if (X > threshold) {
        if (w == 0) {
          w = 1;
        }
        else if (w == -1) {
          w = -2;
        }
        else if (w == 4) {
          w = 0;
        }
        else if (w == -3) {
          w = -4;
        }
      }
      else if (X < -threshold) {
        if (w == 1) {
          w = 2;
        }
        else if (w == 0) {
          w = -1;
        }
        else if (w == 3) {
          w = 4;
        }
        else if (w == -4) {
          w = 0;
        }
      }
      else {
        if (w == 2) {
          w = 3;
        }
        else if (w == -2) {
          w = -3;
        }
      }
      if (Y > threshold) {
        if (a == 0) {
          a = 1;
        }
        else if (a == -1) {
          a = -2;
        }
        else if (a == 4) {
          a = 0;
        }
        else if (a == -3) {
          a = -4;
        }
      }
      else if (Y < -threshold) {
        if (a == 1) {
          a = 2;
        }
        else if (a == 0) {
          a = -1;
        }
        else if (a == 3) {
          a = 4;
        }
        else if (a == -4) {
          a = 0;
        }
      }
      else {
        if (a == 2) {
          a = 3;
        }
        else if (a == -2) {
          a = -3;
        }
      }
      if (Z > threshold) {
        if (j == 0) {
          j = 1;
        }
        else if (j == -1) {
          j = -2;
        }
        else if (j == 4) {
          j = 0;
        }
        else if (j == -3) {
          j = -4;
        }
      }
      else if (Z < -threshold) {
        if (j == 1) {
          j = 2;
        }
        else if (j == 0) {
          j = -1;
        }
        else if (j == 3) {
          j = 4;
        }
        else if (j == -4) {
          j = 0;
        }
      }
      else {
        if (j == 2) {
          j = 3;
        }
        else if (j == -2) {
          j = -3;
        }
      }
    }
    }
  
  
  delay(0);
}

I don't know this sensor, but I had a quick look in your code and found this which may explain resolution problems:

int16_t GyX, GyY, GyZ . . . 
. . .

// you are getting  a signed 16 bit integer in 2 separate parts.
// this implies the first part contains the sign.
// If you've seen an example, this should, however, be OK
GyX = Wire.read()<<8|Wire.read();
GyY = Wire.read()<<8|Wire.read();
GyZ = Wire.read()<<8|Wire.read();// 0x48


if (AccelLockToggle == 1) {
   // Here, it appears you are reducing the effective resolution in quite a crude way.
   // You have effectively a 15bit integer with a sign. By dividing by 1000 
   // you are knocking "nearly" 10 of those bits out leaving 32 discrete values.
   // Maybe try bit shifting to reduce the resolution but take care with the sign bit
   Mouse.move( -GyZ / 1000, GyX / 1000, 0 );
}
else {
   Mouse.move( -GyZ / 2000, GyX / 2000, 0 );
}

According the the documentation, Mouse.move() - Arduino Reference, mouse.move() takes "signed char" parameters.

Maybe write a small sketch without the sensor code which simply puts test values into mouse.move() to see if you get a "smooth" movement.

Thanks!

    Wire.requestFrom(MPU,6,true);// request a total of 14 registers

You look silly when the code and the useless comment don't match.

I uploaded this code and now get a device error 'Windows has stopped this device because it has reported problems. (Code 43) A request for the USB device descriptor failed.' I uninstalled, reinstalled, updated drivers, tried to roll back driver(not an option). I don't know what else to do.

#include <MPU9250_asukiaaa.h>
#include <Wire.h>
#include "Mouse.h"
#define accelRange
#define gyroRange

MPU9250 myIMU; //only need yaw/pitch (x,y)


float aX, aY, gX, gY;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  
  myIMU.beginAccel();
  myIMU.beginGyro();
  
  accelRange(0x08); // accel scale 4g; 2g=0x00; 8g=0x10; 16g=0x10
  gyroRange(0x10); // gyro scale 1000 DPD; 250DPS=0x00; 500DPS=0x10; 2000DPS=0x10
  Mouse.begin();
}

void loop() {

  myIMU.accelUpdate();
  aX = myIMU.accelX();
  aY = myIMU.accelY();
  
  myIMU.gyroUpdate();
  gX = myIMU.gyroX();
  gY = myIMU.gyroY();
  
  int total_gX = cos((gX)*cos(gY));
  int total_gY = sin((gX)*cos(gY));
  
  Mouse.move(total_gX, total_gY, 0);
}