I bought this range finder http://www.dfrobot.com/wiki/index.php/URM37_V3.2_Ultrasonic_Sensor_(SKU:SEN0001)
And now I'm having difficulties to make it work on nodeJS. My setup is Arduino UNO and nodeJs using "firmata" library.
What have i tried: 1. I tested the Rangefinder with native Arduino IDE and it worked. 2. Then i wrote data to EEPROM from Arduino IDE(code exmaple below):
int cmmd1[]={
0x44,0x00,0x10,0x54};//low byte stored in the sensor for the distance threshold.
int cmmd2[]={
0x44,0x01,0x00,0x45};//high byte, write 0x0010 into address 0x01 and 0x00,so the threshold is set to 16cm
int cmmd3[]={
0x44,0x02,0xaa,0xf0};// Autonomous mode. write 0xaa into address 0x02
//int cmmd3[]={
// 0x44,0x02,0xbb,0x01}; // PWM mode. write 0xbb into address 0x02
int i;
void setup(){
Serial.begin(9600); // Sets the baud rate to 9600
A_Mode_Setup(); //PWM mode setup function
}
void loop()
{
}
void A_Mode_Setup(){
//write the data into the URM37 EEPROM
for (i=0;i<4;i++)
Serial.write(cmmd3[i]);
delay(200);
for (i=0;i<4;i++)
Serial.write(cmmd1[i]);
delay(200);
for (i=0;i<4;i++)
Serial.write(cmmd2[i]);
delay(200);
}
I tried to make the same code as it was in the manual to make it work but in nodeJS, and i failed:
var board = new firmata.Board('/dev/cu.usbmodemfd121', function() { var command = [0x44, 0x02, 0xbb, 0x01]; board.pinMode(5, board.MODES.OUTPUT); board.digitalWrite(5, board.HIGH); board.pinMode(3, board.MODES.INPUT); board.sp.write(command, function(err, results) { console.log(arguments) }); var callback = function() { console.log(arguments); //console.log(this) } board.on('pulse-in-3', callback); board.on('pin-state-3', callback); board.pulseIn({ pin: 3, value: board.LOW, timeout: 50 }, callback); setInterval(function() { board.digitalWrite(5, board.LOW); board.digitalWrite(5, board.HIGH); }, 100);
});
Please Guys help me!