BMP 180 pressure sensor and connecting two Arduinos I2C issue

Hi everyone,

I’d like to ask you about some issue I’ve lately seen. I have my pressure sensor (BMP 180/ GY-68) connected to the Arduino Pro Mini (I2C slave) that is supposed to read the data, calculate this to the altitude and store the highest result. The other Arduino (Uno) is the master which is to read the stored int value from the slave and show it on the 16x2 LCD display. There aren’t any other significant things in this circuit. Unluckily, apart from that it theoretically works, I sometimes see some odd data like -256m and just after that e.g. 3688m. Sometimes it doesn’t occur at all. Pull-up resistors are the ones integrated with the BMP 180: 4.7K each. Without connecting the other board, the data seems to be clear. What may cause this problem?

The master’s code:

#include <Wire.h>
#include <LiquidCrystal.h>

#define ReadSwitch 12
#define LED 13


LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(ReadSwitch, INPUT_PULLUP);
  ///////////////////////////////////
  lcd.begin(16, 2);
  lcd.setCursor(4, 0);
  lcd.print("CONNECT");
  lcd.setCursor(4, 1);
  lcd.print("ALTIMETER");
  digitalWrite(LED, HIGH);


  Wire.begin();
}
//////////////////////////////
void loop()
{
  bool flag1 = 0; //to reduce blinking
  byte p[2];
  int result;
  delay(30);
  Wire.requestFrom(0x21, 2, true);
  if (Wire.available() == 2)
  {
    for (int i = 0; i < 2; i++)
    {
      p[i] = Wire.read();
    }
    result = (p[0] | p[1] << 8);
  }

  if (digitalRead(ReadSwitch) == LOW)
  {
    if (result != -32768)
    {
      if (!flag1)
      {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("MAX:  ");
        flag1 = 1;
      }

      lcd.print(result);
      lcd.print("m");
      digitalWrite(LED, LOW);
    }
    else
    {
      flag1 = 0;
      lcd.clear();
      lcd.setCursor(6, 0);
      lcd.print("READING");
      lcd.setCursor(5, 1);
      lcd.print("PROBLEM");

      digitalWrite(LED, 0);
      delay (30);
      digitalWrite(LED, 1);
      delay (30);
      digitalWrite(LED, 0);
      delay (30);
      digitalWrite(LED, 1);
      delay (30);
      digitalWrite(LED, 0);
      delay (30);
      digitalWrite(LED, 1);
      delay (30);
      digitalWrite(LED, 0);
      delay (30);
      
    }
  }
  else
  {
    flag1 = 0;
    digitalWrite(LED, HIGH);
    lcd.clear();
    lcd.setCursor(4, 0);
    lcd.print("CONNECT");
    lcd.setCursor(4, 1);
    lcd.print("ALTIMETER");

  }
  delay(500);
}

The slave’s code:

#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <Wire.h>
#define LED 13
#define SWITCH A0

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
float basicPressure = 0;
int altit, maximum;

void setup()
{
  pinMode(LED, OUTPUT);

  if (!bmp.begin())
  {
    while (1)
    {
      digitalWrite(LED, HIGH);
      delay(200);
      digitalWrite(LED, LOW);
      delay(200);
      digitalWrite(LED, HIGH);
      delay(200);
      digitalWrite(LED, LOW);
      delay(200);
    }
  }
  digitalWrite(LED, HIGH);
  
  sensors_event_t event;
  bmp.getEvent(&event);
  basicPressure = event.pressure;


  maximum = -32768;

  Wire.begin(0x21);
  Wire.onRequest(altitudeTransmission);
}

//////////////////////////////
void loop()
{
  sensors_event_t event;
  bmp.getEvent(&event);
  int altit = bmp.pressureToAltitude(basicPressure, event.pressure);
  if (altit > maximum)
  {
    maximum = altit;
  }
  delay(20);
}
/////////////////////////////
void altitudeTransmission()
{
  if (maximum >= 0)
  {
    byte part1 = ((int)maximum);
    byte part2 = ((int)maximum) >> 8;

    Wire.write(part1);
    Wire.write(part2);
  }
  else
  {
    Wire.write((-32768));
    Wire.write((-32768 >> 8));
  }
}

The original Adafruit’s library is used with parts taken from it’s example. If you have some idea, share it, please.

Cheers

What you do in your setup is a multimaster I2C bus (for the sensor the Pro Mini is the master, for the Pro Mini the UNO is the master). The Wire library doesn’t support this.

Why don’t you just read the BMP180 from the UNO? What the reason for the Pro Mini?

Thank you, you're probably right. I'll try to modify my code. I need as small board as possible because I want to use it in RC planes.

That would rule out the UNO. In any way I don’t see the necessity to have two Arduinos working, one should be enough to read a sensor.