It tries to connect the slave to the master, pair and transmit the pitch, roll, and yaw values through Bluetooth. However, the transmitted value is all constant at 90, and I don't know what the problem is. The pitch roll yaw value of mpu 6050 comes out well, and simply sending and receiving values without using mpu 6050 goes well.
//slave
#include <SoftwareSerial.h>
SoftwareSerial btSerial(3,2);
void setup() {
btSerial.begin(9600);
Serial.begin(9600);
}
void loop() {
if(btSerial.available()){
Serial.print(" roll ");
long a = btSerial.parseInt();
Serial.print(a);
Serial.print(" pitch ");
long b = btSerial.parseInt();
Serial.print(b);
Serial.print(" yaw ");
long c = btSerial.parseInt();
Serial.print(c);
Serial.println("");
}
}
//master
#include <Wire.h>
#include <MPU6050.h>
#include <SoftwareSerial.h>
MPU6050 mpu;
SoftwareSerial btSerial(3,2);
// Timers
unsigned long timer = 0;
float timeStep = 0.01;
// Pitch, Roll and Yaw values
float pitch = 0;
float roll = 0;
float yaw = 0;
void setup()
{
btSerial.begin(9600);
Serial.begin(9600);
// Initialize MPU6050
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
{
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
// Calibrate gyroscope. The calibration must be at rest.
// If you don't want calibrate, comment this line.
mpu.calibrateGyro();
// Set threshold sensivty. Default 3.
// If you don't want use threshold, comment this line or set 0.
mpu.setThreshold(3);
}
void loop()
{
timer = millis();
// Read normalized values
Vector norm = mpu.readNormalizeGyro();
// Calculate Pitch, Roll and Yaw
pitch = pitch + norm.YAxis * timeStep;
roll = roll + norm.XAxis * timeStep;
yaw = yaw + norm.ZAxis * timeStep;
int pitchmap= map(pitch ,-100,100,0,180);
int rollmap = map(roll,-100,100,0,180);
int yawmap = map(yaw, -100,100,0, 180);
Serial.print(pitchmap);
Serial.print(rollmap);
Serial.println(yawmap);
// Wait to full timeStep period
btSerial.println(pitchmap);
btSerial.println(rollmap);
btSerial.println(yawmap);
delay(10);
}