Combined Codes for altimeter MS5607

Hello
I'm trying to get an Altimeter MS5607 to measure height, pressure and temperature (i know, that's what it always does, but I'm trying to get it to show me the temperature and pressure too). I also want it to save the measurements on an SD card, using the SD Breakout from Adafruit. Here are the codes to measure temperature+pressure and for height. They both work separately, but not combined.
I don't get any errors when I upload the code, but it doesn't show anything on the serial monitor. It would be really nice if someone could help me.

temperature + pressure

#include <Wire.h>
#define ADDRESS 0x77 //0x76

uint32_t D1 = 0;
uint32_t D2 = 0;
int32_t dT = 0;
int32_t TEMP = 0;
int64_t OFF = 0; 
int64_t SENS = 0; 
int32_t P = 0;
uint16_t C[7];

void setup() {
// Disable internal pullups, 10Kohms are on the breakout
 PORTC |= (1 << 4);
 PORTC |= (1 << 5);

  Wire.begin();
  Serial.begin(9600); //9600 changed 'cos of timing?
  delay(100);
  initial(ADDRESS);

}

void loop()
{
  D1 = getVal(ADDRESS, 0x48); // Pressure raw
  D2 = getVal(ADDRESS, 0x58);// Temperature raw

  dT = D2 - (C[4]*256);
  TEMP = 2000 + ((dT * C[5])/8388608);
  OFF  = ((C[1])<<16) + ((C[3] * dT) >> 7);
  SENS = ((C[0])<<15) + ((C[2] * dT) >> 8);
  P = ((D1 * SENS/2097152 - OFF)/32768)/100;


  Serial.print("     Actual TEMP= ");
  Serial.print(TEMP);
  Serial.print("      Actual PRESSURE= ");
  Serial.print(P);

  Serial.println();  
  Serial.print(" RAW Temp D2=  ");
  Serial.print(D2);
  Serial.print(" RAW Pressure D1=  ");
  Serial.println(D1);
  Serial.println();

  Serial.print(" dT=  ");
  Serial.println(dT);
  Serial.println();
  Serial.print(" C0/1=  ");
  Serial.println(C[0]);
  Serial.print(" C1/2=  ");
  Serial.println(C[1]);
  Serial.print(" C2/3=  ");
  Serial.println(C[2]); 
  Serial.print(" C3/4=  ");
  Serial.println(C[3]); 
  Serial.print(" C4/5=  ");
  Serial.println(C[4]); 
  Serial.print(" C5/6=  ");
  Serial.println(C[5]); 
  Serial.print(" C6/7=  ");
  Serial.println(C[6]); 
  Serial.print(" C7/8=  ");
  Serial.println(C[7]);
  Serial.println();

  delay(1000

    );
}

long getVal(int address, byte code)
{
  unsigned long ret = 0;
  Wire.beginTransmission(address);
  Wire.write(code);
  Wire.endTransmission();
  delay(10);
  // start read sequence
  Wire.beginTransmission(address);
  Wire.write((byte) 0x00);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.requestFrom(address, (int)3);
  if(Wire.available()) {
    //    ret = ((uint32_t)Wire.read() << 16) | ((uint32_t)Wire.read() << 8) | Wire.read();
    ret = Wire.read() * 65536 + Wire.read() * 256 + Wire.read();
  }
  else {
    ret = -1;
  }
  Wire.endTransmission();
  return ret;
}

void initial(uint8_t address)
{

  Serial.println();
  Serial.println("PROM COEFFICIENTS ivan");

  Wire.beginTransmission(address);
  Wire.write(0x1E); // reset
  Wire.endTransmission();
  delay(10);


  for (int i=0; i<7  ; i++) {

    Wire.beginTransmission(address);
    Wire.write(0xA2 + (i * 2));
    Wire.endTransmission();

    Wire.beginTransmission(address);
    Wire.requestFrom(address, (uint8_t) 6);
    delay(1);
    if(Wire.available()) {

      C[i] = Wire.read() *256 + Wire.read();
    }
    else {
      Serial.println("Error reading PROM 1"); // error reading the PROM or communicating with the device
    }
    Serial.println(C[i]);
  }
  Serial.println();
}

Height + save it on an SD card

#include <SD.h> // to use Adafruit SD breakout board
#include <Wire.h> // to use I2C
#include "IntersemaBaro.h" // to use Altimeter Module MS5607
#define BUTTON 7 // Button wordt uitgelezen aan poort 7
File dataFile; // declaration of dataFile

