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

From FriendlyELEC WiKi
Jump to: navigation, search
(Update Log)
 
(24 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Matrix - Pressure and Temperature Sensor|English]]
+
[[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.
  
==特性==
+
==Features==
 
* I2C,3.3V
 
* I2C,3.3V
* 气压值 (16 to 19 bit)
+
* Pressure data(16 to 19 bit)
* 温度值 (16 bit)
+
* Temperature data(16 bit)
 
* PCB Dimension(mm): 16 x 16
 
* PCB Dimension(mm): 16 x 16
  
 
[[File:Matrix-Pressure_and_Temperature_Sensor_PCB.png|frameless|400px|]]
 
[[File:Matrix-Pressure_and_Temperature_Sensor_PCB.png|frameless|400px|]]
  
* 引脚说明:
+
* Pin Description:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|名称   || 描述
+
|Pin   || Description
 
|-
 
|-
 
|SDA    || I2C SDA
 
|SDA    || I2C SDA
Line 24: Line 24:
 
|SCL    || I2C SCL
 
|SCL    || I2C SCL
 
|-  
 
|-  
|5V    || 电源5V
+
|5V    || Supply Voltage 5V
 
|-
 
|-
|GND    ||
+
|GND    || Ground
 
|}
 
|}
  
==工作原理==
+
==Basic Device Operation==
* 模式(超低功率、标准高,超高分辨率)可以选择通过变量过采样设置(0,1,2,3)的C代码。
+
* The mode (ultra low power, standard, high, ultra high resolution) can be selected by the variable oversampling_setting (0, 1, 2, 3) in the C code.
* 计算真实的气压和温度值步长为 1pa(= 0.01 hpa = 0.01 mbar),温度的步长为 0.1°C。
+
* Calculation of true temperature and pressure in steps of 1Pa (= 0.01hPa = 0.01mbar) and temperature in steps of 0.1°C.
* 计算绝对高度,测量压力p和压力在海平面1013.25 p0例如hpa,海拔米可以与国际气压公式计算:
+
* With the measured pressure p and the pressure at sea level p0 e.g. 1013.25hPa, the altitude in meters can be calculated with the international barometric formula: [[File:Matrix-Pressure_and_Temperature_Sensor_Calculat.png|frameless|400px|]]
[[File:Matrix-Pressure_and_Temperature_Sensor_Calculat.png|frameless|400px|]]
+
* With the measured pressure p and the absolute altitude the pressure at sea level can be calculated:
* 计算海平面气压,使用测量压力P和绝对高度可以计算出海平面气压:
+
 
[[File:Matrix-Pressure_and_Temperature_Sensor_Calculat01.png|frameless|400px|]]
 
[[File:Matrix-Pressure_and_Temperature_Sensor_Calculat01.png|frameless|400px|]]
这样,不同海拔 Δaltitude = 10米对应于1.2hPa海平面变化。
+
Thus, a difference in altitude of ∆altitude = 10m corresponds to 1.2hPa pressure change at sea level.
  
==下载Matrix源码==
+
==Applications==
Matrix配件相关的代码是完全开源的,统一由一个仓库进行管理:git://github.com/friendlyarm/matrix.git <br>
+
===Connect to NanoPi M1===
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。<br>
+
Refer to the following connection diagram to connect the module to the NanoPi M1:<br>
* nanopi分支用于支持NanoPi;
+
[[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_m1.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_m1]]
* nanopi2分支用于支持NanoPi 2;
+
* tiny4412分支用于支持Tiny4412;
+
* raspberrypi分支用于支持RaspberryPi;
+
  
