add this to bonescript index.js
https://www.youtube.com/watch?v=JJS42HShD7M
analogRead = exports.analogRead = function(pin){
var value = fs.readFileSync("/sys/devices/platform/tsc/ain" +
pin);
return value;
}
have ez1 sonar working on beaglebone. max output voltage at max 255
in. is less than 1.8 volts.
using node.js and processing.js
also blinks led at less than alarm voltage. two views fishview and
default.
client code
Dashboard
Project Files
Open a file or create a new one to get started
p.draw = function(){
p.background(224);
p.textSize(30);
p.fill(0, 102, 153);
myWidth = p.textWidth('sonar ' + inches + ' in');
p.text('sonar ' + inches + ' in', canvasWidth/2 - myWidth/2,
canvasHeight - 40);
var height = (inches/255) * canvasHeight ;
p.arc(xorigin, yorigin, height, height, -120 * Math.PI/180,
-60 *Math.PI/180);
};
p.drawFish = function(){
p.background(224);
p.textSize(15);
p.fill(0, 102, 153);
for (i = 25; i < 255; i+=25){
var height = (i/255) * canvasHeight ;
p.line(0,height, canvasWidth, height);
p.text(i + ' in', 10, height-20);
}
for (j = 0; j < 3; j++){
if (!isNaN(fishArray[j])){
var depth = fishArray[j]/255 * canvasHeight;
var x = canvasWidth/2 + (j*120) - 90;
var y = depth;
p.ellipse(x,y , 70,20);
p.triangle(x-20,y,x-40,y-20, x-40, y+20);
p.text(Math.round(fishArray[j]),x , y + 25);
}
}
};
p.noLoop();
}
var currentProc;
var sonar = new Processing(sonarCanvas, sonarSketchProc);
var socket = io.connect('http://192.168.7.2:8080');
socket.on('reading', function (data) {
var r = document.getElementById('range').value;
var x = parseFloat(data);
// console.log(x);
inches = Math.floor(x);
var dispMode = document.getElementById('display').value
fishArray[count] = x;
server code
var bb = require('./bonescript');
var io = require('socket.io').listen(8080);
var ledPin = bone.P8_3;
var onLed = false;
io.disable('heartbeats');
io.set('log level', 1);
function getReading(){
var raw = parseFloat(analogRead('1'));
// console.log("raw " + raw);
var v = (raw/4096.000)* 1.8;
// console.log("actual voltage " + v);
var inches = v/(3.4/512);
return inches;
}
io.sockets.on('connection', function (socket) {
pinMode(ledPin, OUTPUT);
socket.emit('reading', getReading() );
socket.on('nextReading', function (data) {
socket.emit('reading', getReading());
});
socket.on('toggle',function(data){
if (onLed === false){
digitalWrite(ledPin, HIGH);
onLed = true;
} else {
digitalWrite(ledPin, LOW);
onLed=false;
}
});
socket.on('ledoff',function(data){
digitalWrite(ledPin, LOW);
});
});