Intel Edison and NodeJS serial port communication: I am receiving strange characters

99封情书 提交于 2019-12-25 06:51:05

问题


I have a FTDI connected to my PC and the FTDI is connected to an Intel Edison Arduino breakout board 0RX and 1TX pins.

Serial pin hookup:
Edison TX ------> FTDI RX
Edison RX ------> FTDI TX

To edit the Intel Edisons GPIO I followed the correct answer in the first post:
https://communities.intel.com/message/265411#265411

To view my GPIO configurations I executed:
cat /sys/kernel/debug/gpio

Which then echoed out:

Nodejs code:

var SerialPort = require("serialport").SerialPort;  
var port = "/dev/ttyMFD1";  
var serialPort = new SerialPort(port, {  
  baudrate: 9600  
}, false);  

console.log("Open port: "+ port);  
serialPort.open(function (error) {  
  if (error) {  
    console.log('Failed to open: '+error);  
  } else {  
    console.log('open');  
    serialPort.on('data', function(data) {  
      console.log('data received: ' + data);  
    });  
    //write data to serial port every second  
    var counter = 90;  
    setInterval(function () {  
      serialPort.write(String(counter)+ "\r\n", function(err) {  
        if(err) {  
          console.log('err ' + err);  
        }else{  
          console.log('Writing data ');  
        }  
      });  
      counter++;  
      if(counter>100)  
        counter =90;  
    }, 1000);  
  }  
});

I then executed:
node uart.js

I get strange characters even when I am not sending characters to the Intel Edison
Strange characters:

I wasn't sure if my nodejs script was causing any issues so I executed: cat /dev/ttyMFD1
which echoed out the same strange characters even when I wasn't sending data to the Intel Edison.

I have no idea why I am receiving the strange characters when I am not sending data to the Intel Edison or how to stop that from happening. I am not sure if I configured my GPIOs correct or if it is noise or what...? What do I need to do to fix/troubleshoot this issue?

To troubleshoot this further I added the following code snippet inside of the serialPort on function:

var s = JSON.stringify(data);
console.log ("data: " + s);

That code produces:
[255,255,255,255]

UPDATE
The issues seems to be with the setInterval function. I remove the set interval and for a test I implemented a for-loop. The loop made 10 rounds successfully sending characters without receiving the garbage characters.


回答1:


To enhance your code, you can enable PIN0/PIN1 for UART usage (TX/RX) with MRAA without to set from the command shell

 var m = require('mraa');
 var uart = new m.Uart(0);



回答2:


The strange characters were due to a really stupid mistake on my part. I forgot to hook the GND from the FTDI board to the GND of the Intel Edison. Once I connected the GNDs together the strange characters stopped.



来源:https://stackoverflow.com/questions/27596728/intel-edison-and-nodejs-serial-port-communication-i-am-receiving-strange-charac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!