在主机PC上安装git,以Ubuntu14.04为例
+
Connection Details:
<syntaxhighlight lang="bash">
+
{| class="wikitable"
$ sudo apt-get install git
+
|-
</syntaxhighlight>
+
|Matrix-Pressure_and_Temperature_Sensor || NanoPi M1     
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V    || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
  
克隆Matrix配件代码仓库
+
===Connect to NanoPi 2===
<syntaxhighlight lang="bash">
+
Refer to the following connection diagram to connect the module to the NanoPi 2:<br>
$ git clone git://github.com/friendlyarm/matrix.git
+
</syntaxhighlight>
+
克隆完成后会得到一个名为matrix的目录,里面存放着所有Matrix配件的代码。
+
 
+
==与NanoPi 2连接使用==
+
===硬件连接===
+
参考下图连接模块Matrix-Pressure_and_Temperature_Sensor和NanoPi 2:<br>
+
 
[[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_2]]
 
[[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_2]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|Matrix-Pressure_and_Temperature_Sensor_nanopi || NanoPi 2
+
|Matrix-Pressure_and_Temperature_Sensor || NanoPi 2
 
|-
 
|-
 
|SDA    || Pin3
 
|SDA    || Pin3
Line 76: Line 74:
 
|}
 
|}
  
===编译测试程序===
+
===Connect to NanoPi M2 / NanoPi 2 Fire===
进入Matrix代码仓库,切换到nanopi2分支
+
Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire:<br>
<syntaxhighlight lang="bash">
+
[[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_M2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_M2]]
$ cd matrix
+
$ git checkout nanopi2
+
</syntaxhighlight>
+
  
