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

onoff-pi5

v1.0.0

Published

GPIO access and interrupt detection with Node.js — Pi 5 compatible (character device API)

Readme

onoff-pi5

Drop-in replacement for onoff with full Raspberry Pi 5 compatibility.

Why this exists

The original onoff uses the Linux sysfs GPIO interface (/sys/class/gpio). The Raspberry Pi 5 uses the RP1 I/O controller chip, whose GPIO is only accessible via the character device API (/dev/gpiochipN). The sysfs interface is absent on Pi 5, making the original onoff non-functional.

This rewrite replaces sysfs with node-libgpiod (character device API) while maintaining 100% API compatibility with the original onoff public interface.


Installation

npm install onoff-pi5
# or if replacing onoff in an existing project:
npm uninstall onoff
npm install onoff-pi5
# then in your code replace:
#   require('onoff')  →  require('onoff-pi5')

System requirement: libgpiod must be installed on the Pi:

sudo apt install libgpiod2 libgpiod-dev

Key differences from original onoff

| Concern | Original onoff | onoff-pi5 | |---|---|---| | GPIO backend | sysfs /sys/class/gpio | Character device /dev/gpiochipN | | Pi 5 support | ❌ No | ✅ Yes | | Pi 1–4 support | ✅ Yes | ✅ Yes (auto-detects chip) | | Interrupt detection | epoll on sysfs value file | 1ms polling via setInterval | | Native dependency | epoll (compiled) | node-libgpiod (compiled) | | API compatibility | — | 100% drop-in |

Interrupt note: The polling approach works well for buttons and switches (debounce tolerance already covers the 1ms poll jitter). For high-frequency interrupts (>500/sec), replace _startWatch() with line.eventWait() in a worker_thread.


gpiochip auto-detection

The library automatically selects the gpiochip with the most lines:

| Board | Chip | Lines | |---|---|---| | Pi 5 (RP1) | gpiochip4 | 54 | | Pi 4 / 3 / 2 | gpiochip0 | 54 |

You do not need to configure this manually.


Usage (identical to original onoff)

const { Gpio } = require('onoff-pi5');

// LED on GPIO17, button on GPIO4
const led    = new Gpio(17, 'out');
const button = new Gpio(4, 'in', 'both');

button.watch((err, value) => {
  if (err) throw err;
  led.writeSync(value);
});

process.on('SIGINT', () => {
  led.unexport();
  button.unexport();
});
// Debounced button with toggle
const { Gpio } = require('onoff-pi5');
const led    = new Gpio(17, 'out');
const button = new Gpio(4, 'in', 'rising', { debounceTimeout: 10 });

button.watch((err) => {
  if (err) throw err;
  led.writeSync(led.readSync() ^ 1);
});

process.on('SIGINT', () => {
  led.unexport();
  button.unexport();
});
// Check accessibility (useful for dev machines without GPIO)
const { Gpio } = require('onoff-pi5');

if (Gpio.accessible) {
  const led = new Gpio(17, 'out');
  led.writeSync(Gpio.HIGH);
  setTimeout(() => { led.writeSync(Gpio.LOW); led.unexport(); }, 1000);
} else {
  console.log('No GPIO available on this system');
}

API

Identical to the original onoff — see https://github.com/fivdi/onoff#api

License

MIT