MPU 6050 combine with BMP180 on the Arduino UNO board

Hello~
I just tried combine MPU 6050 with BMP 180 but it has a serious error
The error is our source code doesn’t work :sob:
We combine each other code to only one code But it’s not working
They are clearly work separately :sob: and We can’t find a grammatical error
We all the beginner in Arduino so we need you guys’ help!!
Please help to solve this problem :’(
These pictures are our electric circuit to connet Arduino UNO and MPU 6050 and BMP 180 and LCD monitor
And these source codes are MPU 6050 + electrical magnetic, BMP 180 and final bind.
PLEASE see our code and reply to slove this problem!
Thank you~ :’(

MPU 6050 + electrical magnetic.txt (3.72 KB)

BMP 180.txt (2.49 KB)

Final bind.txt (6.05 KB)

It would really help if comments are in english...

You should describe what problem you have with the source code. What output do you get? What output do you expect?

Here is the unedited code in tags (Please read the “How to use this forum” thread next time):

#include <Wire.h> //°øÅë
#include <Adafruit_Sensor.h> //¿Âµµ,°íµµ
#include <Adafruit_BMP085_U.h>
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

const int MPU_addr = 0x68; //ÀÚÀÌ·Î
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;

float dt;
float accel_angle_x, accel_angle_y, accel_angle_z;
float gyro_angle_x, gyro_angle_y, gyro_angle_z;
float filtered_angle_x, filtered_angle_y, filtered_angle_z;
float baseAcX, baseAcY, baseAcZ;
float baseGyX, baseGyY, baseGyZ;

const int driverPin = 10; //Ȑ̉
int led =13;

int j; //¿Âµµ,°íµµ
int arry[200];

void setup() { 
  initMPU6050(); //ÀÚÀÌ·Î
  Serial.begin(115200);
  calibAccelGyro();
  initDT(); 
  
  pinMode(driverPin, OUTPUT); //»êÃâ
  pinMode(led, OUTPUT);

  Serial.begin(9600); //¿Âµµ,°íµµ
  Serial.println("Pressure Sensor Test"); Serial.println("");
  
  if(!bmp.begin()) 
  {
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  displaySensorDetails(); 

}

void displaySensorDetails(void) //¿Âµµ,°íµµ Ãâ·Â
{
  sensor_t sensor;
  bmp.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version); 
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" hPa");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" hPa");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" hPa");  
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500); //Áö¿¬½Ã°£- 1000=1ÃÊ
}

void loop() 
{
  readAccelGyro(); //ÀÚÀÌ·Î
  calcDT();
  calcAccelYPR();
  calcGyroYPR();
  calcFilteredYPR();              

  static int cnt;
  cnt++;
  if(cnt%2 == 0)
    SendDataToProcessing();   
  
  if(filtered_angle_x==30&&filtered_angle_y==30) //»êÃâ
 {
  delay(3000);
  magneticOff();
  }                             
  else
  magneticOn(); 

  int i; //¿Âµµ,°íµµ
  j = 0;
  for(i=0;i<200;i++)
  {
    result();
  }
  
}

void initMPU6050() //ÀÚÀÌ·Î ½ÃÀÛ
{
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
}

void readAccelGyro() //ÀÚÀÌ·Î ÀÔ·Â
{
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr, 14, true);
  AcX = Wire.read() << 8 | Wire.read();
  AcY = Wire.read() << 8 | Wire.read();
  AcZ = Wire.read() << 8 | Wire.read();
  Tmp = Wire.read() << 8 | Wire.read();
  GyX = Wire.read() << 8 | Wire.read();
  GyY = Wire.read() << 8 | Wire.read();
  GyZ = Wire.read() << 8 | Wire.read();
}

void SendDataToProcessing() //ÀÚÀÌ·Î Ãâ·Â
{
  Serial.print(F(" x = "));
  Serial.print(filtered_angle_x, 2);
  Serial.print(F(" y = "));
  Serial.print(filtered_angle_y, 2);
  Serial.print(F(" z = "));
  Serial.print(filtered_angle_z, 2);
  Serial.println(F(""));
  delay(100);
}

