12 Replies Latest reply on Aug 5, 2015 10:14 PM by iceowl

    UART2 for data transfer using NodeJS

    NicolasSchmidt

      I'm using my own breakout board for my project. I wired one sensor to the uart1 and an other to uart2. I can communicate with no problem with the uart1 ttyMFD1 (using SerialPort) but I can't figure out how to communicate with uart2 ttyMFD2. I'm using NodeJS.

       

      I tried the command "fw_setenv bootargs_console" to remove the console from ttyMFD2, but it only bricked my Edison (I can't see it when I connect it to my computer with the mini breakout board). Hopefully I have another one.


      Any idea how to communicate through uart2 with NodeJS?

        • 1. Re: UART2 for data transfer using NodeJS
          CMata_Intel

          Hi NicolasSchmidt

           

          There is another thread where a customer used this code to test this UART I think it worked. Have you tried with this?

           

          //Code from https://communities.intel.com/message/294492#294492
          
          var serialport = require('serialport');
          
          var port = new serialport.SerialPort('/dev/ttyMFD2', {
                  baudrate: 9600,
                  parser: serialport.parsers.readline('\r\n')
              }, false);
          
          port.on('open', function() {
            setInterval(function() {
              console.log('send AT');
              port.write('AT\r\n');
            }, 1000);
            port.on('data', function(line) {
              console.log('data:', line);
            });
          });
          
          port.open();
          
          
          

           

          How are you testing this? Are you checking the signal in another device or are you connected to the board through SSH and sending the code from another IDE?

           

          Regards;

          CMata

          • 2. Re: UART2 for data transfer using NodeJS
            NicolasSchmidt

            Yes I saw that thread. I'm using SerialPort exactly like rosek. It works like a charm on uart1. But, I can't use the line fw_setenv bootargs_console because after that, I can't reboot my Edison.

            • 3. Re: UART2 for data transfer using NodeJS
              bermerlin

              I got the same problem using 'fw_setenv bootargs_console ' after upgrading to the latest firmware revision 2.1 : the Edison freezes forever during reboot, and I had to reflash it from Windows with the 'flashall.bat  and  df-util.exe' method.

               

              So we're back to the initial problem: unable to disable the console from UART2 with the Intel breakout board.

              • 4. Re: UART2 for data transfer using NodeJS
                NicolasSchmidt

                To unfreeze it, I stop the boot by pressing any key at startup. I then enter the commands:


                setenv bootargs_console console=ttyMFD2 earlyprintk=ttyMFD2,keep 

                saveenv

                 

                But it is not helping for using UART2 as data transfer with NodeJS. Any idea???

                • 5. Re: UART2 for data transfer using NodeJS
                  NicolasSchmidt

                  Hi CMata_Intel,

                   

                  I am presently connected through SSH. A device (GPS) is connected with uart2_rx and uart2_tx of my Edison. To make my tests, I also probe the line with the RX of an external FTDI and a terminal program. I also sometime remove the GPS and plug the TX line of the FTDI.

                  • 6. Re: UART2 for data transfer using NodeJS
                    CMata_Intel

                    Hi NicolasSchmidt

                     

                    Do you have results in any of those cases?

                    Let's try to run a sketch using the Arduino IDE with Serial2.begin(9600), remember to use Serial2.end() at the end of the sketch to get back the full functionality of the port to use the Terminal Console? This is just to check the UART2 because you are using a custom board so we could check that everything is good.

                     

                     

                    Regards;

                    CMata

                    • 7. Re: UART2 for data transfer using NodeJS
                      CMata_Intel

                      Hi NicolasSchmidt

                       

                      Do you have results in any of those cases?

                      Let's try to run a sketch using the Arduino IDE with Serial2.begin(), remember to use Serial2.end() at the end of the sketch to get back the full functionality of the port to use the Terminal Console. This is just to check the UART2 because you are using a custom board so we could check that everything is good.

                      Just to be sure, when you use the Terminal Console through a serial cable, is everything working good?

                       

                      Regards;

                      CMata

                      • 8. Re: UART2 for data transfer using NodeJS
                        rosek

                        Hi guys,

                         

                        Just to confirm,- I haven't got luck with the UART2, I'm afraid. In our project we have GSM module connected using UART2 & USB, so we've decided to use USB connection only and move forward with the project.

                         

                        It would be good to figure out why UART2 doesn't work as expected one day, but it wasn't essential at the moment.

                         

                        Best Regards,

                        Krzysztof

                        • 9. Re: UART2 for data transfer using NodeJS
                          rosek

                          I did a bit of testing tonight and can confirm that with the newest image Edison stucks on boot after executing 'fw_setenv bootargs_console' command. However I've noticed that UART2 is usable after stopping console each time after reboot:

                           

                          systemctl stop serial-getty@ttyMFD2.service

                           

                          This means that the devices connected to UART2 still receives a lot of trash during boot time but at least it's possible to communicate with it. I've been trying to disable serial-getty, but it looks like it starts anyway on each time after reboot.

                           

                          Hope this helps.

                          • 10. Re: UART2 for data transfer using NodeJS
                            NicolasSchmidt

                            Thank you rosek!

                             

                            It works! I don't mind the gibberish at boot because I control the power line of the GPS with a MOSFETs switch.

                             

                            Thanks also to CMata_Intel and bermerlin for your help!

                            • 11. Re: UART2 for data transfer using NodeJS
                              iceowl

                              After executing the systemctl command suggested above I was successful in using UART2.

                              I am also trying to use UART2 to communicate to a GPS module, thereby freeing UART1 to speak to something else. 

                              However, like many others I have found that if I leave the GPS connected physically to the GPIO pins while booting - the boot process stalls.  The solution seems to be, as NicolasSchmidt says, to totally disconnect from UART2 (he uses a MOSFET switch).  Then you can boot.  If you do not do this - it's not that the device on UART2 sees gibberish, but clearly if your device responds with some sort of gibberish it can stall the boot process.

                               

                              Cheers

                              Joe

                              • 12. Re: UART2 for data transfer using NodeJS
                                iceowl

                                UPDATE from my end:

                                 

                                Ok - here is what is working for me reliably.  Nothing else seemed to do it with release 2.1   No matter what I did I was getting trash from the console.

                                 

                                I created an /etc/init.d directory.

                                 

                                Inside that directory I created a file called disableConsole.sh which looks like this:

                                 

                                #!/bin/sh

                                #systemctl stop serial-getty@ttyMFD2.service

                                systemctl start serial-getty@ttyS0.service

                                console=ttyS0


                                Then I added it to the boot sequence with update-rc.d disableConsole.sh defaults


                                And everything seems fine.


                                The problem I was having was that when I stopped serial-getty on ttyMFD2 after bootup, then mraa::Uart would not work at all from C++ in eclipse.  I needed to keep that going for some reason.

                                Nor does clearing bootargs_console work at all.  The system refuses to boot with no tty for the console.  


                                I tried pointing the console to /dev/null but that also resulted in the system freezing on bootup.

                                I'm hoping that what I have accomplished is to aim the console somewhere else - I was hoping to a pseudo tty, but this worked the first time I tried it so I just left it alone.  I have no clue if it actually does what I'm intending it to do, but I can boot the Edison and use UART2 with no junk coming through (after boot up).  I was previously getting console dreck coming through after bootup...


                                Cheers,


                                Joe