Arduino + BMP180 显示气压 温度
来源:互联网 发布:后现代主义风格 知乎 编辑:程序博客网 时间:2024/04/27 17:51
<img src="http://img.blog.csdn.net/20150223151225717?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZG8zMzVtYW9tYW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<span style="color: rgb(68, 68, 68); font-family: Tahoma, 'Microsoft Yahei', Simsun; font-size: 14px; line-height: 21px;">这是BMP180模块,四个引脚</span><br style="word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, 'Microsoft Yahei', Simsun; font-size: 14px; line-height: 21px;" /><br style="word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, 'Microsoft Yahei', Simsun; font-size: 14px; line-height: 21px;" /><span style="color: rgb(68, 68, 68); font-family: Tahoma, 'Microsoft Yahei', Simsun; font-size: 14px; line-height: 21px;">以Arduino Uno为例:VCC 接3.3v,GND接GND,SCL接A5,SDA接A4</span>
<span style="color: rgb(68, 68, 68); font-family: Tahoma, 'Microsoft Yahei', Simsun; font-size: 14px; line-height: 21px;">库:http://pan.baidu.com/s/1i3KN4Vj</span>
<span style="color: rgb(68, 68, 68); font-family: Tahoma, 'Microsoft Yahei', Simsun; font-size: 14px; line-height: 21px;"></span><pre name="code" class="cpp">#include <SFE_BMP180.h>#include <Wire.h> SFE_BMP180 pressure;// 创建一个气压计对象 double baseline; // 基准气压 void setup(){ Serial.begin(9600); Serial.println("REBOOT"); // 初始化传感器 if (pressure.begin()) Serial.println("BMP180 init success"); else { // 糟糕,气压计出问题了,多半是连线有问题 Serial.println("BMP180 init fail (disconnected?)\n\n"); while(1); // 暂停 } //获得基准气压 baseline = getP(); Serial.print("baseline pressure: "); Serial.print(baseline); Serial.println(" hPa"); } void loop(){ double a,p,t; p = getP();// 获得一个气压值 a = pressure.altitude(p,baseline);//获得基于基准气压的高度值 Serial.print("relative altitude: "); if (a >= 0.0) Serial.print(" "); // 调整正数显示格式 Serial.print(a,1); Serial.print(" meters "); t = getT();// 获得一个温度值 Serial.print("temperature: "); Serial.print(t,1); Serial.println(" degrees"); delay(500);//刷新率} double getP(){ char status; double T,P,p0,a; // You must first get a temperature measurement to perform a pressure reading. // Start a temperature measurement: // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned. status = pressure.startTemperature(); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed temperature measurement: // Note that the measurement is stored in the variable T. // Use '&T' to provide the address of T to the function. // Function returns 1 if successful, 0 if failure. status = pressure.getTemperature(T); if (status != 0) { // Start a pressure measurement: // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned. status = pressure.startPressure(3); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed pressure measurement: // Note that the measurement is stored in the variable P. // Use '&P' to provide the address of P. // Note also that the function requires the previous temperature measurement (T). // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) // Function returns 1 if successful, 0 if failure. status = pressure.getPressure(P,T); if (status != 0) { return P; } else Serial.println("error retrieving pressure measurement\n"); } else Serial.println("error starting pressure measurement\n"); } else Serial.println("error retrieving temperature measurement\n"); } else Serial.println("error starting temperature measurement\n");} double getT(){ char status; double T,p0; status = pressure.startTemperature(); if (status != 0) { delay(status); status = pressure.getTemperature(T); if (status != 0) { status = pressure.startPressure(3); return T; } else Serial.println("error retrieving temperature measurement\n"); } else Serial.println("error starting temperature measurement\n");}
效果:
参考资料:https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup-
0 0
- Arduino + BMP180 显示气压 温度
- Arduino BMP085/BMP180气压传感器实验
- BMP180气压传感器调试
- Arduino LCD 温度显示
- BMP180气压传感器波动过大的解决方案
- BMP180
- 20141115 【 Arduino - LM35 - 4位八段数码管 】 数码管显示温度
- arduino 大气气压模块 BOSCH BMP085
- Arduino笔记三气压模块BMP85
- 单片机控制气压海拔模块BMP180之模块化编程(持续更新中)
- 单片机控制气压海拔模块BMP180之模块化编程(持续更新中)
- STM32F4的I2C读取BMP085模块的温度和气压
- STM32+MS5611测气压温度例程详解,测试无误
- Arduino 卡片7 温度报警器
- 基于 Arduino 的温度+湿度传感器
- RaspberryPi和Arduino控制温室温度
- 【Arduino】使用LM35传感器实时测量温度
- 如何制作一个Arduino温度数据记录仪
- poj3140 Contestants Division(树形DP)
- Eclipse for Mac 常用快捷键
- scala泛函编程是怎样被选中的
- CC150 Arrays and Strings 1.1 ~ 1.3 Unique Characters, Reverse String, IsPermutation
- VisualSVN Server 安装出错
- Arduino + BMP180 显示气压 温度
- 在某个位置后面插入字符串
- jQuery最佳实践
- poj1466 Girls and Boys
- ADB server didn't ACK 解决方法
- VB.NET——导出Excel
- Android之Animation动画的使用(一)
- POJ 3252 round numbers(数位DP)
- Windows Server 2012 安装.NET2.0-3.5的方法