void calibAccelGyro() //ÀÚÀÌ·Î °¡¼Óµµ °è»ê º£À̽º
{
  float sumGyX = 0, sumGyY = 0, sumGyZ = 0;

  readAccelGyro();

  for(int i=0; i<10; i++){
    readAccelGyro();
    sumGyX += GyX; sumGyY += GyY; sumGyZ += GyZ;
    delay(100);
  }
  baseGyX = sumGyX / 10; baseGyY = sumGyY / 10; baseGyZ = sumGyZ / 10;
}

unsigned long t_now;
unsigned long t_prev;
void initDT() 
{
    t_prev = millis();
}

void calcDT() 
{
  t_now = millis();
  dt = (t_now - t_prev) / 1000.0;
  t_prev = t_now;
}

//ÀÚÀÌ·Î °¡¼Óµµ °è»ê (YPR)
void calcAccelYPR() 
{

  float accel_x, accel_y, accel_z;
  float accel_xz, accel_yz;
  const float RADIANS_TO_DEGREES = 180/3.14159;

  accel_x = AcX - baseAcX;
  accel_y = AcY - baseAcY;
  accel_z = AcZ + (16384 - baseAcZ);

  accel_yz = sqrt(pow(accel_y, 2) + pow(accel_z, 2));
  accel_angle_y = atan(-accel_x / accel_yz)*RADIANS_TO_DEGREES;

  accel_xz = sqrt(pow(accel_x, 2) + pow(accel_z, 2));
  accel_angle_x = atan(accel_y / accel_xz)*RADIANS_TO_DEGREES;

  accel_angle_z = 0;
}

//ÀÚÀÌ·Î ÀÚÀ̷ΰª °è»ê (YPR)
 float gyro_x, gyro_y, gyro_z; 

void calcGyroYPR()
{
  const float GYROXYZ_TO_DEGREES_PER_SED = 131;
                                
  gyro_x = (GyX - baseGyX) / GYROXYZ_TO_DEGREES_PER_SED;
  gyro_y = (GyY - baseGyY) / GYROXYZ_TO_DEGREES_PER_SED;
  gyro_z = (GyZ - baseGyZ) / GYROXYZ_TO_DEGREES_PER_SED;

  gyro_angle_x += gyro_x * dt;
  gyro_angle_y += gyro_y * dt;
  gyro_angle_z += gyro_z * dt;
}

void calcFilteredYPR() //ÀÚÀÌ·Î ÇÊÅÍ Àû¿ë°ª °è»ê (YPR)
{

  const float ALPHA = 0.96;
  float tmp_angle_x, tmp_angle_y, tmp_angle_z;

  tmp_angle_x = filtered_angle_x + gyro_x * dt;
  tmp_angle_y = filtered_angle_y + gyro_y * dt;
  tmp_angle_z = filtered_angle_z + gyro_z * dt;

  filtered_angle_x = ALPHA * tmp_angle_x + (1.0 - ALPHA) * accel_angle_x;
  filtered_angle_y = ALPHA * tmp_angle_y + (1.0 - ALPHA) * accel_angle_y;
  filtered_angle_z = tmp_angle_z; 
}

void magneticOn() //Ȑ̉
{

    digitalWrite(driverPin, HIGH);
    digitalWrite(led, HIGH);
}
void magneticOff()
{    
    digitalWrite(driverPin, LOW);
    digitalWrite(led, LOW);
}

void result() //¿Âµµ,°íµµ ÇÔ¼ö ALL
{
  sensors_event_t event; 
  bmp.getEvent(&event);
  Serial.print("Pressure:    ");
  Serial.print(event.pressure);
  Serial.println(" hPa");
  delay(100);
  
  float temperature;
  bmp.getTemperature(&temperature);
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" C");
  delay(100);
 
  float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
  arry[j]=bmp.pressureToAltitude(seaLevelPressure,event.pressure);
  if(arry[j]-arry[0]>=0)
  {
    Serial.print("Altitude:    "); 
    Serial.print(arry[j]-arry[0]); 
    Serial.println(" m");
    Serial.println(j);
    Serial.println("");
  }
  else
  {
    Serial.print("Altitude:    "); 
    Serial.println("default"); 
    Serial.println(j);
    Serial.println("");
  }
  j++;
  delay(100);
}