MPU6050 And BMP180 Together

Hi, I am working on a flight computer for a model rocket and am recently stuck. I'm using a MPU6050 + HMC5883L/QMC5883 + BMP180 10DOF board for the first parachute ejection system and a BMP180 for the second parachute ejection system. I am currently testing the flight computer but I see that I can not get altitude data (there is some data, but it is just like random numbers) from the BMP180 -which is necessary for triggering the ejection system- when I connect the 10DOF and the BMP180 in serial to Arduino UNO and look at the serial monitor. I think I know how to connect multiple I2C devices to the same board; with pull-up resistors. (I also read something that says that these sensors have built-in pull-up resistors, so, I do not need to add them separately. May this be the reason? But I could not get clear data either way) Since I need acceleration/gyro data for the first ejection mechanism and pressure/altitude data for the second ejection mechanism, I have to find a way to get these data clearly. When I checked the addresses of the sensors, I saw that BMP180's address is 0x77 and 10DOF has three addresses: 0x53, 0x68, 0x77. I think that the problem is caused by the address 0x77. And there is not any pin to change the addresses on the sensors. So, how can I overcome this? The code is attached below. Thanks for your help in advance.

main_program_woex.ino (5.05 KB)

Please read and follow the instructions in the "How to use the forum" post, at the top of every forum section.

jremington:
Please read and follow the instructions in the "How to use the forum" post, at the top of every forum section.

Thanks! I hope it is better now :slight_smile:

Your code, posted in line as described in "How to use the forum".

Yes, it is a problem if two sensors have the same I2C address. If you have two BMP180 pressure sensors, remove one of them. Or replace the 10DOF module with a simple MPU6050 module.

Note: "goto" statements are unnecessary, and are generally viewed as bad programming practice.

#include <Adafruit_BMP085.h> 
#include <MPU6050_tockn.h> 
#include <Wire.h>
#include <Servo.h> 
Servo servo1; 
Servo servo2;
Adafruit_BMP085 bmp; 
MPU6050 mpu6050(Wire); 
float base;
int alti, xangle, zangle, yacc, gpslat, gpslon;
#define rx 11 
#define tx  10 
#define gpsbaud 9600 
#define BuzzerPin  11 
#define buzzerdelay 100 //ms
#define buzzererrordelay 100 //ms
#define buzzerbeeptime 2 //times
#define startingaltitude 600 //m
#define delaytime 2000 //ms
#define thresholdangle 30 //degree
#define thresholdacc 0 //m/s^2
#define servoangle 180 //degree
#define seconderaltitude1 1000 //m
#define seconderaltitude2 700 //m
#define seconderaltitude3 600 //m
#define afterdeploytime 3000 //ms
#define safeacc -3 //m/s^2
#define groundaltitude 3 //m
#define servo1pin 9 
#define servo2pin 6 
#define servoinitialposition 90 //degree
#include <TinyGPS++.h> 
TinyGPSPlus gps; 
#include <SoftwareSerial.h> 
SoftwareSerial ss(rx, tx); 

void setup() {

  Serial.begin(9600); 
  ss.begin(gpsbaud); 
  Wire.begin(); 
  mpu6050.begin(); 
  mpu6050.calcGyroOffsets(true);
  servo1.write(servoinitialposition);
  servo2.write(servoinitialposition);
  servo1.attach(servo1pin); 
  servo2.attach(servo2pin);
  pinMode(BuzzerPin, OUTPUT); 
  digitalWrite(BuzzerPin, LOW); 
  if (bmp.begin()) { 
    Serial.println(); 
    Serial.println("BMP180 initialization successful"); 
    for (int i = 0; i <= buzzerbeeptime; i++) { 
      digitalWrite(BuzzerPin, HIGH); 
      delay(buzzerdelay); 
      digitalWrite(BuzzerPin, LOW); 
      delay(buzzerdelay); 
    }
  }

  else { 
    Serial.println(); 
    Serial.println(" --- Could not find a valid BMP180 sensor, check wiring! --- "); 
    digitalWrite(BuzzerPin, HIGH); 
    delay(buzzererrordelay); 
    digitalWrite(BuzzerPin, LOW);
  }
  base = bmp.readPressure(); 
  flight(); 
}

void loop() {} 

int getAltitude() {
  alti = round(bmp.readAltitude(base));
  Serial.print(F("MAIN: ")); 
  Serial.print(alti); 
  Serial.println(F("m")); 
  return alti; 
}

void getNMEA() {
  Serial.println(); 
  while (ss.available() > 0) {
    Serial.write(ss.read()); 
  }
  Serial.println(); 
}
int mpux() {
  mpu6050.update(); 
  xangle = abs(mpu6050.getAngleX()); 
  return xangle; 
}
int mpuz() { 
  mpu6050.update();
  zangle = abs(mpu6050.getAngleZ()); 
  return zangle; 
}
int mpuaccy() { 
  mpu6050.update(); 
  yacc = mpu6050.getAccY(); 
  return yacc; 
}

