Giter VIP home page Giter VIP logo

pi-pins's Introduction

pi-pins

Control, read, and monitor Linux GPIO devices from node.js.

A little set of interrupt-supporting wrappers around "/sys/class/gpio" interface, to control pins on e.g. the Raspberry Pi or Beaglebone, as originally written to help get node-nrf off the ground.

It's synchronous/blocking because I forget why (probably to match Tessel?)

Example usage

First add a jumper wire from GPIO pin 17 to GPIO pin 22, and npm install pi-pins. Then:

var pin1 = require("pi-pins").connect(17),
    pin2 = require("pi-pins").connect(22);
pin2.mode('in');
pin1.mode('high'); console.log("Should be true:", pin2.value());
pin1.mode('low'); console.log("Should be false:", pin2.value());
pin2.on('rise', function () {       // …or `'fall'`, or `'both'`
    console.log("RING A DING A LING");
});
pin2.value(true);

API

Here are its methods:

  • var GPIO = require('pi-pins'); — import suggestion, used below
  • var pin = GPIO.connect(number) — get pin ready for use. Could very possibly fail if you don't use sudo to run your script or set perms or whatever. but then, the software and hardware, working together, as one, until the very end
  • pin.mode(direction) — set pin direction to 'in' or 'out' (or go straight to 'low' or 'high' output)
  • pin.value() — read the pin's value ('in' mode)
  • pin.value(boolean) — set the pin's value ('out' mode)

It also does events (parties, weddings):

  • 'rise' — emitted when gpio.value() goes from false to true
  • 'fall' — emitted when gpio.value() goes from true to false
  • 'both' — emitted whenever gpio.value() changes

If a tree might fall/rise/both in the forest and nobody is watching, neither is pi-pins.

Licentious

I sure hope not. But otherwise:

Copyright (c) 2013–2014, Nathan Vander Wilt

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

pi-pins's People

Contributors

natevw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pi-pins's Issues

A question regarding value

I've just got a quick question regarding your use of high/low on set yet returning true/false on get.

Can you give a bit of your reasoning on this? It seems a bit inconsistent to set a value as high and have it return as 'true' rather than 'high'.

Thanks

EPERM, operation not permitted while pin.value(true);

On both a raspberry pi (arch linux arm) and a beaglebone black (debian) I get a permission denied running test.js that came with npm install pi-pins
If I change index.js:46 to use a write() instead of writeSync() there will be no error, however I do want to make sure my write are not just buffered.

trace from node test.js

fs.js:540
return binding.write(fd, buffer, offset, length, position);
^
Error: EPERM, operation not permitted
at Object.fs.writeSync (fs.js:540:18)
at EventEmitter.gpio.value (/root/nrf/node_modules/nrf/node_modules/pi-pins/index.js:46:16)
at Object. (/root/nrf/node_modules/nrf/node_modules/pi-pins/test.js:9:6)

Installation invalid target problem.

Hello every one.
I am trying to install pi-pins on a node project on my raspberry pi b+ (to used a dependent library -nfr-) and I am finding that the target is not valid. Exactly what it says is:

npm ERR! Error: No compatible version found: epoll@'^0.1.3'
npm ERR! Valid install targets:
npm ERR! ["0.0.1","0.0.2","0.0.3","0.0.4","0.0.5","0.0.6","0.0.7","0.0.8","0.1.0","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5","0.1.7","0.1.8","0.1.9"]
npm ERR! at installTargetsError (/home/demon/node/lib/node_modules/npm/lib/cache.js:685:10)
npm ERR! at /home/demon/node/lib/node_modules/npm/lib/cache.js:607:10
npm ERR! at saved (/home/demon/node/lib/node_modules/npm/node_modules/npm-registry-client/lib/get.js:138:7)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Linux 3.12.28+
npm ERR! command "/home/demon/node/bin/node" "/home/demon/node/bin/npm" "install" "pi-pins"
npm ERR! cwd /home/demon/proyectos-node/rf24
npm ERR! node -v v0.10.2
npm ERR! npm -v 1.2.15
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/demon/proyectos-node/rf24/npm-debug.log
npm ERR! not ok code 0

Why do I have this problem? and What could I do to solve it??
THANK YOU VERY MUCH.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.