Everything STOPs code [PROBLEM] BMP180

If you are familiar with BMP180 it's a Pressure / temperature sensor pins: A5,A4.
I've been using lately BMP180 with the BMP085 library, here is the code:

BMP085 Lib Code:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
   which provides a common 'type' for sensor data and some helper functions.
   
   To use this driver you will also need to download the Adafruit_Sensor
   library and include it in your libraries folder.

   You should also assign a unique ID to this sensor for use with
   the Adafruit Sensor API so that you can identify this particular
   sensor in any data logs, etc.  To assign a unique ID, simply
   provide an appropriate value in the constructor below (12345
   is used by default in this example).
   
   Connections
   ===========
   Connect SCL to analog 5
   Connect SDA to analog 4
   Connect VDD to 3.3V DC
   Connect GROUND to common ground
    
   History
   =======
   2013/JUN/17  - Updated altitude calculations (KTOWN)
   2013/FEB/13  - First version (KTOWN)
*/
   
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

/**************************************************************************/
/*
    Displays some basic information on this sensor from the unified
    sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
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);
}

/**************************************************************************/
/*
    Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Pressure Sensor Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!bmp.begin())
  {
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
}

/**************************************************************************/
/*
    Arduino loop function, called once 'setup' is complete (your own code
    should go here)
*/
/**************************************************************************/
void loop(void) 
{
  /* Get a new sensor event */ 
  sensors_event_t event;
  bmp.getEvent(&event);
 
  /* Display the results (barometric pressure is measure in hPa) */
  if (event.pressure)
  {
    /* Display atmospheric pressue in hPa */
    Serial.print("Pressure:    ");
    Serial.print(event.pressure);
    Serial.println(" hPa");
    
    /* Calculating altitude with reasonable accuracy requires pressure    *
     * sea level pressure for your position at the moment the data is     *
     * converted, as well as the ambient temperature in degress           *
     * celcius.  If you don't have these values, a 'generic' value of     *
     * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA   *
     * in sensors.h), but this isn't ideal and will give variable         *
     * results from one day to the next.                                  *
     *                                                                    *
     * You can usually find the current SLP value by looking at weather   *
     * websites or from environmental information centers near any major  *
     * airport.                                                           *
     *                                                                    *
     * For example, for Paris, France you can check the current mean      *
     * pressure and sea level at: http://bit.ly/16Au8ol                   */
     
    /* First we get the current temperature from the BMP085 */
    float temperature;
    bmp.getTemperature(&temperature);
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");

    /* Then convert the atmospheric pressure, and SLP to altitude         */
    /* Update this next line with the current SLP for better results      */
    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    Serial.print("Altitude:    "); 
    Serial.print(bmp.pressureToAltitude(seaLevelPressure,
                                        event.pressure)); 
    Serial.println(" m");
    Serial.println("");
  }
  else
  {
    Serial.println("Sensor error");
  }
  delay(1000);
}

Here is the same code but without the extra stuffs that I don't need:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>  
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);


void setup(){
  Serial.begin(9600);
  
  if(!bmp.begin())
  {
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
}

void loop(){
  sensors_event_t event;
  bmp.getEvent(&event);
 

  if (event.pressure)
  {

    Serial.print("Pressure:    ");
    Serial.print(event.pressure);
    Serial.println(" hPa");
    
    float temperature;
    bmp.getTemperature(&temperature);
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");

    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    Serial.print("Altitude:    "); 
    Serial.print(bmp.pressureToAltitude(seaLevelPressure,
                                        event.pressure)); 
    Serial.println(" m");
    Serial.println("");
  }
  delay(1000);
}

What's my problem?
If you look in the SETUP you will see

if(!bmp.begin())
  {
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }

The problem is this lines of code, without them the BMP is not working so you need to keep this
but if you use extra components on your arduino like other I2C sensors or simple sensors or motors or anything else and you have this code without using (unplug) the BMP, the bmp.begin() sees that the sensor is not plugged and stops everything.

What I mean it stops everything? nothing is running, it's like freezing all the chip, all the code.

Are you familiar with BMP180/code is there something to do about that?
about that specific line of code

Have you thought of using i2cdev instead?

You seem to be keen on wasting RAM too - the F() macro is useful in educating you otherwise.

Domino60:
and you have this code without using (unplug) the BMP, the bmp.begin() sees that the sensor is not plugged and stops everything.

That's what it is intended to do. if you want it to behave differently you need to change the program. The line

while(1);

is what is causing it to stop

...R

No, it is not bmp.begin() that sots the code, it is the while (1);.

Remove it and the 'problem' is gone.

That's what it is intended to do. if you want it to behave differently you need to change the program. The line
while(1);
is what is causing it to stop

No, it is not bmp.begin() that sots the code, it is the while (1);.

Remove it and the 'problem' is gone.

This post gave me cancer :smiley: made me look like a noob, facepalm

I delete the while(1) and it's working but even like that, what's then the point keeping the

if(!bmp.begin())
  {}

I don't understand.. ?!

Have you thought of using i2cdev instead?

You mean calling the BMP180 thru Addresses and registers? I tried and gave up :smiley:

This post gave me cancer :smiley: made me look like a noob, facepalm

I must admit, I saw the post count and assumed you'd seen that.

I delete the while(1) and it's working but even like that, what's then the point keeping the

Because you need to call the " begin" method?

You mean calling the BMP180 thru Addresses and registers?

Yes.
Why not? - it's really very simple.

Yes.
Why not? - it's really very simple.

I tried using I2C calling each sensor from the I2C thru sensor Addresses and registers but it took me long
time how to do it how everything is working so I tried, really I tried but I thought after that I need to put formulas/calculations but all that it's already in the libraries.

So what I done is calling the sensor inside a function running it thru millis() once per second, I got about 3 sensors in the I2C all of them calling them like that, same way thru I2C using Lib's they work pretty good.

You can create a boolean variable and then use it later, to control whether the program should "use" the BMP. That makes it an option that you don't have to configure.

if(!bmp.begin())
  {
    BMPInstalled = true;
  }
  else
  {
    Serial.print("no BMP085 detected");
    BMPInstalled = false;
  }

//...
if (BMPInstalled)
{ // use it...}