problemilla mezclando 2 codigos

Muy buenas!

Pues vereis. Tengo un problema haciendo copy paste con 2 codigos. Necesito agregar a un codigo parte de otro. El tema es que soy un burro con esto de arduino y da errores.
A ve si me podeis echar una mano.
Los codigos son los siguientes.

/*Based largely on code by  Jim Lindblom

  Get pressure, altitude, and temperature from the BMP085.
  Serial.print it out at 9600 baud to serial monitor.
*/

#include <Wire.h>

#define BMP085_ADDRESS 0x77  // I2C address of BMP085

const unsigned char OSS = 0;  // Oversampling Setting
String temp, SerialDegC;
// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;

// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  SerialDegC += char(176);           // Setup a Degrees C Serial symbol
  SerialDegC += "C ";

  bmp085Calibration();
}

void loop()
{
  float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first
  float pressure = bmp085GetPressure(bmp085ReadUP());
  float atm = pressure / 101325; // "standard atmosphere"
  float altitude = calcAltitude(pressure); //Uncompensated caculation - in Meters


  Serial.print("Baro: ");
  Serial.print('\n');
  Serial.print(pressure / 100, 1); // correccion +1 milibatr y un decimal
  Serial.print(" mB");
  Serial.print('\n');
  Serial.print("Temp:   ");
  Serial.print('\n');
  Serial.print(temperature - 2, 1 ); //correccion (-2) y un decimal
  Serial.print(" ");
  Serial.println(SerialDegC);
  Serial.print('\n');



  delay(5000);

}

// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
  ac1 = bmp085ReadInt(0xAA);
  ac2 = bmp085ReadInt(0xAC);
  ac3 = bmp085ReadInt(0xAE);
  ac4 = bmp085ReadInt(0xB0);
  ac5 = bmp085ReadInt(0xB2);
  ac6 = bmp085ReadInt(0xB4);
  b1 = bmp085ReadInt(0xB6);
  b2 = bmp085ReadInt(0xB8);
  mb = bmp085ReadInt(0xBA);
  mc = bmp085ReadInt(0xBC);
  md = bmp085ReadInt(0xBE);
}

// Calculate temperature in deg C
float bmp085GetTemperature(unsigned int ut) {
  long x1, x2;

  x1 = (((long)ut - (long)ac6) * (long)ac5) >> 15;
  x2 = ((long)mc << 11) / (x1 + md);
  b5 = x1 + x2;

  float temp = ((b5 + 8) >> 4);
  temp = temp / 10 - 1.5;

  return temp;
}

// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up) {
  long x1, x2, x3, b3, b6, p;
  unsigned long b4, b7;

  b6 = b5 - 4000;
  // Calculate B3
  x1 = (b2 * (b6 * b6) >> 12) >> 11;
  x2 = (ac2 * b6) >> 11;
  x3 = x1 + x2;
  b3 = (((((long)ac1) * 4 + x3) << OSS) + 2) >> 2;

  // Calculate B4
  x1 = (ac3 * b6) >> 13;
  x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
  x3 = ((x1 + x2) + 2) >> 2;
  b4 = (ac4 * (unsigned long)(x3 + 32768)) >> 15;

  b7 = ((unsigned long)(up - b3) * (50000 >> OSS));
  if (b7 < 0x80000000)
    p = (b7 << 1) / b4;
  else
    p = (b7 / b4) << 1;

  x1 = (p >> 8) * (p >> 8);
  x1 = (x1 * 3038) >> 16;
  x2 = (-7357 * p) >> 16;
  p += (x1 + x2 + 3791) >> 4;

  long temp = p;
  return temp;
}

// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
  unsigned char data;

  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();

  Wire.requestFrom(BMP085_ADDRESS, 1);
  while (!Wire.available())
    ;

  return Wire.read();
}

// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
  unsigned char msb, lsb;

  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();

  Wire.requestFrom(BMP085_ADDRESS, 2);
  while (Wire.available() < 2)
    ;
  msb = Wire.read();
  lsb = Wire.read();

  return (int) msb << 8 | lsb;
}

