Node.js 如何将URM37(测距仪)连接到Arduino并通过NodeJ读取数据

Node.js 如何将URM37(测距仪)连接到Arduino并通过NodeJ读取数据,node.js,arduino,firmata,Node.js,Arduino,Firmata,我买了这个测距仪 现在我很难让它在nodeJS上工作。 我的设置是Arduino UNO和使用firmata库的nodeJs 我试过什么: 1.我用本地的Arduino IDE测试了测距仪,它成功了。 2.然后我将数据从Arduino IDEcode exmaple写入EEPROM,如下所示: int cmmd1[]={ 0x44,0x00,0x10,0x54};//low byte stored in the sensor for the distance threshold. int c

我买了这个测距仪

现在我很难让它在nodeJS上工作。 我的设置是Arduino UNO和使用firmata库的nodeJs

我试过什么: 1.我用本地的Arduino IDE测试了测距仪,它成功了。 2.然后我将数据从Arduino IDEcode exmaple写入EEPROM,如下所示:

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);

}
})


请大家帮帮我

你能解释一下什么不起作用吗。你从node.js中得到错误了吗?如果我有时数码读取pin 3,我会得到错误参数1,有时是0,但没有值。。。但在这种情况下,它不会起任何作用
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);