void flight () { 
s1: delay(delaytime); getAltitude(); getNMEA(); 
  Serial.print(F("MAIN: <=")); Serial.print(startingaltitude); Serial.print(F("m ")); Serial.print(F("(")); Serial.print(alti); Serial.println(F("m)"));
  if (alti > startingaltitude) { 
    Serial.print(F("MAIN: THRESHOLD ALTITUDE EXCEEDED ")); Serial.print(F("(>")); Serial.print(startingaltitude); Serial.print(F("m)"));
s2: delay(delaytime); mpuaccy(); getAltitude(); getNMEA(); 
    if ( yacc < thresholdacc) { 
      Serial.println(F("MAIN: ACCELERATION THRESHOLD EXCEEDED, SLOWING DOWN"));
s3: delay(delaytime); mpux(); mpuz(); getAltitude(); getNMEA(); 
      if ( xangle > thresholdangle || zangle > thresholdangle) { 
        Serial.print(F("MAIN: ")); Serial.print(thresholdangle); Serial.println(F(" DEGREE DETECTED, MAIN 1 EJECTING"));
        servo1.write(servoangle); 
        delay(afterdeploytime); 
s4: delay(delaytime); getAltitude(); getNMEA(); 
        if (alti < seconderaltitude1) { 
          Serial.print(F("MAIN: ALTITUDE <=")); Serial.print(seconderaltitude1); Serial.print(F("m"));
s5: delay(delaytime); getAltitude(); getNMEA(); 
          if (alti < seconderaltitude2) { 
            Serial.print(F("MAIN: ALTITUDE <=")); Serial.print(seconderaltitude2); Serial.print(F("m"));
s6: delay(delaytime); getAltitude(); getNMEA(); 
            if (alti < seconderaltitude3) { 
              Serial.print(F("MAIN: ALTITUDE <=")); Serial.print(seconderaltitude3); Serial.print(F("m, MAIN 2 EJECTING"));
              servo2.write(servoangle); 
              delay(afterdeploytime); 
s7: delay(delaytime); mpuaccy(); getAltitude(); getNMEA(); 
              if (yacc > safeacc) { 
                Serial.print(F("MAIN: ACCELERATION ")); Serial.print(yacc); Serial.println(F("m/s^2, SAFE"));
s8: delay(delaytime); getAltitude(); getNMEA();  
                if (alti < groundaltitude) { 
                  getAltitude(); getNMEA(); 
                  Serial.println(F("MAIN: LANDED"));
                }
                else { 
                  goto s8; 
                }
              }
              else { 
                Serial.print(F("MAIN: ACCELERATION "));
                Serial.print(yacc);
                Serial.println(F("m/s^2, HIGH ACCELERATION"));
                goto s7; 
              }
            }
            else { 
              goto s6; 
            }
          }
          else {
            goto s5;
          }
        }
        else {
          goto s4; 
        }
      }
      else { 
        goto s3; 
      }
    }
    else { 
      goto s2; 
    }
  }
  else { 
    goto s1; 
  }
}

jremington:
Your code, posted in line as described in "How to use the forum".

Yes, it is a problem if two sensors have the same I2C address. If you have two BMP180 pressure sensors, remove one of them. Or replace the 10DOF module with a simple MPU6050 module.

Note: "goto" statements are unnecessary, and are generally viewed as bad programming practice.

#include <Adafruit_BMP085.h> 

#include <MPU6050_tockn.h>
#include <Wire.h>
#include <Servo.h>
Servo servo1;
Servo servo2;
Adafruit_BMP085 bmp;
MPU6050 mpu6050(Wire);
float base;
int alti, xangle, zangle, yacc, gpslat, gpslon;
#define rx 11
#define tx  10
#define gpsbaud 9600
#define BuzzerPin  11
#define buzzerdelay 100 //ms
#define buzzererrordelay 100 //ms
#define buzzerbeeptime 2 //times
#define startingaltitude 600 //m
#define delaytime 2000 //ms
#define thresholdangle 30 //degree
#define thresholdacc 0 //m/s^2
#define servoangle 180 //degree
#define seconderaltitude1 1000 //m
#define seconderaltitude2 700 //m
#define seconderaltitude3 600 //m
#define afterdeploytime 3000 //ms
#define safeacc -3 //m/s^2
#define groundaltitude 3 //m
#define servo1pin 9
#define servo2pin 6
#define servoinitialposition 90 //degree
#include <TinyGPS++.h>
TinyGPSPlus gps;
#include <SoftwareSerial.h>
SoftwareSerial ss(rx, tx);

