1

I want to make a game with Javascript with LED and pushbutton interaction. My problem is: I don't know how to make Javascript "talk" with the GPIO pins. Any help would be highly appreciated.

  • Did you look at npmjs.com/package/pi-gpio ? – mpromonet Mar 15 '15 at 10:12
  • No ill have a look thx. – Daniel Lewis Mar 15 '15 at 10:43
  • If that works for you please add it as an answer yourself. I'm not sure if node.js modules can be used outside of node but I believe they can -- if you need help with that look/ask on Stack Overflow. Or maybe you'll want to use node as the server, it is a pretty cool thing. – goldilocks Mar 15 '15 at 13:08
  • @goldilocks If by "using outside node" you means in a web browser, surely not. The pi-gpio use the gpio sysfs to access to gpio, then it need a node server. I don't think there is a web browser API that give access to raspberry gpio. – mpromonet Mar 15 '15 at 16:20
  • @mpromonet You are most likely right. I did notice there is a node system for "browserifying" modules for use on the client, but there are probably restrictions on that WRT hardware access. If the OP is programming games in js I'd think a node server would be right up his alley anyway. – goldilocks Mar 15 '15 at 16:30
2

Yes. you can use Node-Red with gpio contrib. Its visual programming with javascript.

https://www.npmjs.com/package/node-red-contrib-gpio

Also, you can try cylonjs. It supports many platforms other than raspberry pi.

http://cylonjs.com/documentation/platforms/raspberry-pi/

0

WebIOPi has a REST API that can be accessed via a JavaScript client, so I believe that should fit your needs.

0

Yes (as noted by @mpromonet);

var gpio = require("pi-gpio");

gpio.open(16, "output", function(err) {     // Open pin 16 for output 
    gpio.write(16, 1, function() {          // Set pin 16 high (1) 
        gpio.close(16);                     // Close pin 16 
    });
});

Documentation pi-gpio node.js based library npm package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.