npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

i2c-sensor-am2315

v2.1.0

Published

I2C communication driver for the AOSONG AM2315 temperature and humidity sensor.

Readme

I2C Driver for Sensor AM2315

Build Status Git Issues NPM Downloads Current Version

I2C communication driver for the AOSONG AM2315 temperature and humidity sensor.

Installation

Using npm

Install via npm using:

npm install i2c-sensor-am2315 --save

Dependencies

To successfully install i2c-bus, and thus this library from npm, access to the i2c-dev interface and library is needed. If you plan to develop on a Mac or PC:

  1. Download the i2c-sensor-am2315 repo.
  2. Comment out the i2c-bus dependency in package.json
  3. Install the i2c-sensor-am2315 module with the path inside your project folder (npm install)

Usage

Using Callback

The driver supports an asynchronous read() command:

// init prerequisites
var Driver = require("i2c-sensor-am2315");

// create device
var device = new Driver();

// read the sensor
device.read(function (err, data) {
  if (err) {
    console.error(err);
  } else {
    console.log("Original in K");
    console.log(data);
    console.log("Convert K to °F");
    console.log(device.convertKelvinToFahrenheit(data));
  }
});

Using Async-Await

You can also use the async-await syntax with the readAsync() command:

// init prerequisites
var Driver = require("i2c-sensor-am2315");

// create device
var device = new Driver();

// read the sensor
var data = await device.readAsync();
console.log("Original in K");
console.log(data);
console.log("Convert K to °F");
console.log(device.convertKelvinToFahrenheit(data));

Result

Original in K
{
  temperature: 296.25,
  temperatureUnit: 'K',
  humidity: 36.3,
  humidityUnit: '%RH',
  crcCheck: true,
  validReading: true
}
Convert K to °F
{
  temperature: 73.58,
  temperatureUnit: '°F',
  humidity: 36.3,
  humidityUnit: '%RH',
  crcCheck: true,
  validReading: true
}

Conversions

Temperature is reported by default in SI units (Kelvin), but the driver comes with built-in temperature conversion functions to °F and °C. The functions can convert both atomic numeric values as well as an object with the same structure as the output data. Methods:

var output = Driver.convertKelvinToCelsius(input);
var output = Driver.convertKelvinToFahrenheit(input);
var output = Driver.convertCelsiusToKelvin(input);
var output = Driver.convertCelsiusToFahrenheit(input);
var output = Driver.convertFahrenheitToKelvin(input);
var output = Driver.convertFahrenheitToCelsius(input);

The output matches the input, if input is numeric, then output is numeric. If input is an object, then so is output, however the function does not modify the original input values

Configuration

Custom driver configuration is available using the following methods, although rarely needed:

Driver.setI2cBusNumber(bus)

Default is 1 - the default I2C bus on the majority of Raspeberry Pi devices. Use an integer value relevant to your device/controller.

// init prerequisites
var Driver = require('i2c-sensor-am2315');

// create device
var device = new Driver;

// set to bus 0 (older Raspberry Pi devices)
device.setI2cBusNumber(0);

Driver.setDeviceAddress(address)

Default is 0x5c - the AM2315 microcontroller uses a fixed address of 0x5c on the I2C bus, you should never have to change this value.

Driver.setReadCmdRegister(register)

Default is 0x03 - also a value you should not have to change, unless you customize this driver library to implement a different read register command.

Driver.setDebugMode(true)

Default is false - set it to true to output additional debugging information to the console.

Compatibility

Tested to work on:

  • Raspberry Pi 2 Model B, Linux raspberrypi 4.1.15-v7+
  • Raspberry Pi 4
  • Raspberry Pi Zero 2

Let me know of other tested devices and I'll add them to the list.