Sensors working together

Hi,

I have Arduino Uno connected to three sensors:

  • BMP085 barometric pressure sensor
  • MMA8452 accelerometer
  • Pololu L3GD20 Gyro

All of the above sensors work by themselves. but when all are connected together , the BMP showes numbers that are not logical

(Temperature : -13421773.00 , Altitude -15102 meters).

Accelerometer and gyro readings are good.

all of the sensors share the SDA and SCL pins (analog 4 & 5).

any ideas how to solve this ?

Thanks !

any ideas how to solve this ?

Posting your code would be a good first step.

#include <SD.h>
#include <Wire.h>
#include <L3G.h>
#include <MMA8453_n0m1.h>
#include <Time.h>
#include <Adafruit_BMP085.h>
#include <TMRpcm.h>  

MMA8453_n0m1 accel;
L3G gyro;
Adafruit_BMP085 bmp;
TMRpcm tmrpcm; 
File myFile;

/*******************************************************************************************************************************************/

void setup() {
  Serial.begin(9600);
  tmrpcm.speakerPin = 9; //Set speaker output pin to 9  
  /* from here it is the gyro init */
  Wire.begin();
  Wire.beginTransmission(GYRO_1_WRITE);
  Wire.write(byte(0x20));
  Wire.write(0xFF);
  Wire.endTransmission();
  if (!gyro.init())
  {
    Serial.println("Failed to autodetect gyro type!");
    while (1);
  }
  /* from here it is SD and accelerometer init  */
  accel.setI2CAddr(0x1D); //change your device address if necessary, default is 0x1C
  accel.dataMode(true, 4); //enable highRes 10bit, 2g range [2g,4g,8g]		
  if (!SD.begin(10)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  pinMode(10, OUTPUT);

} 

/*******************************************************************************************************************************************/

AGA CheckSensors() {
  AGA result;
  accel.update();
  result.acc.x = accel.x();
  result.acc.y = accel.y();
  result.acc.z = accel.z();
  gyro.read(); 
  result.gyro.x = (int)gyro.g.x;
  result.gyro.y = (int)gyro.g.y;
  result.gyro.z = (int)gyro.g.z;
  /*result.alt = bmp.readAltitude(); // in brackets , sea level bar pressure for autocorrect*/
  return result;
}

/*******************************************************************************************************************************************/

int CompRes(AGA q1, AGA q2)
{
  AGA Limt; // Set the limits of alert
  Limt.acc.x = 5;
  Limt.acc.y = 5;
  Limt.acc.z = 5;
  Limt.gyro.x = 120;
  Limt.gyro.y = 120;
  Limt.gyro.z = 120;
  Limt.alt = 4;
  int save = 0;
  if ((abs(q2.acc.x - q1.acc.x))>(Limt.acc.x)) 
  {
    save = 1; 
  }
  else if ((abs(q2.acc.y - q1.acc.y))>(Limt.acc.y)) 
  {
    save = 2; 
  }
  else if ((abs(q2.acc.z - q1.acc.z))>(Limt.acc.z)) 
  {
    save = 3; 
  }
  else if ((abs(q2.gyro.x - q1.gyro.x))>(Limt.gyro.x)) 
  {
    save = 4; 
  }
  else if ((abs(q2.gyro.y - q1.gyro.y))>(Limt.gyro.y)) 
  {
    save = 5; 
  }
  else if ((abs(q2.gyro.z - q1.gyro.z))>(Limt.gyro.z)) 
  {
    save = 6; 
  }
  //else if ((abs(q2.alt - q1.alt))>(Limt.alt)) 
  //    {save = 1; }
  else (save=0);
  return save;


}
/*******************************************************************************************************************************************/

void PRTF(AGA f,int time) {
  // prints the result to the text file
  Serial.print(time); 
  Serial.print(" seconds ");
  Serial.print(" Acceleration ");
  Serial.print(" x: ");
  Serial.print(f.acc.x);
  Serial.print(" y: ");
  Serial.print(f.acc.y);
  Serial.print(" z: ");
  Serial.print(f.acc.z);
  Serial.print(" Gyro ");
  Serial.print(" x: ");
  Serial.print(f.gyro.x);
  Serial.print(" y: ");
  Serial.print(f.gyro.y);
  Serial.print(" z: ");
  Serial.println(f.gyro.z);
  Serial.print(" Altitude ");
  Serial.println(f.alt);
  Serial.print(" Temp ");
  Serial.println(bmp.readTemperature());
  ; 
}


/*******************************************************************************************************************************************/


void loop() {
  AGA q1;
  AGA q2;
  int time;
  boolean save;
  delay(500);
  q1 = CheckSensors();
  delay(500);
  q2 = CheckSensors();
  save = CompRes(q1,q2);
  time = now();
  if (save >= 1)
  {
    PRTF(q2,time);
    myFile = SD.open("record.txt", FILE_WRITE);
    if (myFile) {
      myFile.print(time); 
      myFile.print(", seconds ");
      myFile.print(", Acceleration ");
      myFile.print(",x: ,");
      myFile.print(q2.acc.x);
      myFile.print(",y: ,");
      myFile.print(q2.acc.y);
      myFile.print(",z: ,");
      myFile.print(q2.acc.z);
      myFile.print(", Gyro ");
      myFile.print(",x: ,");
      myFile.print(q2.gyro.x);
      myFile.print(",y: ,");
      myFile.print(q2.gyro.y);
      myFile.print(",z: ,");
      myFile.println(q2.gyro.z);
      /*  myFile.print(", Altitude ,");
       myFile.print(q2.alt);
       myFile.print(", Temp ,");
      /*myFile.print(bmp.readTemperature());*/
      myFile.close();
    }
    /*tmrpcm.play("Cparis.wav"); */

  }
  /* Serial.print(", device moved: ,");
   Serial.print(save); */

  delay(100);
}

Moderator edit: Code auto-formatted for legibility.

I would add supply decoupling capacitors on each sensor for a start.

If the work separately , and not together,

I would give some thought to the number of resistors that are there, trying to "pull up" the two I2C signal lines. If the resistance to the upper voltage is too low, the device will be incapable of pulling the voltage level down, to make a signal.

Those nonsense signals from the BMP085 probably correspond to getting all 1's or all 0's from the device, because the data transmission has not actually been successful at all.

I would give some thought to the number of resistors that are there, trying to "pull up" the two I2C signal lines.

My guess is that the OP has exactly none. In which case one resistor from the I2C clock line to +5V and another from the I2C data line to +5V. I would use 4K7 resistors.

Thanks for the replys! , I will try and report. ( I do not have any resistors , so it will take me a bit of time to try)

To be clear , all sensors work OK when working alone (all are connected , but a different code that uses only one of them . for example , the BMP085 example gives good readings , and all other sensors are still connected to the arduino board.)

there are currently no resistors or capacitors connected to the system.

Thanks again,

Lack of pullup resistor's would explain that. The arduino has internal pullups but they are only 30K. That might be enough to pull up one device but not three.