https://github.com/ianmetcalf/node-ds2482-temperature
Provides an interface for Dallas DS18B20 temperature sensors over the DS2482 onewire bridge
https://github.com/ianmetcalf/node-ds2482-temperature
beaglebone-black ds18b20 ds2482 onewire raspberry-pi temperature-sensor
Last synced: 3 months ago
JSON representation
Provides an interface for Dallas DS18B20 temperature sensors over the DS2482 onewire bridge
- Host: GitHub
- URL: https://github.com/ianmetcalf/node-ds2482-temperature
- Owner: ianmetcalf
- License: mit
- Created: 2014-12-28T23:41:01.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-04-21T03:07:56.000Z (over 8 years ago)
- Last Synced: 2024-11-13T09:48:01.711Z (11 months ago)
- Topics: beaglebone-black, ds18b20, ds2482, onewire, raspberry-pi, temperature-sensor
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DS18B20 Onewire Temperature Sensor
[](https://gitter.im/ianmetcalf/node-ds2482?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Provides an interface for Dallas DS18B20 temperature sensors over the DS2482 onewire bridge
# Install
```
$ npm install ds2482-temperature
```# Usage
```js
const DS18B20 = require('ds2482-temperature');const sense = new DS18B20();
sense.init()
.then(() => sense.search())
.then(() => sense.readTemperatures()).then(temps => {
console.log(temps); // Returns a list of temperature reading from all found sensors
}).catch(err => {
console.error(err);
});
```## Streaming
```js
const DS18B20 = require('ds2482-temperature');const sense = new DS18B20();
sense.init()
.then(() => {
sense.on('data', val => {
console.log(val);
});sense.on('error', err => {
console.error(err);
});
});
```# API
### new DS18B20([options])
Creates an interface for Dallas DS18B20 temperature sensors. The instance inherites from
[readable stream](https://nodejs.org/api/stream.html#stream_readable_streams)
and will search and emit measurements for all found sensors when a `data` listener is added.__Options:__
- `wire` an instance of [wire](https://github.com/ianmetcalf/node-ds2482)
- `i2c` an instance of [i2c](https://github.com/kelly/node-i2c)
- `address` the i2c address of the bridge chip, default: `0x18`
- `device` the location of the i2c interface, default: `/dev/i2c-1`
- `units` the temperature units, default: `C`
- `pollRate` the rate to poll the sensors when streaming, default: `30 secs`---
### sense.init()
Resets the bridge chip and any onewire devices connected to it__Returns:__ `Promise ` resolves with DS2482 status register
---
### sense.search()
Searches the bus and returns a list of found temperature sensors__Returns:__ `Promise >` resolves with list of sensors
```js
[
,
,
]
```---
### sense.readTemperatures()
Initiates a measurement and returns the temperature readings from all known sensors__Returns:__ `Promise ` resolves with list of temperatures
```js
[
{rom: "2826274402000012", value: 22.9375, units: "C"},
{rom: "28493331020000bf", value: 22.875, units: "C"},
{rom: "280b135f020000d9", value: 21.9375, units: "C"},
]
```---
### sense.destroy()
Destroys the streaming interface---
### new DS18B20.Sensor(rom [, options])
Creates a temperature sensor instance. The instance inherites from
[readable stream](https://nodejs.org/api/stream.html#stream_readable_streams)
and will emit measurements from the sensor when a `data` listener is added.__Arguments:__
- `rom` the ROM address of the sensor as a 16 character hex encoded string__Options:__
- `wire` an instance of [wire](https://github.com/ianmetcalf/node-ds2482)
- `i2c` an instance of [i2c](https://github.com/kelly/node-i2c)
- `address` the i2c address of the bridge chip, default: `0x18`
- `device` the location of the i2c interface, default: `/dev/i2c-1`
- `units` the temperature units, default: `C`
- `pollRate` the rate to poll the sensor when streaming, default: `30 secs`---
### sensor.readTemperature()
Initiates a measurement and returns the temperature reading from a particular sensor__Returns:__ `Promise ` resolves with temperature
```js
22.9375
```---
### sensor.destroy()
Destroys the streaming interface