How to use RN42 Bluetooth module and MPU-6050 simultaneously?

Hello everyone in Arduino community. I have a question about using two modules with Arduino UNO at the same time.

I’m now trying to measure the tilt angle of the head by MPU-6050 sensor and move the cursor on the monitor according to its angle. The HID protocol of RN42 BT module is used to move the cursor.

I checked each module separetaly. In other words I confirmed MPU-6050 correctly works when I only connected it to Arduino. Also RN42 correctly works in HID mode when I connected it without MPU-6050. The problem is when I connnect those two modules at the same time, I does not work. Does anyone have a solution for that? Any help would be appreciated!

Here’s a detailed description of what I have now:

MPU-6050 — Arduino UNO
VCC — 3.3V
GND — GND
SCL — SCL
SDA — SDA

RN42 — Arduino UNO
3.3V — 3.3V
GND — GND
RXD — TXD
TXD — RXD
CTS -|
RTS -|

The below code is what I am trying to run:

#include <SoftwareSerial.h>
#include <Wire.h>

#define RAD_TO_DEG 180/PI
#define DEG_TO_RAD PI/180

#define tx 1
#define rx 0

#define LED 13

int xRaw, yRaw, zRaw;
int xAcc, yAcc, zAcc;
int roll, pitch;

SoftwareSerial btSerial(rx, tx);

void setup() {
  Wire.begin();

  Wire.beginTransmission(0x68);
  Wire.write(0x6B);
  Wire.write(0x00);
  Wire.endTransmission();
  
  Wire.beginTransmission(0x68);
  Wire.write(0x1C);
  Wire.write(0x10);
  Wire.endTransmission();

  Wire.beginTransmission(0x68);
  Wire.write(0x1B);
  Wire.write(0x08);
  Wire.endTransmission();

  Wire.beginTransmission(0x68);
  Wire.write(0x1A);
  Wire.write(0x05);
  Wire.endTransmission();
  
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
  
  btSerial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  Wire.beginTransmission(0x68);
  Wire.write(0x3B);
  Wire.endTransmission();
  Wire.requestFrom(0x68, 14);

  digitalWrite(LED, HIGH);
  while (Wire.available() < 14);
  digitalWrite(LED, LOW);

  xRaw = Wire.read() << 8 | Wire.read();
  yRaw = Wire.read() << 8 | Wire.read();
  zRaw = Wire.read() << 8 | Wire.read();

  roll = atan2(yRaw, xRaw) * RAD_TO_DEG;
  pitch = atan2(zRaw, xRaw) * RAD_TO_DEG;

  int xMove = convertToRange(roll);
  int yMove = convertToRange(pitch);
  
  btSerial.write((byte)0xFD);
  btSerial.write((byte)0x05);
  btSerial.write((byte)0x02);
 
  btSerial.write((byte)0x00);
  btSerial.write((byte)xMove);  // the displacement of the cursor along the x-axis
  btSerial.write((byte)yMove);  // the displacement of the cursor along the y-axis
  btSerial.write((byte)0x00);

  delay(50);
}

int convertToRange(int angle) {
  int res;
  if (0 <= angle && angle <= 40) {
    res = (angle/40) * 127;
  }
  else if (-40 <= angle && angle < 0) {
    res = 255 - (angle/40) * 127;
  }
  else {
    res = 0;
  }
  return res;
}

Please tell us what "it does not work" means.

What did you expect to happen, and what happened instead? Post examples of output.