// Read the uncompensated temperature value
unsigned int bmp085ReadUT() {
  unsigned int ut;

  // Write 0x2E into Register 0xF4
  // This requests a temperature reading
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x2E);
  Wire.endTransmission();

  // Wait at least 4.5ms
  delay(5);

  // Read two bytes from registers 0xF6 and 0xF7
  ut = bmp085ReadInt(0xF6);
  return ut;
}

// Read the uncompensated pressure value
unsigned long bmp085ReadUP() {

  unsigned char msb, lsb, xlsb;
  unsigned long up = 0;

  // Write 0x34+(OSS<<6) into register 0xF4
  // Request a pressure reading w/ oversampling setting
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x34 + (OSS << 6));
  Wire.endTransmission();

  // Wait for conversion, delay time dependent on OSS
  delay(2 + (3 << OSS));

  // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
  msb = bmp085Read(0xF6);
  lsb = bmp085Read(0xF7);
  xlsb = bmp085Read(0xF8);

  up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8 - OSS);

  return up;
}

void writeRegister(int deviceAddress, byte address, byte val) {
  Wire.beginTransmission(deviceAddress); // start transmission to device
  Wire.write(address);       // write register address
  Wire.write(val);         // write value to write
  Wire.endTransmission();     // end transmission
}

int readRegister(int deviceAddress, byte address) {

  int v;
  Wire.beginTransmission(deviceAddress);
  Wire.write(address); // register to read
  Wire.endTransmission();

  Wire.requestFrom(deviceAddress, 1); // read a byte

  while (!Wire.available()) {
    // waiting
  }

  v = Wire.read();
  return v;
}

float calcAltitude(float pressure) {

  float A = pressure / 101325;
  float B = 1 / 5.25588;
  float C = pow(A, B);
  C = 1 - C;
  C = C / 0.0000225577;

  return C;
}

El segundo codigo al que estoy agregado las lineas es:

#include <DS1307RTC.h>

#include <Time.h>

#include <SD.h>
#include <SPI.h>
#include <Wire.h>




/*#include <dht.h>

#include <Wire.h>
#include <SD.h>

#include "Time.h" 
#include "DS1307RTC.h"

*/


#include <DHT22.h>
// Only used for sprintf
#include <stdio.h>

#define BMP085_ADDRESS 0x77  // I2C address of BMP085

const unsigned char OSS = 0;  // Oversampling Setting
String temp, SerialDegC;

// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;

// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;

// Data wire is plugged into port 2 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)

//#define DHT11_PIN 4
#define DHT22_PIN 2


DHT22 myDHT22(DHT22_PIN);




//Delay between recording new sensor readings in milliseconds
//Remember to bare in mind that this won't include the time
//the device takes to execute the code (i.e. 1 or 2 secs) which
//will be added onto the sampling delay to give the sample rate.
//Range 0 -> 4 294 967 295
//600000 ms = 10 mins
//unsigned long sampleDelay = 600000;
unsigned long sampleDelay = 600000; //Time to wait between general temperature readings
//MAke sure that sampleDelay is longer than maxRetrys * readDelay!!!!!
unsigned long readDelay = 2000; //Time to wait between attempts to read DHT22
unsigned long numberRetrys = 3;




boolean DEBUG_MODE = true;


int count = 0;

