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

From FriendlyELEC WiKi
Jump to: navigation, search
(与Tiny4412连接使用)
Line 241: Line 241:
 
==Connect to Tiny4412==
 
==Connect to Tiny4412==
  
==与RaspberryPi连接使用==
+
==Connect to RaspberryPi==
  
==与Arduino连接使用==
+
==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]
  
Line 251: Line 251:
 
===Feb-24-2016===
 
===Feb-24-2016===
 
* Added the whole English version
 
* Added the whole English version
 +
 +
===Feb-26-2016===
 +
* Translated into English

Revision as of 08:00, 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 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 Download Matrix Source Code

All the matrix modules' code samples are open source. They are maintained on GitHub - https://github.com/friendlyarm/matrix.git
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.

  • 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

Please follow the steps below to get the source code:
Install the git utility on a PC running Ubuntu14.04

$ sudo apt-get install git

Clone the matrix code from GitHub

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

If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.

5 Connect to NanoPi 2

5.1 Hardware Connection

Please refer to the following connection diagram to connect the Matrix-Pressure_and_Temperature_Sensor to the NanoPi 2:
Matrix-Pressure_and_Temperature_Sensor_nanopi_2

Connection Details:

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

5.2 Compile Test Program

Please login the matrix hub and enter the nanopi2 branch

$ cd matrix
$ git checkout nanopi2

Compile the matrix code

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

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.
Generated library files are under the "install/lib" directory. The test program is under the "install/usr/bin" directory.
The modules are under the "modules" directory. The driver's source code is in github: https://github.com/friendlyarm/linux-3.4.y.git

5.3 Run Test Program

Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.
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.

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

Insert this TF card to your NanoPi 2, power on and run the following command to load the driver

$ cd /modules
$ insmod bmp085.ko

Start the matrix-pressure_temp program

$ matrix-pressure_temp

Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi 2.
Here is what you expect to observe:
matrix-pressure_temp_result

5.4 Code Sample

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 Connect to NanoPi

6.1 Preparations

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].
Note: please use the kernel's source code from the nanopi-v4.1.y-matrix branch.

$ 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

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.

6.2 Hardware Connection

Please refer to the following connection diagram to connect the Matrix-Pressure_and_Temperature_Sensor to the NanoPi:
Matrix-Pressure_and_Temperature_Sensor_nanopi

Connection Details:

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

6.3 Compile Test Program

Please login the matrix hub and enter the nanopi branch

$ cd matrix
$ git checkout nanopi

Compile the matrix code

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

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.
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".

6.4 Run Test Program

Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.
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.

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

Insert this TF card to your NanoPi, power on and run the following command to load the driver

$ cd /modules
$ insmod bmp085-i2c.ko

Start the matrix-pressure_temp program.

$ matrix-pressure_temp

Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi.

6.5 Code Sample

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 Connect to Tiny4412

8 Connect to RaspberryPi

9 Connect to Arduino

10 Resources

BMP180.pdf

11 Update Log

11.1 Feb-24-2016

  • Added the whole English version

11.2 Feb-26-2016

  • Translated into English