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

From FriendlyELEC WiKi
Jump to: navigation, search
(Created page with " ==介绍== 此配件搭载DHT11温湿度传感器。DHT11是一款入门级传感器,湿度采集范围为20%-80%,误差为5%,温度采集范围为0℃-50℃,误差...")
 
Line 1: Line 1:
 
 
 
==介绍==
 
==介绍==
 +
[[File:TemperatureAndHumiditySensor.png|thumb|Temperature and Humidity Sensor]]
 
此配件搭载DHT11温湿度传感器。DHT11是一款入门级传感器,湿度采集范围为20%-80%,误差为5%,温度采集范围为0℃-50℃,误差为±2℃,适合要求不高的场合使用。我们把DHT11的4针引脚简化为3针引出,并在PCB上加上固定孔,方便您安装使用。
 
此配件搭载DHT11温湿度传感器。DHT11是一款入门级传感器,湿度采集范围为20%-80%,误差为5%,温度采集范围为0℃-50℃,误差为±2℃,适合要求不高的场合使用。我们把DHT11的4针引脚简化为3针引出,并在PCB上加上固定孔,方便您安装使用。
 
==特性==
 
==特性==
Line 7: Line 6:
 
* 一线协议
 
* 一线协议
 
* 2.54mm排针接口,接线方便,通用性强
 
* 2.54mm排针接口,接线方便,通用性强
 +
==使用方法==
 +
===连接===
 +
*连接到Tiny4412 SDK (1506)
 +
::GND针脚:    接地
 +
::VCC:  接5V
 +
::S针脚:接GPIO PIN1, 必须使用中断引脚,可用引脚(1、2、3、4、9、10)
 +
 +
===Linux下的C示例===
 +
<syntaxhighlight lang="c">
 +
#include <stdio.h>
 +
#include <stdlib.h>
 +
#include "libfahw.h"
 +
 +
void parseCmd(int argc, char **argv, int *pin)
 +
{
 +
    int num = atoi(argv[1]);
 +
    switch(num) {
 +
    case 1:
 +
        *pin = TINY4412_GPIO_PIN1;
 +
        break;
 +
    case 2:
 +
        *pin = TINY4412_GPIO_PIN2;
 +
        break;
 +
    case 3:
 +
        *pin = TINY4412_GPIO_PIN3;
 +
        break;
 +
    case 4:
 +
        *pin = TINY4412_GPIO_PIN4;
 +
        break;
 +
    case 9:
 +
        *pin = TINY4412_GPIO_PIN9;
 +
        break;
 +
    case 10:
 +
        *pin = TINY4412_GPIO_PIN10;
 +
        break;
 +
    default:
 +
        printf("Unsupported pin TINY4412_GPIO_PIN%d\n", num);
 +
        num = 1;
 +
        *pin = TINY4412_GPIO_PIN1;
 +
    }
 +
    printf("Using pin TINY4412_GPIO_PIN%d\n", num);
 +
}
 +
 +
int main(int argc, char ** argv)
 +
{
 +
    int ret = -1;
 +
    int dhtTemp = 0;
 +
    int dhtHdty = 0;
 +
    int devFD = -1;
 +
    int pin = TINY4412_GPIO_PIN1;
 +
 +
    if (argc == 2) {
 +
        parseCmd(argc, argv, &pin);
 +
    } else {
 +
        printf("Using default pin TINY4412_GPIO_PIN1\n");
 +
    }
 +
    if ((devFD = dht11Init(pin)) == -1) {
 +
        printf("Fail to init dht11\n");
 +
        return -1;
 +
    }
 +
 +
    if ((ret = dht11Read(DHT_HUMIDITY, &dhtHdty)) != -1) {
 +
        printf("Get humidity : %d\n", dhtHdty);
 +
    } else {
 +
        printf("Faided to get humidity\n");
 +
    }
 +
 +
    if ((ret = dht11Read(DHT_TEMP, &dhtTemp)) != -1) {
 +
        printf("Get temperature : %d\n", dhtTemp);
 +
    } else {
 +
        printf("Faided to get temperature\n");
 +
    }
 +
 +
    dht11DeInit(devFD);
 +
    return ret;
 +
}
 +
</syntaxhighlight>
 +
 +
===编译并运行示例===
 +
<syntaxhighlight lang="bash">
 +
git clone http://github.com/friendlyarm/fa-hardware.git
 +
cd fa-hardware
 +
cd demo
 +
cd matrix-temperature_and_humidity_sensor
 +
make
 +
</syntaxhighlight>
 +
将编译生成的dht11通过ftp上传到开发板上运行即可测试。
 +
 +
==相关资料==

Revision as of 08:23, 27 July 2015

1 介绍

Temperature and Humidity Sensor

此配件搭载DHT11温湿度传感器。DHT11是一款入门级传感器,湿度采集范围为20%-80%,误差为5%,温度采集范围为0℃-50℃,误差为±2℃,适合要求不高的场合使用。我们把DHT11的4针引脚简化为3针引出,并在PCB上加上固定孔,方便您安装使用。

2 特性

  • 20%-80%,+-5%,0℃-50℃, +-2℃
  • 一线协议
  • 2.54mm排针接口,接线方便,通用性强

3 使用方法

3.1 连接

  • 连接到Tiny4412 SDK (1506)
GND针脚: 接地
VCC: 接5V
S针脚:接GPIO PIN1, 必须使用中断引脚,可用引脚(1、2、3、4、9、10)

3.2 Linux下的C示例

#include <stdio.h>
#include <stdlib.h>
#include "libfahw.h"
 
void parseCmd(int argc, char **argv, int *pin)
{
    int num = atoi(argv[1]);
    switch(num) {
    case 1:
        *pin = TINY4412_GPIO_PIN1;
        break;
    case 2:
        *pin = TINY4412_GPIO_PIN2;
        break;
    case 3:
        *pin = TINY4412_GPIO_PIN3;
        break;
    case 4:
        *pin = TINY4412_GPIO_PIN4;
        break;
    case 9:
        *pin = TINY4412_GPIO_PIN9;
        break;
    case 10:
        *pin = TINY4412_GPIO_PIN10;
        break;
    default:
        printf("Unsupported pin TINY4412_GPIO_PIN%d\n", num);
        num = 1;
        *pin = TINY4412_GPIO_PIN1;
    }
    printf("Using pin TINY4412_GPIO_PIN%d\n", num);
}
 
int main(int argc, char ** argv)
{
    int ret = -1;
    int dhtTemp = 0;
    int dhtHdty = 0;
    int devFD = -1;
    int pin = TINY4412_GPIO_PIN1;
 
    if (argc == 2) {
        parseCmd(argc, argv, &pin);
    } else {
        printf("Using default pin TINY4412_GPIO_PIN1\n");
    }
    if ((devFD = dht11Init(pin)) == -1) {
        printf("Fail to init dht11\n");
        return -1;
    }
 
    if ((ret = dht11Read(DHT_HUMIDITY, &dhtHdty)) != -1) {
        printf("Get humidity : %d\n", dhtHdty);
    } else {
        printf("Faided to get humidity\n");
    }
 
    if ((ret = dht11Read(DHT_TEMP, &dhtTemp)) != -1) {
        printf("Get temperature : %d\n", dhtTemp);
    } else {
        printf("Faided to get temperature\n");
    }
 
    dht11DeInit(devFD);
    return ret;
}

3.3 编译并运行示例

git clone http://github.com/friendlyarm/fa-hardware.git
cd fa-hardware
cd demo
cd matrix-temperature_and_humidity_sensor
make

将编译生成的dht11通过ftp上传到开发板上运行即可测试。

4 相关资料