Adafruit BMP183 SPI Altitude Sensor not retrieving correct altitude value

I"m using a Adafruit BMP183 SPI Altitude Sensor in a arduino project. The sensor works when I run the example program and gets correct results, but when I use the same code in my program I get weird values for altitude, i get varying negative values.

/*00000000      Libraries included    00000000*/
#include <SerialGraphicLCD.h>
#include <SoftwareSerial.h>
#include "DHT.h"
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP183.h>
#include <DS3234.h>

/*00000000      GLCD screen size  00000000*/
#define maxX 127//159 
#define maxY 63 //127

/*00000000   BMPsensor  00000000*/
#define BMP183_CLK  13  // AKA CLK
#define BMP183_SDO  12  // AKA MISO
#define BMP183_SDI  11  // AKA MOSI
#define BMP183_CS   4
Adafruit_BMP183 bmp = Adafruit_BMP183(BMP183_CLK, BMP183_SDO, BMP183_SDI, BMP183_CS);
volatile float pressure_mmHg;
volatile float pressurepascal;
volatile float Altitude;
volatile float last_microsBMP;
float seaLevelPressure;

/*00000000   DeadOn time chip  00000000*/
volatile int TimeDate [7]; //second,minute,hour,null,day,month,year
const int CSpin=10;
const int MOSIpin=11;
const int MISOpin=12;
const int CLKpin=13;
float last_microsTime;

/*00000000    DHT sensor stuff    00000000*/
#define DHTPIN 9     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);
volatile float humidity=0;
volatile float airtemp=0;
volatile float heatindex=0;
volatile float last_microsDHT;

/*00000000      variables for PINS    00000000*/
//Bup Bdown Bleft Bright Bcenter But1 But2 But3
//const int ledPin13 = 13;       // the number of the LED pin

/*00000000    variables for debounce    00000000*/
long debouncing_time = 250; //Debouncing delay coefficent
long last_micros;
int state = LOW;

/*00000000    variables for menus    00000000*/


/*00000000    LCD class declaration    00000000*/
LCD LCD;

/*00000000    CoSensor declaration    00000000*/
volatile int CoCode;
volatile int CoLevel;
float last_microsCO;
/*00000000    SETUP    00000000*/

void setup()
{
  pinMode(5, INPUT_PULLUP);     //button on pin 5
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  
  Serial.begin(9600);
  
  attachInterrupt(0, debounce, FALLING); //interrupt
  
//  pinMode(ledPin13, OUTPUT);   // pin 13 on board LED

  RTC.configure(MOSIpin,MISOpin,CLKpin,CSpin);
//  RTC.setDateTime(18,9,2014,23,28,0); // RTC.setDateTime(int d, int mo, int y, int h, int mi, int s);
  dht.begin();
  bmp.begin();

//RTC.setDateTime(24, 10, 2014, 23, 17, 0); // int d, int mo, int y, int h, int mi, int s

  //splash screen
  LCD.setBacklight(20);
  LCD.clearScreen();
  LCD.setHome();
  LCD.printStr(" Program starts in "); //displays "program is starting in 5/4/3/2/1 etc"
    for(int i = 5; i >= 0; i--) 
      {
        LCD.setX(113);
        LCD.setY(0);
        LCD.printNum(i);
        delay(500);
      } 
  LCD.clearScreen(); 
  delay(200);
}

/*00000000    LOOP    00000000*/

void loop(void)
{   
Serial.print("\n");   
Serial.print("Altitude:    "); 
Serial.print(bmp.getAltitude(seaLevelPressure)); 
Serial.println(" m");
Serial.println("");
/*Serial.print("\n"); 
Serial.print(Altitude);
Serial.println(" m");
Serial.println("");
*/
delay(50);

SensorUpdate();     //update all sensors including time
MainMenuDisplay();
BOXSELECTOR();
//menu_select();
//sensor_menu();
//time_menu();

}

