GY-68 又称 BMP180是一款非常常见且廉价的气压计模块,工作原理为由于海拔高度不同产生的大气压力也不同,所以由 BMP180 所计算出来的压力和温度值,还可以经过计算得出当前环境的海拔高度作为“海拔高度计”使用。

本文为爱鱼客原创内容,未经作者及本站允许请勿转载至任何其他平台!

GY-68,BMP180,Barometer

**应用:**海拔高度有什么用呢?首先对于登山爱好者来说,通过气压计可以很方便的知道海拔高度。另外在GPS导航时,若没有高度计,在高架桥路段就没法知道是在桥上还是桥下了,总而言之BMP180 可以应用在下面的用途上:

  • 加强GPS精确度(另外还有磁力仪、陀螺仪、加速度仪都可以用来加强GPS精确度)
  • 室内与室外导航
  • 休閒、体育和医疗健康等监测
  • 天气预测
  • 垂直速度指示 ( 上升 / 下降速率 )
  • 风扇转速控制 ( 利用温度值 )

下面来介绍一下如何使用 BMP180 气压计。
一般可以购买到BMP180的breakout板,使用非常方便,另外准备Arduino UNO或其他有至少两个Analog pin的板即可,我们教程以UNO为基础。

BOSCH 官方参数:http://www.bosch-sensortec.com/de/homepage/products_3/environmental_sensors_1/bmp180_1/bmp180

I2C连接:

  • VIN → 建议3.3V (经测试5V也可使用)
  • GND → GND
  • SCL → A5
  • SDA → A4
    (建议焊接一个排线以避免接触不良)

添加两个BMP180/BMP085的库:(我们这里使用Adafruit的库)

  • 下载:Arduino_Sensor-master.zip
  • 下载:BMP085-master.zip
  • 打开Arduino IDE,项目(Project) → Include Library → Add .ZIP Library...
  • 把两个库都添加进去。
  • 直接调用 Example 里的示例(文件 → 示例 → BMP085 → sensorapi)
  • 或者直接拷贝下面的代码到IDE里:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

/*    
   Connections
   ===========
   Connect SCL to analog 5
   Connect SDA to analog 4
   Connect VDD to 3.3V DC
   Connect GROUND to common ground

   History
   =======
   2013/JUN/17  - Updated altitude calculations (KTOWN)
   2013/FEB/13  - First version (KTOWN)
*/

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

/**************************************************************************/
/*
    Displays some basic information on this sensor from the unified
    sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
  sensor_t sensor;
  bmp.getSensor(&amp;sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" hPa");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" hPa");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" hPa");  
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

/**************************************************************************/
/*
    Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Pressure Sensor Test"); Serial.println("");

  /* Initialise the sensor */
  if(!bmp.begin())
  {
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }

  /* Display some basic information on this sensor */
  displaySensorDetails();
}

/**************************************************************************/
/*
    Arduino loop function, called once 'setup' is complete (your own code
    should go here)
*/
/**************************************************************************/
void loop(void) 
{
  /* Get a new sensor event */ 
  sensors_event_t event;
  bmp.getEvent(&amp;event);

  /* Display the results (barometric pressure is measure in hPa) */
  if (event.pressure)
  {
    /* Display atmospheric pressue in hPa */
    Serial.print("Pressure:    ");
    Serial.print(event.pressure);
    Serial.println(" hPa");

    /* Calculating altitude with reasonable accuracy requires pressure    *
     * sea level pressure for your position at the moment the data is     *
     * converted, as well as the ambient temperature in degress           *
     * celcius.  If you don't have these values, a 'generic' value of     *
     * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA   *
     * in sensors.h), but this isn't ideal and will give variable         *
     * results from one day to the next.                                  *
     *                                                                    *
     * You can usually find the current SLP value by looking at weather   *
     * websites or from environmental information centers near any major  *
     * airport.                                                           *
     *                                                                    *
     * For example, for Paris, France you can check the current mean      *
     * pressure and sea level at: [http://bit.ly/16Au8ol](http://bit.ly/16Au8ol)                   */

    /* First we get the current temperature from the BMP085 */
    float temperature;
    bmp.getTemperature(&amp;temperature);
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");

    /* Then convert the atmospheric pressure, and SLP to altitude         */
    /* Update this next line with the current SLP for better results      */
    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    Serial.print("Altitude:    "); 
    Serial.print(bmp.pressureToAltitude(seaLevelPressure,
                                        event.pressure)); 
    Serial.println(" m");
    Serial.println("");
  }
  else
  {
    Serial.println("Sensor error");
  }
  delay(1000);
}

上传到Arduino Uno,打开“串口监视器”,选择9600波特,就可以看到每秒发送一次如下的数据啦:

Pressure Sensor Test
------------------------------------
Sensor:       BMP085
Driver Ver:   1
Unique ID:    10085
Max Value:    1100.00 hPa
Min Value:    300.00 hPa
Resolution:   0.01 hPa
------------------------------------

Pressure:    1005.43 hPa
Temperature: 34.00 C
Altitude:    65.31 m

Pressure:    1005.41 hPa
Temperature: 34.00 C
Altitude:    65.48 m