GithubHelp home page GithubHelp logo

Comments (2)

paulish avatar paulish commented on June 3, 2024

Sorry, my fault: wiringPiSetupSys can be called as non-root.

Please close this issue.

from wiringpi-node.

TheNotary avatar TheNotary commented on June 3, 2024

I was having some trouble getting it working in non-root mode as well. Based on the docs. I eventually realized I had overlooked ensuring that "the GPIO pins have been exported before-hand using gpio program."

Here's code for non-root

/* 
  Pins:

  black wire  = header 6  = ground    
  orange wire = header 11 = wpi 0 = BCM 17
  yellow      = header 13 = wpi 2
  red         = header 15 = wpi 3
*/

// Setup GPIO pins...
var exec = require('child_process').exec;
var cmd = 'gpio export 0 in && gpio export 2 in && gpio export 3 in';

exec(cmd, function(error, stdout, stderr) {
    // command output is in stdout
    //console.log(error);
    console.log(stdout);
    console.log(stderr);
});


var wpi = require('wiring-pi');
wpi.setup('sys');

var pin = 17; // header 11 or wpi 0 as entered to gpio utility

wpi.pinMode(pin, wpi.INPUT);
wpi.pullUpDnControl(pin, wpi.PUD_UP)

var value = wpi.digitalRead(pin);

console.log("The pin state was: " + value);

edit: err... well the wpi code should actually be placed within that system call function to ensure it occurs sequentially, but the above provides the gist without having to store the export pins as a separate configuration in your system orchestration software.

from wiringpi-node.

Related Issues (20)

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.