Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

BMP085


  • Please log in to reply
9 replies to this topic

#1 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 18 December 2012 - 06:54 PM

hello! maybe someone can help me: i can read the temerature and pressure / altitude. but how can i combine them to get (more?) accurate altitude? maybe anyone knows the formula for this ? greetings

#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 18 December 2012 - 07:50 PM

This is the code I'm using. First you need your sealevel pressure to be accurate with Altitude. It's never going to be as accurate as an altimeter.

bpSensor.SeaLevelPressure = 101325; // This is the World Wide ISO

Then my Calculation Method is: (you should be able to extract what you need).

    	public bool CalculateValues()
    	{
        	double X1, X2, B5, B6, X3, B3, P, UT, UP;
        	double B4, B7;

        	//1)   Start temperature measurement
        	I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[1];
        	xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { (byte)Register.BMP085_CTRL_MEAS_REG, (byte)Register.BMP085_T_MEASURE });
        	if (Write(xActions, 100) != 2)
            	return false;

        	//2)	Wait 4.5ms
        	Thread.Sleep(5);

        	//3)   Read UT
        	I2CDevice.I2CTransaction[] xActions2 = new I2CDevice.I2CTransaction[2];
        	xActions2[0] = I2CDevice.CreateWriteTransaction(new byte[] { (byte)Register.BMP085_ADC_OUT_MSB_REG });
        	byte[] RawData = new byte[2];
        	xActions2[1] = I2CDevice.CreateReadTransaction(RawData);
        	if (Write(xActions2, 100) != 3)
            	return false;
        	UT = (Int32)((Int32)(RawData[0] << 8) + (Int32)(RawData[1]));

        	//4)   Start pressure measurement
        	xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { (byte)Register.BMP085_CTRL_MEAS_REG, (byte)(((int)_overSampling << 6) + (byte)Register.BMP085_P_MEASURE) });
        	if (Write(xActions, 100) != 2)
            	return false;

        	//5)   wait (depends on mode)
        	Thread.Sleep(GetWaitTime());

        	//6)   Read UP
        	xActions2[0] = I2CDevice.CreateWriteTransaction(new byte[] { (byte)Register.BMP085_ADC_OUT_MSB_REG });
        	byte[] RawData2 = new byte[3];
        	xActions2[1] = I2CDevice.CreateReadTransaction(RawData2);
        	if (Write(xActions2, 100) != 4)
            	return false;
        	UP = (((Int32)(RawData2[0]) << 16) + ((Int32)(RawData2[1]) << 8) + (Int32)RawData2[2]) >> (8 - (int)_overSampling);

        	//7)   Calculate pressure and temperarure in physical units
        	X1 = ((UT - AC6) * AC5) / System.Math.Pow(2, 15);
        	X2 = (MC * System.Math.Pow(2, 11)) / (X1 + MD);
        	B5 = X1 + X2;
        	Temperature = (B5 + 8) / System.Math.Pow(2, 4);

        	// Temperature is calculated in 0.1C units, so divide by 10
        	Temperature = Temperature / 10;
        	// Convert C to F
        	Temperature = (Temperature * 1.8) + 32;

        	B6 = B5 - 4000;
        	X1 = (AC2 * B6) / System.Math.Pow(2, 11);
        	X2 = (B2 * ((B6 * B6) / System.Math.Pow(2, 12))) / System.Math.Pow(2, 11);
        	X3 = X1 + X2;
        	B3 = (Int32)(
            	(
            	(int)(AC1 * 4 + X3) << ((int)_overSampling + 2) / 4)
            	);
        	X1 = (AC3 * B6) / System.Math.Pow(2, 13);
        	X2 = (B1 * (B6 * B6 / System.Math.Pow(2, 12)) / System.Math.Pow(2, 16));
        	X3 = ((X1 + X2) + 2) / System.Math.Pow(2, 2);
        	B4 = AC4 * (UInt32)(X3 + 32768) / System.Math.Pow(2, 15);
        	B7 = ((UInt32)(UP - B3)) * (UInt32)(50000 >> (int)_overSampling);
        	P = (B7 < 0x80000000) ? (Int32)((B7 * 2) / B4) : (Int32)((B7 / B4) * 2);
        	X1 = (P / System.Math.Pow(2, 8)) * (P / System.Math.Pow(2, 8));
        	X1 = (X1 * 3038) / System.Math.Pow(2, 16);
        	X2 = (-7357 * P) / System.Math.Pow(2, 16);
        	Pressure = P + ((X1 + X2 + 3791) / System.Math.Pow(2, 4));
        	AbsoluteAltitude = (44330.75 * (1 - System.Math.Pow((double)Pressure / SeaLevelPressure, (1 / 5.255))));
        	// Convert Meters to Feet
        	AbsoluteAltitude = AbsoluteAltitude * 3.28;

        	xActions = null;
        	xActions2 = null;
        	return true;
    	}


#3 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 18 December 2012 - 10:31 PM

i have more or less the same, i wanted to know how i can add the temperature into the altitude function :( //edit: you also should get a nice i2c class.

Attached Files



#4 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 11 March 2013 - 09:47 PM

i have more or less the same, i wanted to know how i can add the temperature into the altitude function Posted Image

//edit: you also should get a nice i2c class.

 

Hey Noom, not sure why I missed this post.  Probably as this was my birthday week and I was crazy busy.  Did you ever figure out how to do the temperature / altitude with the BMP085?  If not, let me know and I'll try to code it up.  I am not using the temp but I basically know how to get it.



#5 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 12 March 2013 - 01:56 AM

i can read it out, yes, thats simple.

 

i wondered if there is a formula to make it more precise with the temerature calculating into it.

 

but well, i dont really use it anymore, so no need for investing any further, thx anyways



#6 NeverCast

NeverCast

    New Member

  • Members
  • Pip
  • 6 posts

Posted 12 March 2013 - 02:44 AM

Temperature is atmospheric, nothing to do with altitude?



#7 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 12 March 2013 - 04:15 AM

sure, the bmp is a pressure sensor, and iam very sure temperature affects air pressure



#8 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 12 March 2013 - 12:58 PM

The higher the temperature of the air, the faster it rises and loses density, decreasing the barometric pressure. The cooler it is, the denser the air becomes. This causes the barometric pressure to rise. Hotter temperatures generally mean lower pressure. This relationship doesn't hold true for every instance of temperature vs. barometric pressure.

#9 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 12 March 2013 - 02:45 PM

ok, thanks for the explanation.

 

yeah i was looking for a formula that calculated this, cos i thought (and still think) it has a reason the bmp has a temerature sensor also



#10 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 12 March 2013 - 07:23 PM

http://en.wikipedia....metric_equation

 

Cheers!

 

I should clarify.

 

Posted Image

 

This equation is for measuring the thickness of a layer of atmosphere. For altimetry, we'll measure the layer from ground level to where your instrument is. Use p1 as the pressure at ground level and p2 for the pressure where your instrument is. R is the gas constant, T is the average temperature of the layer, and g is the acceleration due to Earth's gravity.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.