I am trying to control a raspberry pi through web socket. I found a similar project and have been building my project around it. I have managed to get everything except a distance sensor working.
tank.getDistance = function () {
async.parallel([
gpio.write(trig,0),
gpio.write(trig,1),
gpio.write(trig,0),
]);
var start,stop;
while(gpio.read(echo) == 0){start = Date.now();}
while(gpio.read(echo) == 1){stop = Date.now();}
var distance = ((stop-start)/1000.0)*17000
console.log("distance: "+ distance);
};
this is how i am trying to read from the ultrasonic sensor. I have tested this logic in python and it was working there.
socket.on('keydown', function (dir) {
switch (dir) {
case 'up':
tank.moveForward();
console.log("forward");
tank.getDistance();
break;
...
this is where i call the function. But every time I call this function, I get a
/home/pi/marinaBot/marinaBot/node_modules/rpi-gpio/rpi-gpio.js:286
throw new Error('A callback must be provided')
^
Error: A callback must be provided
at Gpio.read.input (/home/pi/marinaBot/marinaBot/node_modules/rpi-gpio/rpi-gpio.js:286:19)
at Object.tank.getDistance (/home/pi/marinaBot/marinaBot/app.js:78:14)
not sure why this is occurring as I am not returning anything. I have tried using other ultrasonic libraries like "r-pi-usonic" but I dont understand the setup of it. Any Ideas? Just starting to learn NodeJS. this may be something realluy simple.