1 2 Previous Next 15 Replies Latest reply on Nov 10, 2015 11:06 AM by IRON_CROSS7

    how to read uart'data from  edison board

    李亚兰

      Hello, I'm a green hand on edison development. Uart's api of edison  has initialize  function but no read function.  I need to read uart's data by js. I hope you can give me some advises.

        • 1. Re: how to read uart'data from  edison board
          CMata_Intel

          Hi 李亚兰

           

          I haven't seen examples of UART's using Javascript. But you could try using System Commands and set your UART : Execute A Unix Command With Node.js | DZone

          In order to set, read and write with the UART  using the System Commands I suggest you to follow this thread

          Another way to solve this is using the MRAA pins and try to adapt the examples in order to achieve the use of the UART. Try these options and let me know if results.

           

          Regards;

          CMata

          • 2. Re: how to read uart'data from  edison board
            345ishaan

            Hi CMata_Intel

             

            I am able to get the serial data from RFID Reader in the /dev/ttyMFD1 . I want to read this port using Javascript and send the data to cloud.

            I am trying to do this in Node.js as i want to learn this language. Can you throw some light whether i  am going in the write direction

            None of the two tasks show any output in the XDK console.

            I am using the following code to get the serial data :-

            var SerialPort = require("serialport").SerialPort

            var serialPort = new SerialPort("/dev/ttyMFD1", {

              baudrate: 9600

            });

             

            serialPort.on("open", function () {

              console.log('open');

              serialPort.on('data', function(data) {

                console.log('data received: ' + data);

              });

              serialPort.write("ls\n", function(err, results) {

                console.log('err ' + err);

                console.log('results ' + results);

              });

            });

             

            At the same time , i also tried executing Linux commands from Node.js:-

             

            var sys = require('sys')

            var exec = require('child_process').exec;

            var child;

             

            // executes `pwd`

            child = exec("pwd", function (error, stdout, stderr) {

              console.log("In");

              sys.print('stdout: ' + stdout);

              sys.print('stderr: ' + stderr);

              if (error !== null) {

                console.log('exec error: ' + error);

              }

            });

             

            Please help

            • 3. Re: how to read uart'data from  edison board
              CMata_Intel

              Hi 345ishaan

               

              Sorry for the late response, I saw that you are using the example in this link, so it seems to be fine. But it doesn't seem that this have been tested in an Edison Board yet.

              I suggest you to use the MRAA library.I haven't found examples for SPI using javascript but in that link you will find all the functions that you can use. Take a look at it.

               

              Regards;

              CMata

              • 4. Re: how to read uart'data from  edison board
                345ishaan

                Hi,

                I am not able to get the outputs for serialport code. So i tried running a simple File read code in Intel XDK

                But the thing is the same code which i am trying to do on edison is working on my linux machine.

                Example. Simple file reading code:-

                /********************************************CODE*****************************************************/

                //Type Node.js Here
                var mraa = require('mraa'); //require mraa
                console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the Intel XDK console
                console.log("Ok to go");

                 

                console.log("Hello World");
                var file_handler = require('fs');
                file_handler.open('/home/root/output.txt','r',function(err,fd){
                    if (err) throw(err);
                    var readBuffer = new Buffer(1024),
                                    bufferoffset=0,
                                    bufferlength = readBuffer.length,
                                    fileposition = 0;
                    file_handler.read(fd,readBuffer,bufferoffset,bufferlength,fileposition,
                            function(err,readBytes){
                                if (err) throw err;
                                console.log('just read'+readBytes+'bytes')
                                if(readBytes>0){
                                    console.log(readBuffer.slice(0,readBytes));
                                }
                    });
                });
                /**************************************************************************************************************/

                I think there is some mistake which i am doing .

                 

                 

                Ishan  

                • 5. Re: how to read uart'data from  edison board
                  CMata_Intel

                  Hi Ishan;

                   

                  Try updating the mraa library: (You will need to have a password and wifi set in you Edison)

                  root@edison:~#  ifconfig wlan0 up  
                  root@edison:~#  echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf
                  root@edison:~#  opkg update
                  root@edison:~#  opkg install libmraa0
                  
                  • 6. Re: how to read uart'data from  edison board
                    345ishaan

                    Thanks C_Mata,

                     

                    I will check this out. I have one more query.

                    I wrote a arduino sketch and everytime when i power on the edison , i have to upload the sketch.

                    Is there any way to directly upload the code if i press the reset button, because i want to give a demo to someone and it looks pretty cool.

                    • 7. Re: how to read uart'data from  edison board
                      deium

                      345ishaan,

                      when you compile and upload a sketch, it usually ends up in the /tmp folders.

                      When you have your program worked out, renaming your program from /tmp/myprogramname to /sketch/sketch.elf will cause the Edison to run your sketch as soon as the Edison has been powered on (give or take a bit in loading the rest of the operating system).

                      cp /tmp/myprogramname /sketch/sketch.elf

                      chmod 755 /sketch.sketch.elf

                      After your demo you will want to remove your sketch from the startup process

                      rm /sketch/sketch.elf

                      • 8. Re: how to read uart'data from  edison board
                        CMata_Intel

                        Hi 李亚兰

                         

                        Do you still have questions about this?

                         

                        Best Regards;

                        CMata

                        • 9. Re: how to read uart'data from  edison board
                          李亚兰

                          Thank you. I have already solve this problem with serialport.

                          • 10. Re: how to read uart'data from  edison board
                            krish11

                            Hello CMata_Intel

                             

                            Do you have any idea reading UART data from Intel Edison mini break out board using Arduino-Intel IDE?

                            I have tried this code but can't get anything

                             

                            void setup() {

                              // initialize serial communication at 9600 bits per second:

                              Serial1.begin(9600);

                              delay(5000);

                              Serial1.println("Testing Setup");

                            }

                            // the loop routine runs over and over again forever:

                            void loop() {

                              Serial1.println("Testing Looping");

                              delay(5000);

                            }


                            Can you please help me out?

                            • 11. Re: how to read uart'data from  edison board
                              CMata_Intel

                              Hi krish11

                               

                              Are you using something else (not the GPS shield) to test the communication? Maybe a Logic analyzer

                              Which pins are you using?

                              And remember to use 1.8V as maximum in the inputs for RX in the breakout board.

                               

                              Regards;

                              CMata

                              • 12. Re: how to read uart'data from  edison board
                                krish11

                                Hello CMata_Intel

                                 

                                Sorry, I dont have a Logic analyzer. I am using GPIO131(tx),130(rx) on Intel Edison mini breakout board.

                                Can you help me out in testing UART using Arduino Intel 1.53?

                                 

                                Regards

                                Krish

                                • 13. Re: how to read uart'data from  edison board
                                  CMata_Intel

                                  Hi krish11

                                   

                                  I'm sorry for the delay in my response.

                                  I used this code:

                                  void setup() {
                                    Serial1.begin(9600);
                                    Serial1.println("Testing1");
                                  }
                                  void loop() {
                                    Serial1.println("Testing2");
                                    delay(10);
                                  }
                                  
                                  
                                  
                                  
                                  
                                  
                                  

                                  Using the pins J18-pin13 and J19-pin8 (GP130 and GP131) I was able to see the output of Tx:

                                  Serial1.PNG

                                  I know you don't have a logic analyzer so I tried this other code too:

                                  void setup() {
                                    Serial1.begin(9600);
                                    Serial.begin(9600);
                                    Serial1.println("Testing1");
                                  }
                                  
                                  void loop() {
                                    char x;
                                    Serial1.println("Testing2");
                                    x = Serial1.read();
                                    Serial.println(x);
                                    delay(1000);
                                  }
                                  
                                  
                                  
                                  
                                  
                                  
                                  

                                  For this case, you have to connect the GP130 to the GP131 and you will see the output in the Serial Monitor of the Arduino-IDE. Let me know if this works for you too. You have to see something like:

                                  serial2.PNG

                                  • 14. Re: how to read uart'data from  edison board
                                    krish11

                                    Hello CMata_Intel

                                     

                                    Thank you very much. I have received the same output as said above in console

                                    1 2 Previous Next