void SensorUpdate()
{
  Battery();
  delay(100);
  ClockRead();
  delay(100);
  DHTsensor();
  delay(100);
  CoSensor();
  delay(100);
  BMPsensor();
  delay(100);
}

/*00000000   debounce functions    00000000*/

void debounce() 
{
  if(((long)(micros() - last_micros) >= debouncing_time * 2000) || last_micros==0)
  {
    state = !state;
    //digitalWrite(13, state);
    last_micros = micros();
    //buttontest();
  }
}

void buttontest()
{
    if(digitalRead(5)==LOW)
    {sensor_menu();}
    
    if(digitalRead(6)==LOW)
    {time_menu();}
    
    if(digitalRead(7)==LOW)
    {/*multimeter();*/}
    
    if(digitalRead(8)==LOW)
    {/*sleep();*/}    
    
    if(digitalRead(9)==LOW)
    {MainMenuDisplay();}    
    
    if(digitalRead(10)==LOW)
    {/*BUTTON10=true;*/}    
}

void MainMenuDisplay()
{
optionrowdisplay(); //display info on glcd
TimeDisplay(0,0,0,0);      //Display Time on glcd
Menubuttons_MenuOptions();
}

void BOXSELECTOR()
{
LCD.drawBox(4,53,0,47,0);//x1,y1,x2,y2  draw box on S Sensor
LCD.drawBox(3,52,1,48,0);
LCD.drawBox(2,51,2,49,0);
delay(50);

}
void CoSensor()
{
  if((long)micros() - last_microsCO >= 100000 || last_microsCO==0) // Wait a few seconds between measurements. //delay(1000);
  {
  CoLevel = analogRead(A5);// 10k resistor noramlizes in basement at 70
  
  if(CoLevel<300)
    {CoCode=1;}
  else if(CoLevel>301 && CoLevel<800)
    {CoCode=2;}
  else if(CoLevel>801)
    {CoCode=3;}
  }
last_microsCO=micros();  
}

void Battery()
{
}

void ClockRead()
{
RTC.readDateTime(); //DD.MM.YYYY-hh.mm.ss
/*
RTC.time_h(); // hour
RTC.time_m(); // minutes
RTC.time_s(); // seconds
RTC.date_d(); // day
RTC.date_m(); // month
RTC.date_y(); // year
RTC.readTemp();
RTC.setDateTime(int d, int mo, int y, int h, int mi, int s);
*/
TimeDate[2]=RTC.time_h(); //2.1.0 hour minute second
TimeDate[1]=RTC.time_m();
TimeDate[0]=RTC.time_s();
TimeDate[5]=RTC.date_d(); // day
TimeDate[4]=RTC.date_m(); // month
TimeDate[3]=RTC.date_y()-2000; // year
}
  

/*0000000000000000000      BMPsensor     00000000000000000000000000000*/

void BMPsensor() 
{
 if((long)micros() - last_microsBMP >= 100500 || last_microsBMP==0) // Wait a few seconds between measurements. //delay(2050);
 {
    /* Display atmospheric pressue in Pascals */
    //float pressurepascal;
    //float pressure_mmHg;
    pressurepascal=bmp.getPressure();
    pressure_mmHg=pressurepascal*(0.0002953);

    // Pressure bmp.getPressure() Pascals
    // Pressure (bmp.getPressure() / 100) millibar (hPa)
    // Pressure (pressure_mmHg); millimeter Mercury (mmHg)
    
    /* First we get the current temperature from the BMP085 */
    float temperatureF;
    float temperatureC;
    temperatureC =bmp.getTemperature();
    temperatureF=(temperatureC*(1.8))+32; //    F = C * 180 + 32

    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; // should be ~1000
    seaLevelPressure=1011;
    //SENSORS_PRESSURE_SEALEVELHPA millibar/hPa
    Altitude=bmp.getAltitude(seaLevelPressure); // meters
 }
last_microsBMP=micros();
}

/*0000000000000000000      DHTsensor     00000000000000000000000000000*/