const int chipSelect = 10; //Arduino Nano uses CS = 10
unsigned long time = 0; // declaration of time variable
int val = LOW; // variabele waarde button, initieel low
//int old_val = LOW; // variabele waarde button na cyclus in void loop
//int bezig = HIGH; // variabele om na te gaan of button actief is
Intersema::BaroPressure_MS5607B baro(true);

void setup() { 
  Serial.begin(9600); // setting the bit rate per second
  baro.init(); // initialising the Altimeter Module MS5607

  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT); // needed for the SD card, making SPI connection
  pinMode (BUTTON,INPUT); // Button is input voor poort 7
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  
  // adding a header to the file data.txt
  dataFile = SD.open("data.txt", FILE_WRITE); // open the file data.txt
  dataFile.print("time (s)"); 
  dataFile.print("\t"); // add tab
  dataFile.print("height (cm)"); 
  dataFile.println(); // carriage return
  dataFile.close(); //close file data.txt
} 

void loop() {
  val = digitalRead (BUTTON); // lees waarde button
  if ((val == HIGH)) { // als button aanstaat en eerste cyclus van de void loop sinds het aanzetten nog niet voltooid is
  
  
  //bezig = digitalRead(BUTTON); //nagegaan of button nog steeds aanstaat
  time = millis();
  
  int alt = baro.getHeightCentiMeters(); //measure height in centimeter
   
  dataFile = SD.open("data.txt", FILE_WRITE); // open the file data.txt
  dataFile.print(time); // print time
  dataFile.print("\t"); // add tab
  dataFile.print((float)(alt)); // print altitude
  dataFile.println(); // add empty line
  dataFile.close(); // close file data.txt
  
    
  // print to the serial port too:
  Serial.print((time)); // print time
  Serial.print("\t"); // add tab
  Serial.print("height (cm): ");
  Serial.print((float)(alt)); // print altitude
  Serial.println(); // carriage return
  delay(1000);

  }
}

This is the combined code that doesn't work.

#include <SD.h> // to use Adafruit SD breakout board
#include <Wire.h> // to use I2C
#include "IntersemaBaro.h" // to use Altimeter Module MS5607
#define BUTTON 7 // Button wordt uitgelezen aan poort 7
#define ADDRESS 0x77 //0x76
File dataFile; // declaration of dataFile

uint32_t D1 = 0;
uint32_t D2 = 0;
int32_t dT = 0;
int32_t TEMP = 0;
int64_t OFF = 0; 
int64_t SENS = 0; 
int32_t P = 0;
uint16_t C[7];

const int chipSelect = 10; //Arduino Nano uses CS = 10
unsigned long time = 0; // declaration of time variable
int val = LOW; // variabele waarde button, initieel low
//int old_val = LOW; // variabele waarde button na cyclus in void loop
//int bezig = HIGH; // variabele om na te gaan of button actief is
Intersema::BaroPressure_MS5607B baro(true);

void setup() { 
  Serial.begin(9600); // setting the bit rate per second
  baro.init(); // initialising the Altimeter Module MS5607

  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT); // needed for the SD card, making SPI connection
  pinMode (BUTTON,INPUT); // Button is input voor poort 7
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  
  // adding a header to the file data.txt
  dataFile = SD.open("data.txt", FILE_WRITE); // open the file data.txt
  dataFile.print("time (s)"); 
  dataFile.print("\t"); // add tab
  dataFile.print("height (cm)"); 
  dataFile.println(); // carriage return
  dataFile.close(); //close file data.txt
  
  // Disable internal pullups, 10Kohms are on the breakout
 PORTC |= (1 << 4);
 PORTC |= (1 << 5);

  Wire.begin();
  Serial.begin(9600); //9600 changed 'cos of timing?
  delay(100);
  initial(ADDRESS);
} 

