Skip to content

Instantly share code, notes, and snippets.

@matzipan
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzipan/8c56a0226dab00a6b3cd to your computer and use it in GitHub Desktop.
Save matzipan/8c56a0226dab00a6b3cd to your computer and use it in GitHub Desktop.
Node.js Raspberry Pi clock source
  1. First, you need to install node.js and npm using the following command.
sudo apt-get install nodejs npm node-semver
  1. Second, you need to install the wiring-pi package.
npm install wiring-pi

The module will be installed in your home directory, so make sure to run the scripts in there. It also depends on another package, node-gyp, which compiles the wiring-pi bindings from source, so it may require gcc and other tools.

  1. Run the script using
sudo node clock.js

The sudo is necessary because wiring-pi accesses some hardware peripherals directly.

var wpi = require('wiring-pi');
wpi.setup('wpi');
// wiring-pi has its own pin numbering scheme: http://wiringpi.com/pins/
wpi.pinMode(15, wpi.modes.OUTPUT);
setInterval(function() {
console.log("HIGH");
wpi.digitalWrite(15, wpi.HIGH);
setTimeout(function() {
console.log("LOW");
wpi.digitalWrite(15, wpi.LOW);
}, 1500);
}, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment