Arduino 各种模块篇 大气压强模块 pressure sensor BMP085

this tutorial is very neat.

Mine is like this :

While the one from sparkfun is like this:

Anyway their circuit are almost the same.(The blue one's better for safty )

So the codes are functional for those two different coloured board.

BMP085 Pin Pin Function
VCC Power (1.8V-3.6V)
GND Ground
EOC End of conversion output
XCLR Master Clear (low-active)
SCL Serial Clock I/O
SDA

Serial Data I/O

 

Example wiring

BMP085 Pin Arduino Pin
VCC 3.3V
GND GND
SCL A5
SDA A4

For now, we're going to ignore XCLR and EOC, it's safe to just leave them unconnected.

 

For more info, YOU DO NEED : https://www.sparkfun.com/tutorials/253

You may need to download all the codes here here, (of one .ino arduino IDE file)

here's the codes:

  1 /* BMP085 Extended Example Code
  2   by: Jim Lindblom
  3   SparkFun Electronics
  4   date: 1/18/11
  5   updated: 2/26/13
  6   license: CC BY-SA v3.0 - http://creativecommons.org/licenses/by-sa/3.0/
  7   
  8   Get pressure and temperature from the BMP085 and calculate 
  9   altitude. Serial.print it out at 9600 baud to serial monitor.
 10 
 11   Update (7/19/11): I've heard folks may be encountering issues
 12   with this code, who're running an Arduino at 8MHz. If you're 
 13   using an Arduino Pro 3.3V/8MHz, or the like, you may need to 
 14   increase some of the delays in the bmp085ReadUP and 
 15   bmp085ReadUT functions.
 16 */
 17 
 18 #include <Wire.h>
 19 
 20 #define BMP085_ADDRESS 0x77  // I2C address of BMP085
 21 
 22 const unsigned char OSS = 0;  // Oversampling Setting
 23 
 24 // Calibration values
 25 int ac1;
 26 int ac2; 
 27 int ac3; 
 28 unsigned int ac4;
 29 unsigned int ac5;
 30 unsigned int ac6;
 31 int b1; 
 32 int b2;
 33 int mb;
 34 int mc;
 35 int md;
 36 
 37 // b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
 38 // so ...Temperature(...) must be called before ...Pressure(...).
 39 long b5; 
 40 
 41 short temperature;
 42 long pressure;
 43 
 44 // Use these for altitude conversions
 45 const float p0 = 101325;     // Pressure at sea level (Pa)
 46 float altitude;
 47 
 48 void setup()
 49 {
 50   Serial.begin(9600);
 51   Wire.begin();
 52   bmp085Calibration();
 53 }
 54 
 55 void loop()
 56 {
 57   temperature = bmp085GetTemperature(bmp085ReadUT());
 58   pressure = bmp085GetPressure(bmp085ReadUP());
 59   altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295));
 60 
 61   Serial.print("Temperature: ");
 62   Serial.print(temperature, DEC);
 63   Serial.println(" *0.1 deg C");
 64   Serial.print("Pressure: ");
 65   Serial.print(pressure, DEC);
 66   Serial.println(" Pa");
 67   Serial.print("Altitude: ");
 68   Serial.print(altitude, 2);
 69   Serial.println(" m");
 70   Serial.println();
 71   
 72   delay(1000);
 73 }
 74 
 75 // Stores all of the bmp085's calibration values into global variables
 76 // Calibration values are required to calculate temp and pressure
 77 // This function should be called at the beginning of the program
 78 void bmp085Calibration()
 79 {
 80   ac1 = bmp085ReadInt(0xAA);
 81   ac2 = bmp085ReadInt(0xAC);
 82   ac3 = bmp085ReadInt(0xAE);
 83   ac4 = bmp085ReadInt(0xB0);
 84   ac5 = bmp085ReadInt(0xB2);
 85   ac6 = bmp085ReadInt(0xB4);
 86   b1 = bmp085ReadInt(0xB6);
 87   b2 = bmp085ReadInt(0xB8);
 88   mb = bmp085ReadInt(0xBA);
 89   mc = bmp085ReadInt(0xBC);
 90   md = bmp085ReadInt(0xBE);
 91 }
 92 
 93 // Calculate temperature given ut.
 94 // Value returned will be in units of 0.1 deg C
 95 short bmp085GetTemperature(unsigned int ut)
 96 {
 97   long x1, x2;
 98   
 99   x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
100   x2 = ((long)mc << 11)/(x1 + md);
101   b5 = x1 + x2;
102 
103   return ((b5 + 8)>>4);  
104 }
105 
106 // Calculate pressure given up
107 // calibration values must be known
108 // b5 is also required so bmp085GetTemperature(...) must be called first.
109 // Value returned will be pressure in units of Pa.
110 long bmp085GetPressure(unsigned long up)
111 {
112   long x1, x2, x3, b3, b6, p;
113   unsigned long b4, b7;
114   
115   b6 = b5 - 4000;
116   // Calculate B3
117   x1 = (b2 * (b6 * b6)>>12)>>11;
118   x2 = (ac2 * b6)>>11;
119   x3 = x1 + x2;
120   b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
121   
122   // Calculate B4
123   x1 = (ac3 * b6)>>13;
124   x2 = (b1 * ((b6 * b6)>>12))>>16;
125   x3 = ((x1 + x2) + 2)>>2;
126   b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
127   
128   b7 = ((unsigned long)(up - b3) * (50000>>OSS));
129   if (b7 < 0x80000000)
130     p = (b7<<1)/b4;
131   else
132     p = (b7/b4)<<1;
133     
134   x1 = (p>>8) * (p>>8);
135   x1 = (x1 * 3038)>>16;
136   x2 = (-7357 * p)>>16;
137   p += (x1 + x2 + 3791)>>4;
138   
139   return p;
140 }
141 
142 // Read 1 byte from the BMP085 at 'address'
143 char bmp085Read(unsigned char address)
144 {
145   unsigned char data;
146   
147   Wire.beginTransmission(BMP085_ADDRESS);
148   Wire.write(address);
149   Wire.endTransmission();
150   
151   Wire.requestFrom(BMP085_ADDRESS, 1);
152   while(!Wire.available())
153     ;
154     
155   return Wire.read();
156 }
157 
158 // Read 2 bytes from the BMP085
159 // First byte will be from 'address'
160 // Second byte will be from 'address'+1
161 int bmp085ReadInt(unsigned char address)
162 {
163   unsigned char msb, lsb;
164   
165   Wire.beginTransmission(BMP085_ADDRESS);
166   Wire.write(address);
167   Wire.endTransmission();
168   
169   Wire.requestFrom(BMP085_ADDRESS, 2);
170   while(Wire.available()<2)
171     ;
172   msb = Wire.read();
173   lsb = Wire.read();
174   
175   return (int) msb<<8 | lsb;
176 }
177 
178 // Read the uncompensated temperature value
179 unsigned int bmp085ReadUT()
180 {
181   unsigned int ut;
182   
183   // Write 0x2E into Register 0xF4
184   // This requests a temperature reading
185   Wire.beginTransmission(BMP085_ADDRESS);
186   Wire.write(0xF4);
187   Wire.write(0x2E);
188   Wire.endTransmission();
189   
190   // Wait at least 4.5ms
191   delay(5);
192   
193   // Read two bytes from registers 0xF6 and 0xF7
194   ut = bmp085ReadInt(0xF6);
195   return ut;
196 }
197 
198 // Read the uncompensated pressure value
199 unsigned long bmp085ReadUP()
200 {
201   unsigned char msb, lsb, xlsb;
202   unsigned long up = 0;
203   
204   // Write 0x34+(OSS<<6) into register 0xF4
205   // Request a pressure reading w/ oversampling setting
206   Wire.beginTransmission(BMP085_ADDRESS);
207   Wire.write(0xF4);
208   Wire.write(0x34 + (OSS<<6));
209   Wire.endTransmission();
210   
211   // Wait for conversion, delay time dependent on OSS
212   delay(2 + (3<<OSS));
213   
214   // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
215   Wire.beginTransmission(BMP085_ADDRESS);
216   Wire.write(0xF6);
217   Wire.endTransmission();
218   Wire.requestFrom(BMP085_ADDRESS, 3);
219   
220   // Wait for data to become available
221   while(Wire.available() < 3)
222     ;
223   msb = Wire.read();
224   lsb = Wire.read();
225   xlsb = Wire.read();
226   
227   up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
228   
229   return up;
230 }

the Serial output when the data is approaching to a stable level:

Here i get Temperature, Pressure, Altitude.

I use google earth to find out at my position the altitude would be around 105 metres.

Either one is right.

Or other accurate sensors or measuring in other methods will give us the most right accurate result.

As we all know that the altitude is caculated out from the pressure.

in different seasons and on different weather, the pressure could be different.

So the altitude i got would not be very accurate.

Google earth maybe use the technology of promixity, ray or etc.. This result could be more accurate than that caculated out from the pressure inderectly.

 

Here we just have a test individually.

If I put the sensor into a bag and blow some air into the bag,

we will see :

The altitude will decrease.

Somehow it comes to an altitude below 0 metre(s). e.g. -13.23m ( coz there are too much air in the bag. The lower Altitude is, the higher air pressure will be. )

You could check it out. Temperature, Pressure, Altitude.

Here's the basic function

Equation to find altitude at a given pressure

Formula to find expected pressure at a given altitude

 

As for some info in Chinese language:

资料自行下载http://www.kuaipan.cn/file/id_61649243307246089.html

 

1、板载BMP085数字式气压传感器,内置AD转换器,支持IIC通信协议

 

2、模块可以测试大气气温和大气压强,

 

      PCB采用沉金工艺。pcb尺寸18.5mm*18mm

 

3、支持5V/3.3V电压输入

 

4、常用的引脚已经引出,插针为标准2.54mm

 

It's brief introduction :

BMP085 是一款高精度、超低能耗的压力传感器,可以应用在移动设备中。它的性能卓越,绝对精度最低可以达到0.03hPa,并且耗电极低,只有3μA。 BMP085采用强大的8-pin陶瓷无引线芯片承载(LCC)超薄封装,可以通过I2C总线直接与各种微处理器相连。


主要特点:

压力范围:300 - 1100hPa(海拔9000米至-500米)

电源电压:1.8V - 3.6V(VDDA)

1.62V - 3.6V(VDDD)

LCC8封装:无铅陶瓷载体封装(LCC)

尺 寸: 5.0mmx5.0x1.2mm

低功耗: 5μA 在标准模式

高精度: 低功耗模式下,分辨率为0.06hPa(0.5米)

高线性模式下,分辨率为0.03hPa(0.25米)

含温度输出

I2C接口

温度补偿

无铅,符合RoHS规范,

MSL 1

反应时间:7.5ms

待机电流:0.1μA

无需外部时钟电路

典型应用:

1.GPS精确导航(航位推算,上下桥检测等)

2.室内室外导航

3.休闲、体育和医疗健康等监测

4.天气预报

5.垂直速度指示(上升/下沉速度)

6.风扇功率控制

posted @ 2013-04-14 22:06  spaceship9  阅读(1316)  评论(0编辑  收藏  举报