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

From FriendlyELEC WiKi
Jump to: navigation, search
Line 139: Line 139:
  
 
==代码说明==
 
==代码说明==
所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-analog_to_digital_converter,内容如下:
+
所有的开发板都共用一套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 i = 0;
+
     int ret = -1;
     int value = 0;
+
     int bmpTemp=0, bmpPressure=0;
     int channel = 0;
+
     int board;
 
+
    float altitude = 0;
     if (argc == 2)
+
   
        channel = atoi(argv[1]);
+
     if ((board = boardInit()) < 0) {
    if (boardInit() < 0)
+
 
         printf("Fail to init board\n");
 
         printf("Fail to init board\n");
 +
        return -1;
 +
    }
 
      
 
      
 
     system("modprobe "DRIVER_MODULE);
 
     system("modprobe "DRIVER_MODULE);
     signal(SIGINT, intHandler);
+
     if ((ret = bmp180Read(BMP180_TEMP, &bmpTemp)) != -1) {
    for (i=0; i<ADC_READ_TIMES; i++) {
+
        printf("The temperature is %.1f C\n", (float)bmpTemp / 10);
        if (pcf8591Read(channel, &value) != -1) {
+
    } else {
            printf("channel%d value=%d\n", channel, value);
+
        printf("Faided to get humidity\n");
        } else {
+
            printf("Fail to get channel%d value\n", channel);
+
            return -1;
+
        }
+
        sleep(1);
+
 
     }
 
     }
 +
    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);
 
     system("rmmod "DRIVER_MODULE);
 
     return 0;
 
     return 0;

Revision as of 10:02, 1 June 2016

English

1 介绍

Matrix-Pressure and Temperature Sensor.png
  • 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

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 硬件连接

4.1 连接NanoPi M1

参考下图连接模块:
Matrix-Pressure_and_Temperature_Sensor_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

连接说明:

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为例。
参考下图连接模块:
Matrix-Pressure_and_Temperature_Sensor_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