Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i2c-adt7420

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i2c-adt7420

ADT7420/ADT7410 I2C temperature sensor driver

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

i2c-adt7420

npm version npm license travis build

Node.js driver for the acurate (±0.25°C) yet affordable ADT7420 digital temperature sensor. Should also work with the less accurate ADT7410.

This module was tested using a Raspberry Pi 3 Model B and the EVAL-ADT7420-PMD breakout board. Please do note that the power LED on the EVAL-ADT7420-PMD board significantly influences the temperature reading! The LED or its series resistor should be desoldered if you need accurate temperature.

Supported features:

  • 13 and 16 bit resolution
  • Continuous and one sample per second modes
  • Alternate I2C addresses

Example: ADT7420 temperature server

const express = require('express');
const {ADT7420} = require('i2c-adt7420');

const config = {
  pollingInterval: 1000
  httpPort: 7420,
  i2cBusNumber: 1
};

const app = express();
let adt7420 = null;
let lastUpdateTime = null;
let temperature = null;

app.get('/', (req, res) => {
  res.setHeader('Content-Type', 'application/json');
  res.send(JSON.stringify({
    temperature: {
      raw: temperature.raw,
      celsius: temperature.celsius,
      kelvin: temperature.kelvin
    },
    time_updated: lastUpdateTime
  }));
})

ADT7420.open({
  i2cBusNumber: config.i2cBusNumber
})
  .then((instance) => {
    adt7420 = instance;
    return adt7420.configure({
      resolution: 16,
      lowPowerMode: (config.pollingInterval >= 1000)
    });
  })
  .then(() => {
    console.log('Configured ADT7420');
    return updateTemperature();
  })
  .then(() => {
    console.log(`Read temperature of ${temperature.celsius}C`);
    setInterval(updateTemperature, config.pollingInterval);
    app.listen(config.httpPort, () => {
      console.log(`Serving temperature data on port ${config.httpPort}`);
    });
  })
  .catch((err) => {
    console.error(err);
    process.exit(3);
  });

function updateTemperature() {
  return adt7420.readTemperature()
    .then((result) => {
      lastUpdateTime = new Date();
      temperature = result;
    })
    .catch((err) => {
      console.error(err);
      process.exit(3);
    });
}

API

Class ADT7420

ADT7420.open([options]) -> Promise

Factory method to asynchronously create an instance of the class.

Arguments:

  • options object of options:
    • i2cBusNumber Optional integer specifying the system's I2C device number of the bus the chip is attached to. If you use a Raspberry Pi, this should be 1 for a Raspberry Pi 3 and 0 for older models. Make sure the operating system supports I2C and that it is enabled. Default: 0.
    • i2cAddress Optional, one of ADT7420.I2C_ADDRESS_0x48 (default), ADT7420.I2C_ADDRESS_0x49, ADT7420.I2C_ADDRESS_0x4A, ADT7420.I2C_ADDRESS_0x4B. This only needs to be specified if you have changed the default address of the chip by physically connecting its address configuration pins.

Returns: promise resolving to an ADT7420 class instance when succesful.

ADT7420#configure([options]) -> Promise

Changes the chip's configuration register. Configuring is recommended but not mandatory.

Arguments:

  • options object of options:
    • resolution Optional integer specifying the sample resolution in bits (either 13 or 16). The chip's reset value is 13 bits.
    • lowPowerMode Optional boolean, false for continuous sample mode, true for one sample per second mode. The chip's reset value is false (continuous mode). See datasheet for details.

Returns: promise resolving to undefined when succesful.

ADT7420#readTemperature() -> Promise

Reads the chip's temperature register.

Returns: promise resolving to an ADT7420Temperature instance when succesful.

Class ADT7420Temperature

ADT7420Temperature#raw : Number

Raw temperature reading as a 16-bit two's complement integer.

ADT7420Temperature#celsius : Number

Temperature reading converted to degrees Celsius.

ADT7420Temperature#kelvin : Number

Temperature reading converted to Kelvin.

Keywords

FAQs

Package last updated on 17 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc