Connecting two BMP085 via I2C and XCLR: Measurements wrong

Hey there,

I'm trying to connect two BMP085 air pressure sensors to my arduino to measure the pressure difference between a room with negative pressure and the outside of that room, so i can calculate the pressure difference and monitor how big it is.

Both sensors seem to work fine if i connect only one of them. However if i start switching them on and off via XCLR they start to produce completely false output. All the readings are off. One sensor will always show too high values and one will always show too low values.

How i set it up:

2x Sensor GND to arduino GND
2x Sensor Vcc to arduino 3.3v
2 x SDA and SCL to arduino SDA and SCL
XCLR of one sensor to digital output 53, the other to digital out 51.

I'm using an arduino mega board.

Here's the code im using, i just modified the BMP085test example that adafruit included in their library. Sorry for the messy code, i'm kinda new to this still.

Adafruit_BMP085 bmp;

int internalpin = 53;
int externalpin = 51;
float rawpressint;
float rawtempint;
float avgpressint;
float avgtempint;
void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
	while (1) {}
  }
}
  
void loop() {
    //readsensorinternal
    pinMode(internalpin, OUTPUT);
    pinMode(externalpin, OUTPUT);
    int i = 0;
    rawpressint = 0;
    rawtempint = 0;
    digitalWrite(internalpin, HIGH);
    digitalWrite(externalpin, LOW); //Ext sensor abschalten
    delay(100);
    while(i<=15)
    {
      i++;
      rawpressint = rawpressint + bmp.readPressure();
      delay(20);
      rawtempint = rawtempint + bmp.readTemperature();
    }
    avgpressint = rawpressint / 16;
    Serial.println("Avg Press Int Sens");
    Serial.println(avgpressint);  
    avgtempint = rawtempint / 16;
    Serial.println("Avg Temp Int Sens");
    Serial.println(avgtempint);
    i = 0;
    float rawpressext = 0;
    float rawtempext = 0;
    digitalWrite(internalpin, LOW);
    digitalWrite(externalpin, HIGH); //Ext sensor anschalten
    delay(100);
    while(i<=15)
        {

      i++;
      rawpressext = rawpressext + bmp.readPressure();
      delay(20);
      rawtempext = rawtempext + bmp.readTemperature();
    }
    float avgpressext = rawpressext / 16;
    Serial.println("Avg Press ext Sens");
    Serial.println(avgpressext);  
    float avgtempext = rawtempext / 16;
    Serial.println("Avg Temp ext Sens");
    Serial.println(avgtempext);
    Serial.println("rawval");
    Serial.println(bmp.readTemperature());
    Serial.println(bmp.readPressure());

Edit: To prevent misunderstandings, the sensors are not yet installed in or outside the room, i just put them on my desk for testing right now.

Do i maybe need some sort of resistor between XCLR and arduino digital out?

Based on the datasheet the master clear (XCLR) low-active input is used to reset the BMP085 and it initializes internal registers and counters (the same as power-on reset).
So you have to completely initialize the sensors each time when using XCLR as a "chipselect"..

My understanding is keeping the LOW at XCLR will deselect the chip. So after enabling the chip with HIGH you have to do "bmp.begin()"..

thanks for your answer, i will try that once im home.

also i read that i'm supposed to reduce the xclr voltage to 3.3v using a voltage divider. however im still new to the concept of voltage dividers and didn't fully understand them.

so how do i build it? what type of resistor do i use? i was thinking a 1k resistor from digitalout to xclr and a 1.5k from xclr to gnd, would that work? or did i get it wrong?

also i read that i'm supposed to reduce the xclr voltage to 3.3v using a voltage divider. however im still new to the concept of voltage dividers and didn't fully understand them.

so how do i build it? what type of resistor do i use? i was thinking a 1k resistor from digitalout to xclr and a 1.5k from xclr to gnd, would that work? or did i get it wrong?

1kohm from atmega to XCLR
1.8kohm from XCLR to ground

The divider must create max 3.3V output from max 5V input.

I2C is limited to about 2 meters.
You could use an Arduino board per sensor. And connect the Arduino boards via serial (perhaps the SoftwareSerial library).

If you connected an Arduino output of 5V to the XCLR pin, the BMP085 could be damaged.

Using the resistors as pito wrote, should work.

This is another post about using XCLR, 2 x BMP085 on I2C - Sensors - Arduino Forum

You don't need the divider, there is a much more easier solution for this:

http://forum.arduino.cc/index.php?topic=77188.msg1477520#msg1477520

Basically you pull down the PIN with OUTPUT/LOW and leave it "floating" with INPUT/LOW. BMP085 has an internal pull up to 3.3, so you don't need it.

Vheers,

Tamas