void setup()
{
  //Wire.begin();
  Serial.begin(9600);
  pinMode(53, OUTPUT);
  SD.begin(53);
  Wire.begin();
  SerialDegC += char(176);           // Setup a Degrees C Serial symbol
  SerialDegC += "C ";
  
bmp085Calibration();
  
  
  
  
  Serial.println("starting");
  Serial.println("DHT TEST PROGRAM STALKER LOG5");
  Serial.print("LIBRARY VERSION: ");

  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
  
  //setTime(17,24,0,13,2,14); // set time to 17:05:00  1 Mar 2010 (see below)
  //RTC.set(now());  // set the RTC to the current time (set in the previous line)
  // format for setting time - setTime(hr,min,sec,day,month,yr);


  setSyncProvider(RTC.get);   // the function to get the time from the RTC




}
void loop()
{
  
   
  if (DEBUG_MODE == true) {
    Serial.println("starting"); 
    
    Serial.print( "The time is ");
   
    Serial.print( year() );    
    Serial.write('/');
     
    Serial.print( month() );  
    Serial.write('/');
    
    
    Serial.print( day() );    
    Serial.write(' ');
     
    Serial.print( hour() );    
    Serial.write(':');
    
    
    Serial.print( minute() );    
    Serial.write(':');
    Serial.println( second() );
  }
  

  
DHT22_ERROR_t errorCode;
Serial.print("Requesting data...");
 
count = 0;
 while (errorCode != DHT_ERROR_NONE && count < numberRetrys) {
   
    // The sensor can only be read from every 1-2s, and requires a minimum
    // 2s warm-up after power-on.
    delay(readDelay);

    count++;
    Serial.println("# of trys to read data");
    Serial.println(count);
    errorCode = myDHT22.readData();
    switch(errorCode)
    {
      case DHT_ERROR_NONE:
        Serial.print("Got Data ");
        Serial.print(myDHT22.getTemperatureC());
        Serial.print("C ");
        Serial.print(myDHT22.getHumidity());
        Serial.println("%");
        // Alternately, with integer formatting which is clumsier but more compact to store and
  	  // can be compared reliably for equality:
  	  //	  
        char buf[128];
        sprintf(buf, "Integer-only reading: Temperature %hi.%01hi C, Humidity %i.%01i %% RH",
                     myDHT22.getTemperatureCInt()/10, abs(myDHT22.getTemperatureCInt()%10),
                     myDHT22.getHumidityInt()/10, myDHT22.getHumidityInt()%10);
        Serial.println(buf);
        break;
      case DHT_ERROR_CHECKSUM:
        Serial.print("check sum error ");
        Serial.print(myDHT22.getTemperatureC());
        Serial.print("C ");
        Serial.print(myDHT22.getHumidity());
        Serial.println("%");
        break;
      case DHT_BUS_HUNG:
        Serial.println("BUS Hung ");
        break;
      case DHT_ERROR_NOT_PRESENT:
        Serial.println("Not Present ");
        break;
      case DHT_ERROR_ACK_TOO_LONG:
        Serial.println("ACK time out ");
        break;
      case DHT_ERROR_SYNC_TIMEOUT:
        Serial.println("Sync Timeout ");
        break;
      case DHT_ERROR_DATA_TIMEOUT:
        Serial.println("Data Timeout ");
        break;
      case DHT_ERROR_TOOQUICK:
        Serial.println("Polled to quick ");
        break;
    }
    
    if (errorCode != DHT_ERROR_NONE) {
        //delay(2000);
        Serial.println("Failed to get data ");
    }

  }
    
  
  //Record the data in th SD card  
   File dataFile = SD.open("DHT22.txt", FILE_WRITE); //Creat a file to record the temperature data 
   if (dataFile) {
 
    dataFile.print(year());     
    dataFile.print('/');
    dataFile.print( month() );  
    dataFile.print('/');
    dataFile.print( day() );    
    dataFile.print(' ');
    dataFile.print( hour() );    
    dataFile.print(':'); 
    dataFile.print( minute() );    
    dataFile.print(':'); 
    dataFile.print( second() );
    dataFile.print( ',' );
  
    dataFile.print(errorCode);
    dataFile.print( ',' );

    dataFile.print(myDHT22.getHumidity());
    dataFile.print( ',' );
        
    dataFile.print(myDHT22.getTemperatureC());
    dataFile.println( ',' );
    
    dataFile.close();
    
    // Print to the serial port 
    //Serial.print(DHT.humidity,1);
    //Serial.print(DHT.temperature,1);
  }  
  // If the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
  //}
  
  
  
  delay(sampleDelay-(count*readDelay)); //Delay until next sensor reading  
}

Del primero estoy agregando al segundo las lineas de codigo para poder hacer que grabe en la sd los datos del sensor BMP085.
Se que despues tengo que agregar algunas lineas de mas para que lo haga, pero eso se como conseguirlo ya que me fijo en como lo hace el segundo codigo.

A ve si encontrais una solucion porque me estoy volviendo loco.

Gracias y saludos