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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pi-gpioutil

v0.0.3

Published

A Node wrapper for Wiring Pi's gpio utility.

Downloads

18

Readme

gpioUtil: A Node wrapper for Wiring Pi's gpio

gpioUtil is a Node wrapper for the Wiring Pi gpio utility, which manages the Raspberry Pi’s GPIO pins. It currently supports the core functions:

  • export, unexport, unexportall,
  • read, write, pwm,
  • readall, exports,
  • mode, edge,
  • version.

(Need anything else? File an issue.)

If you’re not sure what all this is about, please read the gpio utility’s page. gpioUtil is really just a very thin wrapper that allows comfortable invocation from a Node program. Here’s the most important bit:

gpio can control, read and write the GPIO pins, and export/unexport pins via the /sys/class/gpio interface, where they will then be available to user programs (without requiring root privileges).

gpio and gpioUtil are by nature not suited for very frequent read/writes (say, more than one call per minute).
(If that’s what you need, try [wiring-pi][wpi-node-addon], which has Node bindings to the native Wiring Pi library. [In my experience][piswitch], it’s fast enough for sub-millisecond precision.)

[wpi-node-addon]: https://github.com/eugeneware/wiring-pi) [piswitch]: https://github.com/tjanson/PiSwitch

Wiring Pi Installation

If you haven’t already, please install Wiring Pi, which includes the gpio utility, [as described on their website][wpi-install]. [wpi-install]: http://wiringpi.com/download-and-install/

Usage

Here’s a simple example of how gpioUtil might be used:

var gpioUtil = require('pi-gpioutil');
var pinBcm = 17; // BCM numbering
var pinWiring = 0; // Wiring Pi numbering (yes, this is confusing)
gpioUtil.export(pinBcm, 'in', function(err) {
  if (!err) {
    gpioUtil.read(pinWiring, function(err, stdout, stderr, value) {
      if (value) console.log('Input is HIGH!');
    });
  }
});

Reference

General information

All functions have the general form fct([[pin, [params]], [callback]), and do the following:

  1. the input parameters are checked for (syntactic) validity
  2. the gpio utility is called via child_process.exec()
  3. the exec()s err, stdout, stderr are passed to the callback (i.e., you may inspect the raw output)
  4. if the call is meant to return data, the utility’s output is converted for easier processing and passed as a fourth parameter (e.g., readall provides a JSON representation of all pins)

Pin numbers are passed untouched, which means that the Broadcom numbers are used for [un]export, while the Wiring Pi numbering scheme is used for everything else. Neither of course matches the physical pin layout.
Confused? So in everyone else, but there’s this really pretty pinout reference by Philip Howard to make up for it.

When reading pins, high and low voltages are converted to the boolean true/false, respectively.

Important functions

Once again, please refer to the gpio utility’s page for details of what a function does; the following will tell you how to call it.
Callback will always be passed err, stdout, stderr as the first three arguments.
Pin numbers are in Wiring Pi format if not noted otherwise.