Difference between revisions of "Matrix - Pressure and Temperature Sensor"

From FriendlyELEC WiKi
Jump to: navigation, search
(介绍)
Line 1: Line 1:
 
[[Matrix - Pressure and Temperature Sensor/zh|查看中文]]
 
[[Matrix - Pressure and Temperature Sensor/zh|查看中文]]
  
==介绍==
+
==Introduction==
 
[[File:Matrix-Pressure_and_Temperature_Sensor.png|thumb|]]
 
[[File:Matrix-Pressure_and_Temperature_Sensor.png|thumb|]]
*BMP180是一款高精度、小体积、超低能的压力传感器,适用于移动电话、PDAs、GPS导航设备和户外设备。在与仅仅0.25米低空噪音快速转换时,BMP180提供卓越的性能。使用IIC接口可以很轻松的跟主控制器系统进行通讯。
+
* The BMP180 is a high precision, ultra-low power small digital pressure sensor for consumer applications in  mobile phones, PDAs, GPS navigation devices and outdoor equipments. With a low altitude noise of merely 0.25m at fast conversion time, the BMP180 offers superior performance. The I2C interface allows for easy system integration with a microcontroller.
*BMP180基于压阻式技术EMC稳健性、高精度以及线性长期稳定性,被设计用来直接连接带有I2C总线接口的移动设备小型控制器。
+
* The BMP180 is based on piezo-resistive technology for EMC robustness, high accuracy and linearity as well as long term stability.
*BMP180的EEPROM值会补偿气压以及温度值。BMP180包含压阻式传感器、模拟数字转换器、EEPROM控制单元和IIC接口。
+
* The BMP180 consists of a piezo-resistive sensor, an analog to digital converter and a control unit with E2PROM and a serial I2C interface. The E2PROM has stored 176 bit of individual calibration data. This is used to compensate offset, temperature dependence and other parameters of the sensor.
  
 
==特性==
 
==特性==

Revision as of 07:22, 26 February 2016

查看中文

1 Introduction

Matrix-Pressure and Temperature Sensor.png
  • The BMP180 is a high precision, ultra-low power small digital pressure sensor for consumer applications in mobile phones, PDAs, GPS navigation devices and outdoor equipments. With a low altitude noise of merely 0.25m at fast conversion time, the BMP180 offers superior performance. The I2C interface allows for easy system integration with a microcontroller.
  • The BMP180 is based on piezo-resistive technology for EMC robustness, high accuracy and linearity as well as long term stability.
  • The BMP180 consists of a piezo-resistive sensor, an analog to digital converter and a control unit with E2PROM and a serial I2C interface. The E2PROM has stored 176 bit of individual calibration data. This is used to compensate offset, temperature dependence and other parameters of the sensor.

2 特性

  • I2C,3.3V
  • 气压值 (16 to 19 bit)
  • 温度值 (16 bit)
  • PCB Dimension(mm): 16 x 16

Matrix-Pressure and Temperature Sensor PCB.png

  • 引脚说明:
名称 描述
SDA I2C SDA
SCL I2C SCL
5V 电源5V
GND

3 工作原理

  • 模式(超低功率、标准高,超高分辨率)可以选择通过变量过采样设置(0,1,2,3)的C代码。
  • 计算真实的气压和温度值步长为 1pa(= 0.01 hpa = 0.01 mbar),温度的步长为 0.1°C。
  • 计算绝对高度,测量压力p和压力在海平面1013.25 p0例如hpa,海拔米可以与国际气压公式计算:

Matrix-Pressure and Temperature Sensor Calculat.png

  • 计算海平面气压,使用测量压力P和绝对高度可以计算出海平面气压:

Matrix-Pressure and Temperature Sensor Calculat01.png 这样,不同海拔 Δaltitude = 10米对应于1.2hPa海平面变化。

4 下载Matrix源码

Matrix配件相关的代码是完全开源的,统一由一个仓库进行管理:https://github.com/friendlyarm/matrix.git
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。

  • nanopi分支用于支持NanoPi;
  • nanopi2分支用于支持NanoPi 2;
  • tiny4412分支用于支持Tiny4412;
  • raspberrypi分支用于支持RaspberryPi;

在主机PC上安装git,以Ubuntu14.04为例

$ sudo apt-get install git

克隆Matrix配件代码仓库

$ git clone https://github.com/friendlyarm/matrix.git

克隆完成后会得到一个名为matrix的目录,里面存放着所有Matrix配件的代码。

5 与NanoPi 2连接使用

5.1 硬件连接

参考下图连接模块Matrix-Pressure_and_Temperature_Sensor和NanoPi 2:
Matrix-Pressure_and_Temperature_Sensor_nanopi_2

连接说明:

Matrix-Pressure_and_Temperature_Sensor_nanopi NanoPi 2
SDA Pin3
SCL Pin5
5V Pin4
GND Pin6

5.2 编译测试程序

进入Matrix代码仓库,切换到nanopi2分支

$ cd matrix
$ git checkout nanopi2

编译Matrix配件代码

$ make CROSS_COMPILE=arm-linux- clean
$ make CROSS_COMPILE=arm-linux-
$ make CROSS_COMPILE=arm-linux- install

注意:请确保你的主机PC当前使用的交叉编译器为NanoPi 2配套的arm-linux-gcc-4.9.3。
编译成功后库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-Pressure_and_Temperature_Sensor对应的测试程序为matrix-pressure_temp。
硬件驱动模块位于modules目录下,对应的驱动源码都包含在在NanoPi 2的Linux内核仓库里:https://github.com/friendlyarm/linux-3.4.y.git

5.3 运行测试程序

将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令将Matrix的硬件驱动、库文件和测试程序拷贝到NanoPi 2的文件系统上。

$ cp modules /media/rootfs/ -r
$ cp install/lib/* /media/rootfs/lib/ -d
$ cp install/usr/bin/* /media/rootfs/usr/bin/

将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令加载硬件驱动。

$ cd /modules
$ insmod bmp085.ko

运行模块Matrix-Pressure_and_Temperature_Sensor的测试程序。

$ matrix-pressure_temp

注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
运行效果如下:
matrix-pressure_temp_result

5.4 代码展示

int main(int argc, char ** argv) 
{ 
    int ret = -1;
    int bmpTemp = 0;
    int bmpPressure = 0;
    float altitude = 0;
 
    if ((ret = bmp180Read(BMP180_TEMP, &bmpTemp)) != -1) {
        printf("Get temperature : %.1f C\n", (float)bmpTemp / 10);
    } else {
        printf("Faided to get humidity\n");
    }
 
    if ((ret = bmp180Read(BMP180_PRESSURE, &bmpPressure)) != -1) {
        printf("Get pressure : %.2f hPa\n", (float)bmpPressure / 100);
    } else {
        printf("Faided to get pressure\n");
    }
 
    altitude = 44330 * ( 1 - pow( ((float)bmpPressure / 100 / 1013.25), (1/5.255) ) );
    printf("Get altitude : %.2f m\n", altitude);
    return 0;
}

6 与NanoPi连接使用

6.1 准备工作

在NanoPi上运行Debian系统,然后在主机PC上安装并使用相应的编译器,参考wiki: NanoPi & How to Build the Compiling Environment
注意: 只有使用nanopi-v4.1.y-matrix分支编译出来的内核才能配合Matrix配件正常工作。
下载NanoPi内核源代码并编译:

$ git clone https://github.com/friendlyarm/linux-4.x.y.git
$ cd linux-4.x.y
$ git checkout nanopi-v4.1.y-matrix
$ make nanopi_defconfig
$ touch .scmversion
$ make

编译好后的zImage位于内核源码arch/arm/boot/目录下,把该zImage替换掉NanoPi烧写文件sd-fuse_nanopi/prebuilt下的zImage,重新制作SD卡即可。

6.2 硬件连接

参考下图连接模块Matrix-Pressure_and_Temperature_Sensor和NanoPi:
Matrix-Pressure_and_Temperature_Sensor_nanopi

连接说明:

Matrix-Pressure_and_Temperature_Sensor_nanopi NanoPi
SDA Pin3
SCL Pin5
5V Pin4
GND Pin6

6.3 编译测试程序

进入Matrix代码仓库,切换到nanopi分支

$ cd matrix
$ git checkout nanopi

编译Matrix配件代码

$ make CROSS_COMPILE=arm-linux- clean
$ make CROSS_COMPILE=arm-linux-
$ make CROSS_COMPILE=arm-linux- install

注意:请确保你的主机PC当前使用的交叉编译器为NanoPi-Debian配套的arm-linux-gcc-4.4.3。
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-Pressure_and_Temperature_Sensor对应的测试程序为matrix-pressure_temp。

6.4 运行测试程序

将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令将Matrix的硬件驱动、库文件和测试程序拷贝到NanoPi的文件系统上。

$ cp modules /media/rootfs/ -r
$ cp install/lib/* /media/rootfs/lib/ -d
$ cp install/usr/bin/* /media/rootfs/usr/bin/

将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令加载硬件驱动。

$ cd /modules
$ insmod bmp085-i2c.ko

运行模块Matrix-Pressure_and_Temperature_Sensor的测试程序。

$ matrix-pressure_temp

注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。

6.5 代码展示

int main(int argc, char ** argv) 
{ 
    int ret = -1;
    int bmpTemp = 0;
    int bmpPressure = 0;
    float altitude = 0;
 
    if ((ret = bmp180Read(BMP180_TEMP, &bmpTemp)) != -1) {
        printf("Get temperature : %.1f C\n", (float)bmpTemp / 10);
    } else {
        printf("Faided to get humidity\n");
    }
 
    if ((ret = bmp180Read(BMP180_PRESSURE, &bmpPressure)) != -1) {
        printf("Get pressure : %.2f hPa\n", (float)bmpPressure / 100);
    } else {
        printf("Faided to get pressure\n");
    }
 
    altitude = 44330 * ( 1 - pow( ((float)bmpPressure / 100 / 1013.25), (1/5.255) ) );
    printf("Get altitude : %.2f m\n", altitude);
    return 0;
}

7 与Tiny4412连接使用

8 与RaspberryPi连接使用

9 与Arduino连接使用

10 相关资料

BMP180.pdf

11 Update Log

11.1 Feb-24-2016

  • Added the whole English version