Sparkfun support will be closed from 3:00PM to 4:15PM on April 27th for a company-wide townhall meeting. We will resume regular hours on the 28th.

Member #362659

Member Since: September 19, 2012

Country: United States

  • Hi, I am trying to make a data logger using this and the bmp085 pressure sensor. When I output the variables on a serial port it comes up with the correct data but when I write it to a sd card, it always prints: Temperature = 12.80 *C Pressure = 99977 Pa Altitude = 70.78 meters

    every single minute it will print this even though on a serial port it will work. Can someone help me please?
    btw this is my code:

    /* BMP085 Extended Example Code by: Jim Lindblom SparkFun Electronics date: 1/18/11 license: CC BY-SA v3.0 - http://creativecommons.org/licenses/by-sa/3.0/

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

    Update (7/19/11): I’ve heard folks may be encountering issues with this code, who’re running an Arduino at 8MHz. If you’re using an Arduino Pro 3.3V/8MHz, or the like, you may need to increase some of the delays in the bmp085ReadUP and bmp085ReadUT functions. */





    Sd2Card card; SdVolume volume; SdFile root; SdFile file;

    define BMP085_ADDRESS 0x77 // I2C address of BMP085

    const float p0 = 101325; // Pressure at sea level (Pa) float altitude; const unsigned char OSS = 0; // Oversampling Setting char name[] = “data.txt”; //Create an array that contains the name of our file. char contents[256]; //This will be a data buffer for writing contents to the file. char in_char=0; int index=0; //Index will keep track of our position within the contents buffer. // 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; int time=0; int oldtime = 0;

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

    short temperature; long pressure;

    void setup() { Serial.begin(9600); Wire.begin(); bmp085Calibration(); pinMode(10, OUTPUT); card.init(); //Initialize the SD card and configure the //I/O pins. volume.init(card); //Initialize a volume on the SD card. root.openRoot(volume); //Open the root directory in the volume. file.open(root, name, O_CREAT | O_APPEND | O_WRITE); file.println(); file.println(); file.println(“———-NEW SESSION———-”); file.println(); file.println(); file.close(); }

    void loop() { temperature = bmp085GetTemperature(bmp085ReadUT()); pressure = bmp085GetPressure(bmp085ReadUP());

    Serial.print(temperature, DEC); file.open(root, name, O_CREAT | O_APPEND | O_WRITE); //Open or create the file ‘name’ in ‘root’ for writing to the end of the file. file.print(“Time:”); file.print(time); file.print(“ mins”); file.println(); file.print(“Temperature = ”); file.print(temperature, DEC); file.println(“ *C”);

    file.print("Pressure = ");
    file.print(pressure, DEC);
    file.println(" Pa");

    altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295)); // Calculate altitude assuming ‘standard’ barometric // pressure of 1013.25 millibar = 101325 Pascal file.print(“Altitude = ”); file.print(altitude, 2); file.println(“ meters”);

    file.close();            //Close the file.

    int oldtime = ++time; delay(60000);


    // 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 given ut. // Value returned will be in units of 0.1 deg C short bmp085GetTemperature(unsigned int ut) { long x1, x2;

    x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15; x2 = ((long)mc >4);

    // 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)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 = (b78); x1 = (x1 * 3038)>>16; x2 = (-7357 * p)>>16; p += (x1 + x2 + 3791)>>4;

    return p; }

    // 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()

No public wish lists :(