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 🙏

© 2026 – Pkg Stats / Ryan Hefner

i2c

v0.4.0

Published

Native bindings for i2c-dev. Plays well with Raspberry Pi and BeagleBone.

Readme

i2c

Native bindings for i2c-dev. Plays well with Raspberry Pi and BeagleBone.

Install

npm install i2c

Requires Node.js >= 18 and a Linux system with I2C support. The native addon uses Node-API for ABI stability across Node.js versions — no recompilation needed when upgrading Node.js.

Usage

const I2C = require('i2c');
const address = 0x18;
const wire = new I2C(address, { device: '/dev/i2c-1' });

wire.on('open', () => {
  // device is ready

  wire.scan((err, data) => {
    // data contains an array of detected device addresses
  });

  wire.writeByte(byte, (err) => {});

  wire.writeBytes(command, [byte0, byte1], (err) => {});

  wire.readByte((err, res) => {
    // res is a single byte
  });

  wire.readBytes(command, length, (err, res) => {
    // res contains a buffer of bytes
  });

  // plain read/write
  wire.write([byte0, byte1], (err) => {});

  wire.read(length, (err, res) => {
    // res contains a buffer of bytes
  });

  // continuous streaming
  wire.on('data', (data) => {
    // data contains: { address, data, cmd, length, timestamp }
  });

  wire.stream(command, length, delay); // delay in ms (default: 100)
  wire.stopStream(); // stop streaming
});

Raspberry Pi Setup

Enable I2C on Raspberry Pi OS:

sudo raspi-config

Navigate to Interface Options > I2C and select Yes to enable.

Alternatively, enable manually:

sudo dtparam i2c_arm=on
sudo modprobe i2c-dev

To load i2c-dev automatically on boot, add it to /etc/modules-load.d/:

echo "i2c-dev" | sudo tee /etc/modules-load.d/i2c.conf

Verify the I2C bus is available:

ls /dev/i2c-*

Install I2C tools for debugging:

sudo apt install i2c-tools
i2cdetect -y 1

By default, the I2C device requires root access. To allow non-root users, add your user to the i2c group:

sudo usermod -aG i2c $USER

Log out and back in for the group change to take effect.

Device path

The default device path is /dev/i2c-1, which is correct for most Raspberry Pi models (2 and later). For the original Raspberry Pi (rev 1), use /dev/i2c-0:

new I2C(address, { device: '/dev/i2c-0' }); // RPi rev 1
new I2C(address, { device: '/dev/i2c-1' }); // RPi 2+ (default)

BeagleBone Setup

I2C is enabled by default on BeagleBone. Install Node.js and the package:

npm install i2c

The I2C buses are available at /dev/i2c-0, /dev/i2c-1, and /dev/i2c-2 depending on your BeagleBone variant. Use i2cdetect to verify:

i2cdetect -l

Projects using i2c

  • bonescript — Physical computing library for BeagleBone (GitHub)
  • mpu6050 — MPU-6050 accelerometer/gyroscope (GitHub)
  • adxl345 — ADXL345 accelerometer (GitHub)
  • mcp3424 — MCP3424 ADC (GitHub)
  • blinkm — BlinkM LED controller (GitHub)

Contributors

Thanks to @alphacharlie, @J-Cat, and all contributors.

Questions?

http://www.twitter.com/korevec