编译Matrix配件代码
+
Connection Details:
<syntaxhighlight lang="bash">
+
{| class="wikitable"
$ make CROSS_COMPILE=arm-linux- clean
+
|-
$ make CROSS_COMPILE=arm-linux-
+
| || NanoPi M2     
$ make CROSS_COMPILE=arm-linux- install
+
|-
</syntaxhighlight>
+
|SDA    || Pin3
注意:请确保你的主机PC当前使用的交叉编译器为NanoPi 2配套的arm-linux-gcc.4.8.5。<br>
+
|-
编译成功后库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-Pressure_and_Temperature_Sensor对应的测试程序为matrix-pressure_temp。<br>
+
|SCL    || Pin5
 +
|-  
 +
|5V    || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Connect to NanoPC-T2===
 +
Refer to the following connection diagram to connect the module to the NanoPC-T2:<br>
 +
[[File:Matrix-Pressure_and_Temperature_Sensor_NanoPC-T2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_NanoPC-T2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-Pressure_and_Temperature_Sensor || NanoPC-T2
 +
|-
 +
|SDA    || Pin6
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V    || Pin29
 +
|-
 +
|GND    || Pin30
 +
|}
  
===运行测试程序===
+
==Compile & Run Test Program==
将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。<br>
+
Boot your ARM board with Debian and copy the matrix code:
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令将Matrix的硬件驱动、库文件和测试程序拷贝到NanoPi 2的文件系统上。<br>
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ cp modules /media/rootfs/ -r
+
$ apt-get update && apt-get install git
$ cp install/lib/* /media/rootfs/lib/ -d
+
$ git clone https://github.com/friendlyarm/matrix.git
$ cp install/usr/bin/* /media/rootfs/usr/bin/
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
If your cloning is done successfully a "matrix" directory will be generated.
  
将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令加载硬件驱动。<br>
+
Compile and install Matrix:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ cd /modules
+
$ cd matrix
$ insmod bmp085.ko
+
$ make && make install
 
</syntaxhighlight>
 
</syntaxhighlight>
  
运行模块Matrix-Pressure_and_Temperature_Sensor的测试程序。<br>
+
Run test program:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-pressure_temp
 
$ matrix-pressure_temp
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br>
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.<br>
运行效果如下:<br>
+
Here is what you should observe:<br>
[[File:matrix-pressure_temp_result.png|frameless|600px|matrix-pressure_temp_result]]
+
<syntaxhighlight lang="bash">
 +
The temperature is 26.6 C
 +
The pressure is 983.91 hPa
 +
The altitude is 247.18
 +
</syntaxhighlight>
  
===代码展示===
+
==Code Sample==
 +
This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-pressure_and_temperature_sensor". Here is its source code:
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
int main(int argc, char ** argv)  
 
int main(int argc, char ** argv)  
 
{  
 
{  
 
     int ret = -1;
 
     int ret = -1;
     int bmpTemp = 0;
+
     int bmpTemp=0, bmpPressure=0;
     int bmpPressure = 0;
+
     int board;
 
     float altitude = 0;
 
     float altitude = 0;
 
      
 
      
 +
    if ((board = boardInit()) < 0) {
 +
        printf("Fail to init board\n");
 +
        return -1;
 +
    }
 +
   
 +
    system("modprobe "DRIVER_MODULE);
 
     if ((ret = bmp180Read(BMP180_TEMP, &bmpTemp)) != -1) {
 
     if ((ret = bmp180Read(BMP180_TEMP, &bmpTemp)) != -1) {
         printf("Get temperature : %.1f C\n", (float)bmpTemp / 10);
+
         printf("The temperature is %.1f C\n", (float)bmpTemp / 10);
 
     } else {
 
     } else {
 
         printf("Faided to get humidity\n");
 
         printf("Faided to get humidity\n");
 
     }
 
     }
 
 
     if ((ret = bmp180Read(BMP180_PRESSURE, &bmpPressure)) != -1) {
 
     if ((ret = bmp180Read(BMP180_PRESSURE, &bmpPressure)) != -1) {
         printf("Get pressure : %.2f hPa\n", (float)bmpPressure / 100);
+
         printf("The pressure is %.2f hPa\n", (float)bmpPressure / 100);
 
     } else {
 
     } else {
 
         printf("Faided to get pressure\n");
 
         printf("Faided to get pressure\n");
Line 137: Line 164:
  
 
     altitude = 44330 * ( 1 - pow( ((float)bmpPressure / 100 / 1013.25), (1/5.255) ) );
 
     altitude = 44330 * ( 1 - pow( ((float)bmpPressure / 100 / 1013.25), (1/5.255) ) );
     printf("Get altitude : %.2f m\n", altitude);
+
     printf("The altitude is %.2f m\n", altitude);
 +
    system("rmmod "DRIVER_MODULE);
 
     return 0;
 
     return 0;
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
For more details about this APIs called in this code sample refer to [[Matrix API reference manual]] <br>
 +
<!---
 +
==Download Matrix Source Code==
 +
All the matrix modules' code samples are open source. They are maintained on GitHub - https://github.com/friendlyarm/matrix.git <br>
 +
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.<br>
 +
* The nanopi branch contains the matrix modules' code samples for the NanoPi
 +
* The nanopi 2 branch contains the matrix modules' code samples for the NanoPi 2
 +
* The tiny4412 branch contains the matrix modules' code samples for the Tiny4412
 +
* The raspberrypi branch contains the matrix modules' code samples for the RaspberryPi
  
==与NanoPi连接使用==
+
Please follow the steps below to get the source code:<br>
===准备工作===
+
Install the git utility on a PC running Ubuntu14.04
在NanoPi上运行Debian系统,然后在主机PC上安装并使用相应的编译器,参考wiki: [[NanoPi/zh|NanoPi]] & [[How_to_build_the_Compiling_Environment/zh|How to Build the Compiling Environment]]。<br>
+
注意: 只有使用nanopi-v4.1.y-matrix分支编译出来的内核才能配合Matrix配件正常工作。<br>
+
下载NanoPi内核源代码并编译: <br>
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ git clone https://github.com/friendlyarm/linux-4.x.y.git
+
$ sudo apt-get install git
$ cd linux-4.x.y
+
$ git checkout nanopi-v4.1.y-matrix
+
$ make nanopi_defconfig
+
$ touch .scmversion
+
$ make
+
 
</syntaxhighlight>
 
</syntaxhighlight>
编译好后的zImage位于内核源码arch/arm/boot/目录下,把该zImage替换掉NanoPi烧写文件sd-fuse_nanopi/prebuilt下的zImage,重新制作SD卡即可。
 
  
===硬件连接===
+
Clone the matrix code from GitHub
参考下图连接模块Matrix-Pressure_and_Temperature_Sensor和NanoPi:<br>
+
<syntaxhighlight lang="bash">
[[File:Matrix-Pressure_and_Temperature_Sensor_nanopi.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi]]
+
$ git clone https://github.com/friendlyarm/matrix.git
 +
</syntaxhighlight>
 +
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.
  
连接说明:
+
==Connect to NanoPi 2==
 +
===Hardware Connection===
 +
Please refer to the following connection diagram to connect the Matrix-Pressure_and_Temperature_Sensor to the NanoPi 2:<br>
 +
[[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_2]]
 +
 
 +
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|Matrix-Pressure_and_Temperature_Sensor_nanopi || NanoPi
+
|Matrix-Pressure_and_Temperature_Sensor_nanopi || NanoPi 2
 
|-
 
|-
 
|SDA    || Pin3
 
|SDA    || Pin3
Line 175: Line 210:
 
|}
 
|}
  
===编译测试程序===
+
===Compile Test Program===
进入Matrix代码仓库,切换到nanopi分支
+
Please login the matrix hub and enter the nanopi2 branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
$ git checkout nanopi
+
$ git checkout nanopi2
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译Matrix配件代码
+
Compile the matrix code
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ make CROSS_COMPILE=arm-linux- clean
 
$ make CROSS_COMPILE=arm-linux- clean
Line 188: Line 223:
 
$ make CROSS_COMPILE=arm-linux- install
 
$ make CROSS_COMPILE=arm-linux- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为NanoPi-Debian配套的arm-linux-gcc-4.4.3。<br>
+
Note: please make sure to install the cross compiler "arm-linux-gcc-4.9.3" on your PC, which is used to compile files for the NanoPi 2.<br>
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-Pressure_and_Temperature_Sensor对应的测试程序为matrix-pressure_temp。<br>
+
Generated library files are under the "install/lib" directory. The test program is under the "install/usr/bin" directory.<br>
 +
The modules are under the "modules" directory. The driver's source code is in github: https://github.com/friendlyarm/linux-3.4.y.git <br>
  
===运行测试程序===
+
===Run Test Program===
将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。<br>
+
Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.<br>
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令可将Matrix的所有库文件和测试程序拷贝到NanoPi的文件系统上。<br>
+
We assume the rootfs is mounted to /media/rootfs then please run the following commands to copy the module, library and test program to the card.<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ cp install/usr/bin/* /media/rootfs/usr/bin/
+
$ cp modules /media/rootfs/ -r
 
$ cp install/lib/* /media/rootfs/lib/ -d
 
$ cp install/lib/* /media/rootfs/lib/ -d
 +
$ cp install/usr/bin/* /media/rootfs/usr/bin/
 
</syntaxhighlight>
 
</syntaxhighlight>
  
将SD卡重新插入NanoPi,上电启动,在Debian的shell终端中执行以下命令运行模块Matrix-Pressure_and_Temperature_Sensor的测试程序。<br>
+
Insert this TF card to your NanoPi 2, power on and run the following command to load the driver<br>
 +
<syntaxhighlight lang="bash">
 +
$ cd /modules
 +
$ insmod bmp085.ko
 +
</syntaxhighlight>
 +
 
 +
Start the matrix-pressure_temp program<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-pressure_temp
 
$ matrix-pressure_temp
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi 2.<br>
 +
Here is what you expect to observe:<br>
 +
[[File:matrix-pressure_temp_result.png|frameless|600px|matrix-pressure_temp_result]]
  
===代码展示===
+
===Code Sample===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
int main(int argc, char ** argv)  
 
int main(int argc, char ** argv)  
Line 232: Line 277:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==与Tiny4412连接使用==
+
==Connect to NanoPi==
===准备工作===
+
===Preparations===
参考Tiny4412光盘里的《友善之臂Ubuntu使用手册》,在Tiny4412上运行UbuntuCore系统,然后在主机PC上安装并使用相应的编译器。<br>
+
Please install a Debian on a NanoPi and an appropriate cross compiler on a PC. Please refer to wiki: [NanoPi] & [How to Build the Compiling Environment].<br>
注意:只能使用Tiny4412SDK-1506的底板。
+
Note: please use the kernel's source code from the nanopi-v4.1.y-matrix branch.<br>
 +
<syntaxhighlight lang="bash">
 +
$ 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
 +
</syntaxhighlight>
 +
After it is done a zImage will be generated under arch/arm/boot/. You can use it to replace the existing file under sd-fuse_nanopi/prebuilt.
  
===硬件连接===
+
===Hardware Connection===
参考下图连接模块Matrix-Pressure_and_Temperature_Sensor和Tiny4412:<br>
+
Please refer to the following connection diagram to connect the Matrix-Pressure_and_Temperature_Sensor to the NanoPi:<br>
[[File:Matrix-Pressure_and_Temperature_Sensor_tiny4412.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_tiny4412]]
+
[[File:Matrix-Pressure_and_Temperature_Sensor_nanopi.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|Matrix-Pressure_and_Temperature_Sensor || Tiny4412
+
|Matrix-Pressure_and_Temperature_Sensor_nanopi || NanoPi
 
|-
 
|-
|SDA    || CON18 SDA
+
|SDA    || Pin3
 
|-
 
|-
|SCL    || CON18 SCL
+
|SCL    || Pin5
 
|-  
 
|-  
|5V    || CON18 5V
+
|5V    || Pin4
 
|-
 
|-
|GND    || CON18 GND
+
|GND    || Pin6
 
|}
 
|}
  
===编译测试程序===
+
===Compile Test Program===
进入Matrix代码仓库,切换到tiny4412分支
+
Please login the matrix hub and enter the nanopi branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
$ git checkout tiny4412
+
$ git checkout nanopi
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译Matrix配件代码
+
Compile the matrix code
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ make CROSS_COMPILE=arm-linux-gnueabihf- clean
+
$ make CROSS_COMPILE=arm-linux- clean
$ make CROSS_COMPILE=arm-linux-gnueabihf-
+
$ make CROSS_COMPILE=arm-linux-
$ make CROSS_COMPILE=arm-linux-gnueabihf- install
+
$ make CROSS_COMPILE=arm-linux- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为Tiny4412-UbuntuCore配套的arm-linux-gnueabihf-gcc-4.7.3。<br>
+
Note: please make sure to install the cross compiler "arm-linux-gcc-4.4.3" on your PC, which is used to compile files for the NanoPi-Debian.<br>
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-Pressure_and_Temperature_Sensor对应的测试程序为matrix-pressure_temp。
+
Generated library files are under the "install/lib" directory. Applications are under the "install/usr/bin" directory. The test program for the "Matrix-Pressure_and_Temperature_Sensor" module is "matrix-pressure_temp".<br>
  
===运行测试程序===
+
===Run Test Program===
将带有UbuntuCore系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。<br>
+
Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.<br>
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令可将Matrix的所有库文件和测试程序拷贝到Tiny4412的文件系统上。<br>
+
We assume the rootfs is mounted to /media/rootfs then please run the following commands to copy the module, library and test program to the card.<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ cp install/usr/bin/* /media/rootfs/usr/bin/
+
$ cp modules /media/rootfs/ -r
 
$ cp install/lib/* /media/rootfs/lib/ -d
 
$ cp install/lib/* /media/rootfs/lib/ -d
 +
$ cp install/usr/bin/* /media/rootfs/usr/bin/
 +
</syntaxhighlight>
 +
 +
Insert this TF card to your NanoPi, power on and run the following command to load the driver<br>
 +
<syntaxhighlight lang="bash">
 +
$ cd /modules
 +
$ insmod bmp085-i2c.ko
 
</syntaxhighlight>
 
</syntaxhighlight>
  
将SD卡重新插入Tiny4412,上电启动,在UbuntuCore的shell终端中执行以下命令运行模块Matrix-Pressure_and_Temperature_Sensor的测试程序。<br>
+
Start the matrix-pressure_temp program.<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-pressure_temp
 
$ matrix-pressure_temp
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br>
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi.<br>
  
===代码展示===
+
===Code Sample===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
int main(int argc, char ** argv)  
 
int main(int argc, char ** argv)  
Line 312: Line 373:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==与RaspberryPi连接使用==
+
==Connect to Tiny4412==
  
==与Arduino连接使用==
+
==Connect to RaspberryPi==
  
==相关资料==
+
==Connect to Arduino==
 +
--->
 +
 
 +
==Resources==
 
[https://ae-bst.resource.bosch.com/media/products/dokumente/bmp180/BST-BMP180-DS000-12~1.pdf BMP180.pdf]
 
[https://ae-bst.resource.bosch.com/media/products/dokumente/bmp180/BST-BMP180-DS000-12~1.pdf BMP180.pdf]
 +
 +
==Update Log==
 +
===Feb-24-2016===
 +
* Added the whole English version
 +
 +
===Feb-26-2016===
 +
* Translated into English
 +
 +
===June-23-2016===
 +
* Re-organized and simplified wiki

Latest revision as of 14:47, 23 June 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 Features

  • I2C,3.3V
  • Pressure data(16 to 19 bit)
  • Temperature data(16 bit)
  • PCB Dimension(mm): 16 x 16

Matrix-Pressure and Temperature Sensor PCB.png

  • Pin Description:
Pin Description
SDA I2C SDA
SCL I2C SCL
5V Supply Voltage 5V
GND Ground

3 Basic Device Operation

  • The mode (ultra low power, standard, high, ultra high resolution) can be selected by the variable oversampling_setting (0, 1, 2, 3) in the C code.
  • Calculation of true temperature and pressure in steps of 1Pa (= 0.01hPa = 0.01mbar) and temperature in steps of 0.1°C.
  • With the measured pressure p and the pressure at sea level p0 e.g. 1013.25hPa, the altitude in meters can be calculated with the international barometric formula: Matrix-Pressure and Temperature Sensor Calculat.png
  • With the measured pressure p and the absolute altitude the pressure at sea level can be calculated:

Matrix-Pressure and Temperature Sensor Calculat01.png Thus, a difference in altitude of ∆altitude = 10m corresponds to 1.2hPa pressure change at sea level.

4 Applications

4.1 Connect to NanoPi M1

Refer to the following connection diagram to connect the module to the NanoPi M1:
Matrix-Pressure_and_Temperature_Sensor_nanopi_m1

Connection Details:

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

4.2 Connect to NanoPi 2

Refer to the following connection diagram to connect the module to the NanoPi 2:
Matrix-Pressure_and_Temperature_Sensor_nanopi_2

Connection Details:

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

4.3 Connect to NanoPi M2 / NanoPi 2 Fire

Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire:
Matrix-Pressure_and_Temperature_Sensor_nanopi_M2

Connection Details:

NanoPi M2
SDA Pin3
SCL Pin5
5V Pin4
GND Pin6

4.4 Connect to NanoPC-T2

Refer to the following connection diagram to connect the module to the NanoPC-T2:
Matrix-Pressure_and_Temperature_Sensor_NanoPC-T2

Connection Details:

Matrix-Pressure_and_Temperature_Sensor NanoPC-T2
SDA Pin6
SCL Pin5
5V Pin29
GND Pin30

5 Compile & Run Test Program

Boot your ARM board with Debian and copy the matrix code:

$ apt-get update && apt-get install git
$ git clone https://github.com/friendlyarm/matrix.git

If your cloning is done successfully a "matrix" directory will be generated.

Compile and install Matrix:

$ cd matrix
$ make && make install

Run test program:

$ matrix-pressure_temp

Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.
Here is what you should observe:

The temperature is 26.6 C
The pressure is 983.91 hPa
The altitude is 247.18

6 Code Sample

This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-pressure_and_temperature_sensor". Here is its source code:

int main(int argc, char ** argv) 
{ 
    int ret = -1;
    int bmpTemp=0, bmpPressure=0;
    int board;
    float altitude = 0;
 
    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }
 
    system("modprobe "DRIVER_MODULE);
    if ((ret = bmp180Read(BMP180_TEMP, &bmpTemp)) != -1) {
        printf("The temperature is %.1f C\n", (float)bmpTemp / 10);
    } else {
        printf("Faided to get humidity\n");
    }
    if ((ret = bmp180Read(BMP180_PRESSURE, &bmpPressure)) != -1) {
        printf("The pressure is %.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("The altitude is %.2f m\n", altitude);
    system("rmmod "DRIVER_MODULE);
    return 0;
}

For more details about this APIs called in this code sample refer to Matrix API reference manual

7 Resources

BMP180.pdf

8 Update Log

8.1 Feb-24-2016

  • Added the whole English version

8.2 Feb-26-2016

  • Translated into English

8.3 June-23-2016

  • Re-organized and simplified wiki