void DHTsensor() 
{
  if((long)micros() - last_microsDHT >= 100100 || last_microsDHT==0) // Wait a few seconds between measurements. //delay(2100);
      {
      // Reading temperature or humidity takes about 250 milliseconds!
      // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      float h = dht.readHumidity();
      humidity=dht.readHumidity();
      // Read temperature as Celsius
      float t = dht.readTemperature();
      // Read temperature as Fahrenheit
      float f = dht.readTemperature(true);
      airtemp=dht.readTemperature(true);
      // Check if any reads failed and exit early (to try again).
      if (isnan(h) || isnan(t) || isnan(f)) 
        {
          Serial.println("Failed to read from DHT sensor!");
          //last_micros2=micros();
          return;
        }
      
      // Compute heat index
      // Must send in temp in Fahrenheit!
      float hi = dht.computeHeatIndex(f, h);
      heatindex=dht.computeHeatIndex(f, h);
      }
      last_microsDHT=micros();
}

GLCD_menu_with_interrupts_V19_SPI_no_menus.ino (7.08 KB)

wrist_libraries.ino (9.61 KB)

here is the second file with the display code.

/*00000000000000              menu display       00000000000000000000000*/
void optionrowdisplay()
{ 
  LCD.setHome(); //Battery
  LCD.printStr("BATT ");
  delay(35);
  LCD.setX(25);
  LCD.setY(00);
  LCD.printNum(100);
  delay(35);
  LCD.setX(45);
  LCD.setY(00);
  LCD.printStr("%");
  delay(35);
  
  LCD.drawBox(55,0,56,8,1);//(x1,y1,x2,y2,1)
  delay(35);
  
  LCD.setX(60); //Humidity
  LCD.setY(0);
  LCD.printStr("Humidity");
  delay(35);
  LCD.setX(110);
  LCD.setY(0);
  LCD.printNum(humidity);
  delay(35);
  LCD.setX(122);
  LCD.setY(0);
  LCD.printStr("%");
  delay(35);
  
  LCD.setX(0); //Bar pressure
  LCD.setY(10);
  LCD.printStr("BP");
  delay(35);
  LCD.setX(15);
  LCD.setY(10);
  LCD.printNum(pressure_mmHg);
  delay(35); 
  LCD.setX(28);
  LCD.setY(10);
  LCD.printStr("mmHg");
  delay(35);
  
  LCD.drawBox(55,9,56,18,1);//(x1,y1,x2,y2,1)
  delay(35);

  LCD.setX(60); //Temp
  LCD.setY(10);
  LCD.printStr("Temp");
  delay(35);
  LCD.setX(86);
  LCD.setY(10);
  LCD.printNum(airtemp);
  delay(35);
  LCD.setX(98);
  LCD.setY(10);
  LCD.printStr("/");
  delay(35);
  LCD.setX(104);
  LCD.setY(10);
  LCD.printNum(heatindex);
  delay(35);
  LCD.setX(116);
  LCD.setY(10);
  LCD.printStr("*");
  delay(35);
  LCD.setX(122);
  LCD.setY(10);
  LCD.printStr("F");
  delay(35);

if(Altitude<10 && Altitude>=1) //between 1 and 10
{
  LCD.setX(0); //altitude
  LCD.setY(20);
  LCD.printStr("ALA");
  delay(35);
  LCD.setX(22);
  LCD.setY(20);
  LCD.printNum(0);
  delay(35);
  LCD.setX(28);
  LCD.setY(20);
  LCD.printNum(Altitude);
  delay(35);
  LCD.setX(37);
  LCD.setY(20);
  LCD.printStr("m");
  delay(35);
}
else if(Altitude>10 && Altitude<99) //between 10 and 99  || Altitude<1
{
  LCD.setX(0); //altitude
  LCD.setY(20);
  LCD.printStr("ALB");
  delay(35);
  LCD.setX(22);
  LCD.setY(20);
  LCD.printNum(Altitude);
  delay(35);
  LCD.setX(37);
  LCD.setY(20);
  LCD.printStr("m");  
  delay(35);
}
else if(Altitude>99)
{
  LCD.setX(0); //altitude
  LCD.setY(20);
  LCD.printStr("ALC");
  LCD.setX(22);
  LCD.setY(20);
  LCD.printNum(Altitude);
  delay(35);
  LCD.setX(43);
  LCD.setY(20);
  LCD.printStr("m");  
  delay(35);
}
else if(Altitude<1)
{
  LCD.setX(0); //altitude
  LCD.setY(20);
  LCD.printStr("ALD");
  LCD.setX(18);
  LCD.setY(20);
  LCD.printNum(Altitude);
  delay(35);
  LCD.setX(48);
  LCD.setY(20);
  LCD.printStr("m");  
  delay(35);
}
  LCD.drawBox(55,19,56,26,0);//(x1,y1,x2,y2,1)
  delay(35);
  
  LCD.setX(60); //CO level
  LCD.setY(20);
  LCD.printStr("CO");
  delay(35);
  LCD.setX(73); //CO level
  LCD.setY(20);
  LCD.printStr("Level");
  delay(35);

LCD.eraseBlock(103, 20, 127, 27);

switch (CoCode) 
{
    case 1:
      LCD.setX(103);
      LCD.setY(20);
      LCD.printStr("GOOD");
      delay(35);
      break;
    case 2:
      LCD.setX(108);
      LCD.setY(20);
      LCD.printStr("OK");
      delay(35);
      break;
    case 3: 
      LCD.setX(105);
      LCD.setY(20);
      LCD.printStr("BAD");
      delay(35);
      break;
  }

  LCD.setX(0);
  LCD.setY(29);
  LCD.printStr("<-");
  delay(35);
  LCD.setX(12);
  LCD.setY(29);
  LCD.printStr("PW");
  delay(35);
  
  LCD.drawBox(27,28,28,36,0);//(x1,y1,x2,y2,1)
  delay(35);
  LCD.drawBox(94,28,95,36,0);//(x1,y1,x2,y2,1)
  delay(35);

  LCD.setX(0);
  LCD.setY(38);
  LCD.printStr("<-");
  delay(35);
  LCD.setX(12);
  LCD.setY(38);
  LCD.printStr("DIAL");
  delay(35);
   
  LCD.drawBox(36,37,37,44,0);//(x1,y1,x2,y2,1)
  delay(35); 

  LCD.setX(100); //UP BUTTON
  LCD.setY(29);
  LCD.printStr("UP");
  delay(35);
  LCD.setX(115); //UP Arrow
  LCD.setY(29);
  LCD.printStr("->");
  delay(35);
  
  LCD.drawBox(86,37,87,44,0);//(x1,y1,x2,y2,1)
  delay(35); 
  
  LCD.setX(90); //Down BUTTON
  LCD.setY(38);
  LCD.printStr("DOWN");
  delay(35);
  LCD.setX(115); //DOWN arrow
  LCD.setY(38);
  LCD.printStr("->");
  delay(35);
} 

