Difference between revisions of "Matrix - Pressure and Temperature Sensor"
From FriendlyELEC WiKi
Line 37: | Line 37: | ||
Thus, a difference in altitude of ∆altitude = 10m corresponds to 1.2hPa pressure change at sea level. | Thus, a difference in altitude of ∆altitude = 10m corresponds to 1.2hPa pressure change at sea level. | ||
+ | ==硬件连接== | ||
+ | ===连接NanoPi M1=== | ||
+ | 参考下图连接模块:<br> | ||
+ | [[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_m1.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_m1]] | ||
+ | |||
+ | 连接说明: | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | |Matrix-Pressure_and_Temperature_Sensor || NanoPi M1 | ||
+ | |- | ||
+ | |SDA || Pin3 | ||
+ | |- | ||
+ | |SCL || Pin5 | ||
+ | |- | ||
+ | |5V || Pin4 | ||
+ | |- | ||
+ | |GND || Pin6 | ||
+ | |} | ||
+ | |||
+ | ===连接NanoPi 2=== | ||
+ | 参考下图连接模块:<br> | ||
+ | [[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_2]] | ||
+ | |||
+ | 连接说明: | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | |Matrix-Pressure_and_Temperature_Sensor || NanoPi 2 | ||
+ | |- | ||
+ | |SDA || Pin3 | ||
+ | |- | ||
+ | |SCL || Pin5 | ||
+ | |- | ||
+ | |5V || Pin4 | ||
+ | |- | ||
+ | |GND || Pin6 | ||
+ | |} | ||
+ | |||
+ | ===连接NanoPi M2 / NanoPi 2 Fire=== | ||
+ | NanoPi M2和NanoPi 2 Fire的40 Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,这里仅以NanoPi M2为例。<br> | ||
+ | 参考下图连接模块:<br> | ||
+ | [[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_M2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_M2]] | ||
+ | |||
+ | 连接说明: | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | | || NanoPi M2 | ||
+ | |- | ||
+ | |SDA || Pin3 | ||
+ | |- | ||
+ | |SCL || Pin5 | ||
+ | |- | ||
+ | |5V || Pin4 | ||
+ | |- | ||
+ | |GND || Pin6 | ||
+ | |} | ||
+ | |||
+ | ===连接NanoPC-T2=== | ||
+ | 参考下图连接模块:<br> | ||
+ | [[File:Matrix-Pressure_and_Temperature_Sensor_NanoPC-T2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_NanoPC-T2]] | ||
+ | |||
+ | 连接说明: | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | |Matrix-Pressure_and_Temperature_Sensor || NanoPC-T2 | ||
+ | |- | ||
+ | |SDA || Pin6 | ||
+ | |- | ||
+ | |SCL || Pin5 | ||
+ | |- | ||
+ | |5V || Pin29 | ||
+ | |- | ||
+ | |GND || Pin30 | ||
+ | |} | ||
+ | |||
+ | ==编译运行测试程序== | ||
+ | 启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | $ apt-get update && apt-get install git | ||
+ | $ git clone https://github.com/friendlyarm/matrix.git | ||
+ | </syntaxhighlight> | ||
+ | 克隆完成后会得到一个名为matrix的目录。 | ||
+ | |||
+ | 编译并安装Matrix: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | $ cd matrix | ||
+ | $ make && make install | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | 运行测试程序: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | $ matrix-pressure_temp | ||
+ | </syntaxhighlight> | ||
+ | 注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br> | ||
+ | 运行效果如下:<br> | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | The temperature is 26.6 C | ||
+ | The pressure is 983.91 hPa | ||
+ | The altitude is 247.18 | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==代码说明== | ||
+ | 所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-pressure_and_temperature_sensor,内容如下: | ||
+ | <syntaxhighlight lang="c"> | ||
+ | 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; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | API说明参考维基:[[Matrix API reference manual/zh|Matrix API reference manual]] <br> | ||
+ | <!--- | ||
==Download Matrix Source Code== | ==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> | All the matrix modules' code samples are open source. They are maintained on GitHub - https://github.com/friendlyarm/matrix.git <br> | ||
Line 244: | Line 379: | ||
==Connect to Arduino== | ==Connect to Arduino== | ||
+ | ---> | ||
==Resources== | ==Resources== |
Revision as of 14:31, 23 June 2016
Contents
1 Introduction
- 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
- 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:
- With the measured pressure p and the absolute altitude the pressure at sea level can be calculated:
Thus, a difference in altitude of ∆altitude = 10m corresponds to 1.2hPa pressure change at sea level.
4 硬件连接
4.1 连接NanoPi M1
连接说明:
Matrix-Pressure_and_Temperature_Sensor | NanoPi M1 |
SDA | Pin3 |
SCL | Pin5 |
5V | Pin4 |
GND | Pin6 |
4.2 连接NanoPi 2
连接说明:
Matrix-Pressure_and_Temperature_Sensor | NanoPi 2 |
SDA | Pin3 |
SCL | Pin5 |
5V | Pin4 |
GND | Pin6 |
4.3 连接NanoPi M2 / NanoPi 2 Fire
NanoPi M2和NanoPi 2 Fire的40 Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,这里仅以NanoPi M2为例。
参考下图连接模块:
连接说明:
NanoPi M2 | |
SDA | Pin3 |
SCL | Pin5 |
5V | Pin4 |
GND | Pin6 |
4.4 连接NanoPC-T2
参考下图连接模块:
Matrix-Pressure_and_Temperature_Sensor_NanoPC-T2
连接说明:
Matrix-Pressure_and_Temperature_Sensor | NanoPC-T2 |
SDA | Pin6 |
SCL | Pin5 |
5V | Pin29 |
GND | Pin30 |
5 编译运行测试程序
启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库:
$ apt-get update && apt-get install git $ git clone https://github.com/friendlyarm/matrix.git
克隆完成后会得到一个名为matrix的目录。
编译并安装Matrix:
$ cd matrix $ make && make install
运行测试程序:
$ matrix-pressure_temp
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
运行效果如下:
The temperature is 26.6 C The pressure is 983.91 hPa The altitude is 247.18
6 代码说明
所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-pressure_and_temperature_sensor,内容如下:
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; }
API说明参考维基:Matrix API reference manual
7 Resources
8 Update Log
8.1 Feb-24-2016
- Added the whole English version
8.2 Feb-26-2016
- Translated into English