Difference between revisions of "Matrix - Pressure and Temperature Sensor/zh"
From FriendlyELEC WiKi
(→与NanoPi M2连接使用) |
(→连接NanoPC-T2) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 35: | Line 35: | ||
[[File:Matrix-Pressure_and_Temperature_Sensor_Calculat.png|frameless|400px|]] | [[File:Matrix-Pressure_and_Temperature_Sensor_Calculat.png|frameless|400px|]] | ||
* 计算海平面气压,使用测量压力P和绝对高度可以计算出海平面气压: | * 计算海平面气压,使用测量压力P和绝对高度可以计算出海平面气压: | ||
− | [[File:Matrix-Pressure_and_Temperature_Sensor_Calculat01.png|frameless|400px|]] | + | [[File:Matrix-Pressure_and_Temperature_Sensor_Calculat01.png|frameless|400px|]] <br> |
这样,不同海拔 Δaltitude = 10米对应于1.2hPa海平面变化。 | 这样,不同海拔 Δaltitude = 10米对应于1.2hPa海平面变化。 | ||
− | == | + | ==硬件连接== |
− | + | ===连接NanoPi NEO/NanoPi NEO Air=== | |
− | + | NanoPi M1和NanoPi NEO以及NanoPi NEO Air的前24Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,并且使用同一份代码。<br> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | 参考下图连接模块:<br> | |
− | < | + | [[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_NEO.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_NEO]] |
− | + | ||
− | + | ||
− | + | 连接说明: | |
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | |Matrix-Pressure_and_Temperature_Sensor || NanoPi NEO | |
− | + | |- | |
+ | |SDA || Pin3 | ||
+ | |- | ||
+ | |SCL || Pin5 | ||
+ | |- | ||
+ | |5V || Pin4 | ||
+ | |- | ||
+ | |GND || Pin6 | ||
+ | |} | ||
− | == | + | ===连接NanoPi M1=== |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_m1.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_m1]] | |
− | [[File:Matrix- | + | |
连接说明: | 连接说明: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | |Matrix- | + | |Matrix-Pressure_and_Temperature_Sensor || NanoPi M1 |
|- | |- | ||
|SDA || Pin3 | |SDA || Pin3 | ||
Line 76: | Line 77: | ||
|} | |} | ||
− | === | + | ===连接NanoPi 2=== |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_2.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_2]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [[File:Matrix- | + | |
连接说明: | 连接说明: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | |Matrix- | + | |Matrix-Pressure_and_Temperature_Sensor || NanoPi 2 |
|- | |- | ||
|SDA || Pin3 | |SDA || Pin3 | ||
Line 162: | Line 95: | ||
|} | |} | ||
− | === | + | ===连接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]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [[File:Matrix- | + | |
连接说明: | 连接说明: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | | | + | | || NanoPi M2 |
|- | |- | ||
− | |SDA || | + | |SDA || Pin3 |
|- | |- | ||
|SCL || Pin5 | |SCL || Pin5 | ||
|- | |- | ||
− | |5V || | + | |5V || Pin4 |
|- | |- | ||
− | |GND || | + | |GND || Pin6 |
|} | |} | ||
− | === | + | ===连接NanoPi M3=== |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix-Pressure_and_Temperature_Sensor_nanopi_M3.jpg|frameless|600px|Matrix-Pressure_and_Temperature_Sensor_nanopi_M3]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [[File:Matrix- | + | |
连接说明: | 连接说明: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | | | + | | || NanoPi M3 |
|- | |- | ||
|SDA || Pin3 | |SDA || Pin3 | ||
Line 348: | Line 132: | ||
|} | |} | ||
− | === | + | ===连接NanoPC-T2/NanoPC-T3=== |
− | + | 由于NanoPC-T2跟NanoPC-T3的引脚是一样的,所以连接方式是一样的,这里仅以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"> | <syntaxhighlight lang="bash"> | ||
− | $ | + | $ apt-get update && apt-get install git |
− | + | $ git clone https://github.com/friendlyarm/matrix.git | |
− | $ | + | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | 克隆完成后会得到一个名为matrix的目录。 | ||
− | + | 编译并安装Matrix: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ cd | + | $ cd matrix |
− | $ | + | $ make && make install |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 运行测试程序: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ matrix-pressure_temp | $ matrix-pressure_temp | ||
</syntaxhighlight> | </syntaxhighlight> | ||
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br> | 注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<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"> | <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 | + | 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(" | + | 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(" | + | 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 406: | Line 204: | ||
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(" | + | printf("The altitude is %.2f m\n", altitude); |
+ | system("rmmod "DRIVER_MODULE); | ||
return 0; | return 0; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | API说明参考维基:[[Matrix API reference manual/zh|Matrix API reference manual]] <br> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [ | + |
Latest revision as of 08:54, 10 November 2016
Contents
1 介绍
- BMP180是一款高精度、小体积、超低能的压力传感器,适用于移动电话、PDAs、GPS导航设备和户外设备。在与仅仅0.25米低空噪音快速转换时,BMP180提供卓越的性能。使用IIC接口可以很轻松的跟主控制器系统进行通讯。
- BMP180基于压阻式技术EMC稳健性、高精度以及线性长期稳定性,被设计用来直接连接带有I2C总线接口的移动设备小型控制器。
- BMP180的EEPROM值会补偿气压以及温度值。BMP180包含压阻式传感器、模拟数字转换器、EEPROM控制单元和IIC接口。
2 特性
- I2C,3.3V
- 气压值 (16 to 19 bit)
- 温度值 (16 bit)
- PCB Dimension(mm): 16 x 16
- 引脚说明:
名称 | 描述 |
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,海拔米可以与国际气压公式计算:
- 计算海平面气压,使用测量压力P和绝对高度可以计算出海平面气压:
这样,不同海拔 Δaltitude = 10米对应于1.2hPa海平面变化。
4 硬件连接
4.1 连接NanoPi NEO/NanoPi NEO Air
NanoPi M1和NanoPi NEO以及NanoPi NEO Air的前24Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,并且使用同一份代码。
参考下图连接模块:
Matrix-Pressure_and_Temperature_Sensor_nanopi_NEO
连接说明:
Matrix-Pressure_and_Temperature_Sensor | NanoPi NEO |
SDA | Pin3 |
SCL | Pin5 |
5V | Pin4 |
GND | Pin6 |
4.2 连接NanoPi M1
连接说明:
Matrix-Pressure_and_Temperature_Sensor | NanoPi M1 |
SDA | Pin3 |
SCL | Pin5 |
5V | Pin4 |
GND | Pin6 |
4.3 连接NanoPi 2
连接说明:
Matrix-Pressure_and_Temperature_Sensor | NanoPi 2 |
SDA | Pin3 |
SCL | Pin5 |
5V | Pin4 |
GND | Pin6 |
4.4 连接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.5 连接NanoPi M3
参考下图连接模块:
Matrix-Pressure_and_Temperature_Sensor_nanopi_M3
连接说明:
NanoPi M3 | |
SDA | Pin3 |
SCL | Pin5 |
5V | Pin4 |
GND | Pin6 |
4.6 连接NanoPC-T2/NanoPC-T3
由于NanoPC-T2跟NanoPC-T3的引脚是一样的,所以连接方式是一样的,这里仅以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