public
Last active

Use bonescript and node.js to read from all analog pins on a BeagleBone

  • Download Gist
analog-read-all.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
* analog-read-all.js
* Use bonescript and node.js to read from all analog pins on a BeagleBone
* Found in the wild:
* https://groups.google.com/forum/#!msg/beagleboard/rftH6aqyR5k/n7jQbCNAL3YJ
*/
var bb = require('./bonescript');
var sys = require('util');
var fs = require('fs');
 
// default path
ADCPATH = "/sys/bus/platform/devices/tsc/ain";
 
analogRead = function(pin) {
return fs.readFileSync(ADCPATH + (pin+1));
};
 
setup = function() {
};
 
loop = function() {
var i;
for( i = 0; i < 8; i++){
sys.puts("adc" + i + " := " + analogRead(i));
}
 
delay(1000);
};
 
bb.run();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.