SparkFun will be closed Nov 26th and 27th for the Thanksgiving holiday. Orders placed after 2:00pm MT on the 25th will ship out Monday the 30th.
Track My Order
Frequently Asked Questions
International Shipping Info
Mon-Fri, 9am to 12pm and
1pm to 5pm U.S. Mountain Time:
Chat With Us
September 19, 2012
about 3 years ago
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
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
const float p0 = 101325; // Pressure at sea level (Pa)
const unsigned char OSS = 0; // Oversampling Setting
char name = “data.txt”; //Create an array that contains the name of our file.
char contents; //This will be a data buffer for writing contents to the file.
int index=0; //Index will keep track of our position within the contents buffer.
// Calibration values
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int oldtime = 0;
// b5 is calculated in bmp085GetTemperature(…), this variable is also used in bmp085GetPressure(…)
// so …Temperature(…) must be called before …Pressure(…).
card.init(); //Initialize the SD card and configure the
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);
temperature = bmp085GetTemperature(bmp085ReadUT());
pressure = bmp085GetPressure(bmp085ReadUP());
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(“Temperature = ”);
file.print("Pressure = ");
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.close(); //Close the file.
int oldtime = ++time;
// 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
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;
// Read 1 byte from the BMP085 at ‘address’
char bmp085Read(unsigned char address)
unsigned char data;
// 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;
No public wish lists :(
Forgot your password?
No account? Register one!