void loop() {
  val = digitalRead (BUTTON); // lees waarde button
  if ((val == HIGH)) { // als button aanstaat en eerste cyclus van de void loop sinds het aanzetten nog niet voltooid is
  
  
  //bezig = digitalRead(BUTTON); //nagegaan of button nog steeds aanstaat
  time = millis();
  
  int alt = baro.getHeightCentiMeters(); //measure height in centimeter
   
  dataFile = SD.open("data.txt", FILE_WRITE); // open the file data.txt
  dataFile.print(time); // print time
  dataFile.print("\t"); // add tab
  dataFile.print((float)(alt)); // print altitude
  dataFile.println(); // add empty line
  dataFile.close(); // close file data.txt
  
    
  // print to the serial port too:
  Serial.print((time)); // print time
  Serial.print("\t"); // add tab
  Serial.print("height (cm): ");
  Serial.print((float)(alt)); // print altitude
  Serial.println(); // carriage return
  delay(1000);

  }
  
   D1 = getVal(ADDRESS, 0x48); // Pressure raw
  D2 = getVal(ADDRESS, 0x58);// Temperature raw

  dT = D2 - (C[4]*256);
  TEMP = 2000 + ((dT * C[5])/8388608);
  OFF  = ((C[1])<<16) + ((C[3] * dT) >> 7);
  SENS = ((C[0])<<15) + ((C[2] * dT) >> 8);
  P = ((D1 * SENS/2097152 - OFF)/32768)/100;


  Serial.print("     Actual TEMP= ");
  Serial.print(TEMP);
  Serial.print("      Actual PRESSURE= ");
  Serial.print(P);

  Serial.println();  
  Serial.print(" RAW Temp D2=  ");
  Serial.print(D2);
  Serial.print(" RAW Pressure D1=  ");
  Serial.println(D1);
  Serial.println();

  Serial.print(" dT=  ");
  Serial.println(dT);
  Serial.println();
  Serial.print(" C0/1=  ");
  Serial.println(C[0]);
  Serial.print(" C1/2=  ");
  Serial.println(C[1]);
  Serial.print(" C2/3=  ");
  Serial.println(C[2]); 
  Serial.print(" C3/4=  ");
  Serial.println(C[3]); 
  Serial.print(" C4/5=  ");
  Serial.println(C[4]); 
  Serial.print(" C5/6=  ");
  Serial.println(C[5]); 
  Serial.print(" C6/7=  ");
  Serial.println(C[6]); 
  Serial.print(" C7/8=  ");
  Serial.println(C[7]);
  Serial.println();

  delay(1000

    );
}

long getVal(int address, byte code)
{
  unsigned long ret = 0;
  Wire.beginTransmission(address);
  Wire.write(code);
  Wire.endTransmission();
  delay(10);
  // start read sequence
  Wire.beginTransmission(address);
  Wire.write((byte) 0x00);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.requestFrom(address, (int)3);
  if(Wire.available()) {
    //    ret = ((uint32_t)Wire.read() << 16) | ((uint32_t)Wire.read() << 8) | Wire.read();
    ret = Wire.read() * 65536 + Wire.read() * 256 + Wire.read();
  }
  else {
    ret = -1;
  }
  Wire.endTransmission();
  return ret;
}

void initial(uint8_t address)
{

  Serial.println();
  Serial.println("PROM COEFFICIENTS ivan");

  Wire.beginTransmission(address);
  Wire.write(0x1E); // reset
  Wire.endTransmission();
  delay(10);


  for (int i=0; i<7  ; i++) {

    Wire.beginTransmission(address);
    Wire.write(0xA2 + (i * 2));
    Wire.endTransmission();

    Wire.beginTransmission(address);
    Wire.requestFrom(address, (uint8_t) 6);
    delay(1);
    if(Wire.available()) {

      C[i] = Wire.read() *256 + Wire.read();
    }
    else {
      Serial.println("Error reading PROM 1"); // error reading the PROM or communicating with the device
    }
    Serial.println(C[i]);
  }
  Serial.println();
}

Hi SHD_Squad,

I'm at the moment experimenting with the same setup (intersemabaro.h with sd.h), and experiencing the exact same issues.

As a last resort I reverted to Arduino IDE 1.0.1 instead of 1.0.4, and everything suddenly worked!

My setup:
arduino uno, ms5607 breakout board connected to A4&A5, ethernet-shield with SD-card.

Hope this helps.

Cheers,
Lude

ps: if you need more info, please send me an email, I hardly ever look on this forum.

And it's broken again.

What arduino board are you using?

After some digging I found out it's because of the amount of available SRAM memory. Wire.h and SD.h take up a lot of memory (and so does the sdFat libary). Upgrading to a the mega, or using a smaller sd-car library should do the trick (for me).

Please post your seperate code online. Thanks