void setup() {

Serial.begin(9600);
  ss.begin(gpsbaud);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
  servo1.write(servoinitialposition);
  servo2.write(servoinitialposition);
  servo1.attach(servo1pin);
  servo2.attach(servo2pin);
  pinMode(BuzzerPin, OUTPUT);
  digitalWrite(BuzzerPin, LOW);
  if (bmp.begin()) {
    Serial.println();
    Serial.println("BMP180 initialization successful");
    for (int i = 0; i <= buzzerbeeptime; i++) {
      digitalWrite(BuzzerPin, HIGH);
      delay(buzzerdelay);
      digitalWrite(BuzzerPin, LOW);
      delay(buzzerdelay);
    }
  }

else {
    Serial.println();
    Serial.println(" --- Could not find a valid BMP180 sensor, check wiring! --- ");
    digitalWrite(BuzzerPin, HIGH);
    delay(buzzererrordelay);
    digitalWrite(BuzzerPin, LOW);
  }
  base = bmp.readPressure();
  flight();
}

void loop() {}

int getAltitude() {
  alti = round(bmp.readAltitude(base));
  Serial.print(F("MAIN: "));
  Serial.print(alti);
  Serial.println(F("m"));
  return alti;
}

void getNMEA() {
  Serial.println();
  while (ss.available() > 0) {
    Serial.write(ss.read());
  }
  Serial.println();
}
int mpux() {
  mpu6050.update();
  xangle = abs(mpu6050.getAngleX());
  return xangle;
}
int mpuz() {
  mpu6050.update();
  zangle = abs(mpu6050.getAngleZ());
  return zangle;
}
int mpuaccy() {
  mpu6050.update();
  yacc = mpu6050.getAccY();
  return yacc;
}

void flight () {
s1: delay(delaytime); getAltitude(); getNMEA();
  Serial.print(F("MAIN: <=")); Serial.print(startingaltitude); Serial.print(F("m ")); Serial.print(F("(")); Serial.print(alti); Serial.println(F("m)"));
  if (alti > startingaltitude) {
    Serial.print(F("MAIN: THRESHOLD ALTITUDE EXCEEDED ")); Serial.print(F("(>")); Serial.print(startingaltitude); Serial.print(F("m)"));
s2: delay(delaytime); mpuaccy(); getAltitude(); getNMEA();
    if ( yacc < thresholdacc) {
      Serial.println(F("MAIN: ACCELERATION THRESHOLD EXCEEDED, SLOWING DOWN"));
s3: delay(delaytime); mpux(); mpuz(); getAltitude(); getNMEA();
      if ( xangle > thresholdangle || zangle > thresholdangle) {
        Serial.print(F("MAIN: ")); Serial.print(thresholdangle); Serial.println(F(" DEGREE DETECTED, MAIN 1 EJECTING"));
        servo1.write(servoangle);
        delay(afterdeploytime);
s4: delay(delaytime); getAltitude(); getNMEA();
        if (alti < seconderaltitude1) {
          Serial.print(F("MAIN: ALTITUDE <=")); Serial.print(seconderaltitude1); Serial.print(F("m"));
s5: delay(delaytime); getAltitude(); getNMEA();
          if (alti < seconderaltitude2) {
            Serial.print(F("MAIN: ALTITUDE <=")); Serial.print(seconderaltitude2); Serial.print(F("m"));
s6: delay(delaytime); getAltitude(); getNMEA();
            if (alti < seconderaltitude3) {
              Serial.print(F("MAIN: ALTITUDE <=")); Serial.print(seconderaltitude3); Serial.print(F("m, MAIN 2 EJECTING"));
              servo2.write(servoangle);
              delay(afterdeploytime);
s7: delay(delaytime); mpuaccy(); getAltitude(); getNMEA();
              if (yacc > safeacc) {
                Serial.print(F("MAIN: ACCELERATION ")); Serial.print(yacc); Serial.println(F("m/s^2, SAFE"));
s8: delay(delaytime); getAltitude(); getNMEA(); 
                if (alti < groundaltitude) {
                  getAltitude(); getNMEA();
                  Serial.println(F("MAIN: LANDED"));
                }
                else {
                  goto s8;
                }
              }
              else {
                Serial.print(F("MAIN: ACCELERATION "));
                Serial.print(yacc);
                Serial.println(F("m/s^2, HIGH ACCELERATION"));
                goto s7;
              }
            }
            else {
              goto s6;
            }
          }
          else {
            goto s5;
          }
        }
        else {
          goto s4;
        }
      }
      else {
        goto s3;
      }
    }
    else {
      goto s2;
    }
  }
  else {
    goto s1;
  }
}

Thanks for editing. I attached a photo. The altitude data decreases violently. Can I solve this by replacing the BMP180 on 10DOF? I mean, just mechanically.

Did you fix the problem of having two sensors with the same I2C address?

jremington:
Did you fix the problem of having two sensors with the same I2C address?

No, I did't. It is a bit urgent and I have no chance to make any of the sensors malfunction.