void Menubuttons_MenuOptions()
{
  LCD.setX(0); //Sensor Clock Meter Sleep menu options
  LCD.setY(47);
  LCD.printStr("Sensor");  
  delay(35);
  LCD.setX(38); 
  LCD.setY(47);
  LCD.printStr("Time");
  delay(35);
  LCD.setX(65); 
  LCD.setY(47);
  LCD.printStr("Meter");
  delay(35);
  LCD.setX(97); 
  LCD.setY(47);
  LCD.printStr("Sleep");
  delay(25); 

  LCD.setX(0); //LEFT RIGHT ENTER BACK AND EXIT BUTTON
  LCD.setY(56);
  LCD.printStr("<- ->");
  delay(35);
  LCD.setX(36); 
  LCD.setY(56);
  LCD.printStr("ENTER");
  delay(35);
  LCD.setX(73); 
  LCD.setY(56);
  LCD.printStr("BACK");
  delay(25);
  LCD.setX(103); 
  LCD.setY(56);
  LCD.printStr("EXIT");
  delay(35); 
}

int TimeDisplay(int txstart, int tystart, int dxstart, int dystart)
{
  if((long)micros() - last_microsTime >= 500000 || last_microsTime==0) // Wait a few seconds between measurements. //delay(1000);
      {
        if(TimeDate[2]<10)  //hour
          {
            LCD.setX(txstart+39); 
            LCD.setY(tystart+29);
            LCD.printNum(TimeDate[2]); 
            delay(35);
          }
        else
          {
            LCD.setX(txstart+33);
            LCD.setY(tystart+29);
            LCD.printNum(TimeDate[2]); 
            delay(35);
          }

            LCD.setX(txstart+44);
            LCD.setY(tystart+29);
            LCD.printStr(":");//semicolon
            delay(35);
  
        if(TimeDate[1]<10) //minute
          {
            LCD.setX(txstart+50); 
            LCD.setY(tystart+29);
            LCD.printNum(0); 
            delay(35);
            LCD.setX(txstart+56); 
            LCD.setY(tystart+29);
            LCD.printNum(TimeDate[1]);
            delay(35);
          }
        else
          {
            LCD.setX(txstart+50); 
            LCD.setY(tystart+29);
            LCD.printNum(TimeDate[1]); 
            delay(35);
          }
          
            LCD.setX(txstart+61);
            LCD.setY(tystart+29);
            LCD.printStr(":");//semicolon
            delay(35);
  
       if(TimeDate[0]<10)  //second
         {
            LCD.setX(txstart+66);
            LCD.setY(tystart+29);
            LCD.printNum(0);
            delay(35);
            LCD.setX(txstart+72);
            LCD.setY(tystart+29);
            LCD.printNum(TimeDate[0]);
            delay(35);
         }
       else
         {
            LCD.setX(txstart+66);
            LCD.setY(tystart+29);
            LCD.printNum(TimeDate[0]);
            delay(35); 
         }

      if(TimeDate[2]<12)  //AM/PM
        {
            LCD.setX(txstart+79);
            LCD.setY(tystart+29);
            LCD.printStr("AM"); 
            delay(35);
        }
      else
        {
            LCD.setX(txstart+79);
            LCD.setY(tystart+29);
            LCD.printStr("PM");
            delay(25);
        }

if(TimeDate[4]<10)
        {
            LCD.setX(dxstart+45); //Date month
            LCD.setY(dystart+38);
            LCD.printNum(TimeDate[4]);
            delay(35);
        }
else if(TimeDate[4]>10)
        {
            LCD.setX(dxstart+38); //Date month
            LCD.setY(dystart+38);
            LCD.printNum(TimeDate[4]);
            delay(35);
        }

            LCD.setX(dxstart+50); // "/"  
            LCD.setY(dystart+38);
            LCD.printStr("/");
            delay(35);  
            
if(TimeDate[5]<10)
        {
            LCD.setX(dxstart+60); //Day
            LCD.setY(dystart+38);
            LCD.printNum(TimeDate[5]);
            delay(35);  
        }
else if(TimeDate[5]>9)
        {
            LCD.setX(dxstart+56); //Day
            LCD.setY(dystart+38);
            LCD.printNum(TimeDate[5]);
            delay(35);  
        } 
            
            LCD.setX(dxstart+68); // "/" 
            LCD.setY(dystart+38);
            LCD.printStr("/");
            delay(35);  
            
            LCD.setX(dxstart+74); //year
            LCD.setY(dystart+38);
            LCD.printNum(TimeDate[3]);
            delay(35);

        }    

}

}

I'm going to guess., looking at the amount of code you have, that you are running out of memory. You are going to confirm that:
http://playground.arduino.cc/Code/AvailableMemory