Difference between revisions of "Matrix - Temperature and Humidity Sensor"
(→Connection) |
|||
Line 13: | Line 13: | ||
==How To== | ==How To== | ||
===Connection=== | ===Connection=== | ||
− | *Connect Tiny4412 SDK (1506) | + | *Connect to Tiny4412 SDK (1506) |
::GND: Ground | ::GND: Ground | ||
::VCC: 5V | ::VCC: 5V | ||
− | ::S: GPIO PIN1, this pin has to be connected to an interrupt pin. | + | ::S: GPIO PIN1, this pin has to be connected to an interrupt pin. |
===Code Sample in C Under Linux=== | ===Code Sample in C Under Linux=== |
Revision as of 07:14, 7 August 2015
Contents
1 Introduction
This module utilizes the DHT11 temperature and humidity sensor. The DHT11 sensor's relative humidity range is 20%-80% ±5% and its temperature range is 0℃-50℃ ±2℃. DHT11 uses a single bus communication which needs only one data line. Its DATA line is used for communication and synchronization between the microprocessor and DHT11. Its data format consists of the 8bit humidity integer data and 8bit the Humidity decimal data, and 8 bit temperature integer data and 8bit fractional temperature data and 8 bit parity bit. Its application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability, excellent long-term stability, low cost and long distance (up to 20 meters) signal transmission. We simplified the DHT11's 4-pin to 3-pin.
2 Features
- Humidity range: 20-80%RH, temperature range: 0~50℃
- Humidity accuracy:±5%RH, temperature accuracy: ±2℃
- Single bus (I/O) communication
- 2.54 mm spacing pin
3 How To
3.1 Connection
- Connect to Tiny4412 SDK (1506)
- GND: Ground
- VCC: 5V
- S: GPIO PIN1, this pin has to be connected to an interrupt pin.
3.2 Code Sample in C Under Linux
#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 Compile and Run
git clone http://github.com/friendlyarm/fa-hardware.git cd fa-hardware cd demo cd matrix-temperature_and_humidity_sensor make
Copy your compiled bin to your board and you are ready to go.