Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/depuits/pigpio-dht
DHT implementation using node.js and pigpio.
https://github.com/depuits/pigpio-dht
dht pigpio pigpio-dht sensor
Last synced: about 2 months ago
JSON representation
DHT implementation using node.js and pigpio.
- Host: GitHub
- URL: https://github.com/depuits/pigpio-dht
- Owner: depuits
- License: apache-2.0
- Created: 2018-02-23T11:10:07.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-26T13:12:17.000Z (over 5 years ago)
- Last Synced: 2024-10-07T10:30:00.686Z (3 months ago)
- Topics: dht, pigpio, pigpio-dht, sensor
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 15
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pigpio-dht
Dht sensor control using node.js and pigpio. Supported sensors are DHT11, DHT22 and AM2302.
## Installation
1. Install [pigpio C library](https://github.com/joan2937/pigpio).
2. Install module: `npm i pigpio-dht`.## Usage
```javascript
const dht = require('pigpio-dht');
const sensor = dht(dataPin, dhtType);
```| Sensor | dhtType |
|-----------------|:----------------:|
| DHT11 | 11 |
| DHT22 or AM2302 | 22 |### Example
```javascript
const dht = require('pigpio-dht');const dataPin = 5;
const dhtType = 22; //optional
const sensor = dht(dataPin, dhtType);setInterval(() => {
sensor.read();
}, 2500); // the sensor can only be red every 2 secondssensor.on('result', data => {
console.log(`temp: ${data.temperature}°c`);
console.log(`rhum: ${data.humidity}%`);
});sensor.on('badChecksum', () => {
console.log('checksum failed');
});
```### Methods
#### `read()`Start a new reading of the sensor. This can't be called more then once every second for the DHT11 sensor or once every 2 seconds for the DHT22 sensor.
### Events
#### `start`
Emitted when starting to read a value.
#### `end`
Emitted when the reading stops. This because it was complete, an error occurred or anything else.
#### `result`
- result object containing temperature and humidity
Emitted when the reading was completed successful.
#### `badChecksum`
Emitted when finished reading but the checksum was invalid.
## Built With
* [pigpio](https://github.com/fivdi/pigpio) - Gpio wrapper for nodejs
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/depuits/pigpio-dht/tags).