6 Replies Latest reply on Sep 12, 2015 2:26 PM by KimLorentz

    Adafruit GPS and javascript - Help needed

    KimLorentz

      I tryed making a javascript for reading GPS data from Adafruit GPS board.

      I have programmed SparkFun Block for Intel® Edison - Arduino to send RMC and GGA data and send it out true UART1 at baud rate 115200.(Reason is I dont have anything to reduse 3.3 voltage to 1.8.)

      arduinoblock.jpgGPS.jpgminiboard.jpg

       

      I tryed using this code for reading GPS data to the console.log but nothings happening after console.log('GET GPS data');

       

      var m = require('mraa'); //require mraa
      var fs = require('fs'); // require filesystem
      
      
      u = new m.Uart(0);              // /dev/ttyMFD1
      
      console.log(u.getDevicePath());
      
      
      var SerialPort = require("serialport").SerialPort;
      var serialPort = new SerialPort(u.getDevicePath(), {
        baudrate: 115200
      });
      
      // receive GPS (approx every second)
      
      
      serialPort.on("open", function () {
      
        console.log('GET GPS data');
        serialPort.on('data', function(data) {
            var data_string = '' + data
            if (data_string.substring(0,6) == '$GPGGA') {
      gpgga_string = data_string.split('\n')[0];
                gpgga_string = gpgga_string.replace('\n', '');
                gps_data = gpgga_string.split(',');
                console.log('data received: ' + gps_data);
                var time_string = gps_data[1];
                var gps_time = new Date();
                var gps_time_hours = parseInt(gps_data[1].substring(0,2));
                var gps_time_minutes = parseInt(gps_data[1].substring(2,4));
                var gps_time_seconds = parseInt(gps_data[1].substring(4,6));
                gps_time.setHours(gps_time_hours);
      gps_time.setMinutes(gps_time_minutes);
      gps_time.setSeconds(gps_time_seconds);
               
                gps_lat = gps_data[2];
                gps_lat_ns = gps_data[3];
                gps_lon = gps_data[5];
                gps_lon_ew = gps_data[6];
                console.log('gps_time', gps_time);
                console.log(gps_lat, gps_lat_ns);
      
            }
        });
      });
      
      
      // round off output to match C example, which has 6 decimal places
      function roundNum(num, decimalPlaces)
      {
                      var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
                      return (Math.round((num + extraNum)
                                     * (Math.pow(10, decimalPlaces))) / Math.pow(10, decimalPlaces));
      }
      
      

       

      I am also using Intel Edison mini breakout board and not Arduino board.

       

      Anyone now what I did wrong??

        • 1. Re: Adafruit GPS and javascript - Help needed
          DiegoV_Intel

          Hello KimLorentz,

           

          I don’t have the GPS module or the SparkFun block to try to reproduce your project. However, there are some general suggestions that you can try in order to debug your code and hardware settings:

           

          1. Make sure the voltage levels are compatible between the Edison and the GPS module (or any other hardware you have). The Edison module is 1.8V tolerant. If you are using the Mini-Breakout Board you have to use a voltage translator, but if you are using the Arduino SparkFun block you don't need one because the IOs are tied to the ATMEGA328.
          2. Make sure the serial interface is working properly. Sometimes, issues related with serial devices are caused by the Edison (or the "control system") which doesn't send the data correctly, or because of the hardware setup, the data is corrupted by noise. Make sure the serial data received by the GPS module is actually the data sent by Edison.
          3. Adafruit offers a very good guide for the GPS module. The guide is for Arduino usage. I haven't used the Arduino SpakFun block, but you might want to use the Adafruit's guide with it: Overview | Adafruit Ultimate GPS | Adafruit Learning System

           

          Regards,

          Diego.

          • 2. Re: Adafruit GPS and javascript - Help needed
            KimLorentz

            I Tryed this code under here and got somthing, but Its not clear text.

             

            var com = require("serialport");
            
            var serialPort = new com.SerialPort("/dev/ttyMFD1", {
                baudrate: 115200,
                parser: com.parsers.readline('\r\n')
              });
            
            serialPort.on('open',function() {
              console.log('Port open');
            });
            
            serialPort.on('data', function(data) {
              console.log(data);
            });
            
            
            

             

            Maby I can program the Sparkfun board to send Des, Hex, Oct and Char with 1 second interval to se what give me the right output to console.log?

            Is it possible to use char c to read serial data? I know that is what is done to read GPS data on the arduino boards.

            Like this link: Arduino - Print

             

             

            The data I got was:

            Intel XDK - Message Received: run                                                                                                                                                                                                                        

            Port open                                                                                                                                                                                                                                                

            pp\�LvwqwNtrsxL�LpqtswNgstsL�lpNaaLrsfNrpLsq`xquLl\�Jvy                                                                                                                                                                                                  

            D�����lrsv^r`L�LL�L`Nqql�LpNrpL�\�Js�                                                                                                                                                                                                                    

            D�����\rprcrvN`ppLvgqgNtrsx\�LpqtswNwsts\�LqLyLpNyqLy^qL�\suNyL�LLJuuD�����L�\sLpyLruLpvLrsLpsLprLcrLrfLsqL\LLq^rvLp^yqLpNxgZp�                                                                                                                          

            d�����Lrprsrvnppp\�LvwqwNtrsxL�LpqtswNgstsL�LpNqwLrcvNrplsq`xquLlL�Jv�                                                                                                                                                                                   

            D�����lrsfNrpl�L\�lpNagL�LpNsb\�L�Js�                                                                                                                                                                                                                    

            D�����Lrpbsrwnpp`\vwqgntrsyl�L`atswnwstsL�La\yLqnpw\ynqL�LseNyL�L\Ju�                                                                                                                                                                                    

            D�����l�lsL`yLreLpvLrsL`sLprlcr\bvLsa\lLLrnpg\qNpw\qNwxJpp                                                                                                                                                                                               

            D�����LrprsbwNpppL�lfwqw^trcy\�LpqtcwNwstc\�LpnrqLbsvNbpLsqpxqu\LL�Zvyd�����\rsvNr`\�Ll�LpNbqL�\pNcyl�L�Jsq                                                                                                                                              

            D�����LrprsrxNpppLfwqgntrsyL�LpqtcgNwstrL�Lqly\`^yqlyNqL�lse^yL�llJu�                                                                                                                                                                             

            D�����L�Ls\`yLrulpv\rsLpclpr\srLbvLsqlLLLaNrvLpNyalpNxwJp�                                                                                                                                                                                               

            D�����lbprsrxN``pL�LvwqgNtrsy\�Lpqtsg^wstbL�\`NrwlrsfNrpLcapxqulL\�Jvq                                                                                                                                                                                   

            D�����LrcvNr`L�LL�LpNbw\�LpNe`L�L�jsx

            • 3. Re: Adafruit GPS and javascript - Help needed
              Frederick Blais

              This really looks like you don't have the right baudrate. On the module datasheet, its written that the default baudrate is 9600.

              • 4. Re: Adafruit GPS and javascript - Help needed
                KimLorentz

                Yes but I used the Sparkfun arduino board to transmitt the GPS data and that one is set to 115200.

                But I will take a second look at the arduino code on the Sparkfun board, maby it is 9600.

                • 5. Re: Adafruit GPS and javascript - Help needed
                  KimLorentz

                  I tryed a new code like this under:

                  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");
                  
                  
                  var SerialPort = require("serialport").SerialPort
                  var serialPort = new SerialPort("/dev/ttyMFD1", {
                    baudrate: 115200
                  });
                  
                  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);
                    });
                  });
                  
                  
                  
                  
                  
                  

                   

                  This is what I got from console.log

                   

                  Intel XDK - Message Received: run                                                                                                                                                                                                                      
                  MRAA Version: v0.7.3
                  Ok to go
                  open
                  err undefined
                  results 3
                  
                  
                  
                  
                  
                  

                   

                  I even tryed using Arduino IDE and uploaded serial to serial1 communication with the same error. And reprogrammed the sparkfun arduino board to from 115200 to 9600

                   

                  My it be somthing wrong with the sparkfun board or uart pins on the Edison?

                   

                  Update!!

                   

                  I got my selv an TXB0104 Bi-Directional Level Shifter, what is the best way to connect it to the Intel Edison mini breakup board?

                  shifter.jpg

                   

                  What about re-programming an Arduino Pro mini to work like an i2c? make it read GPS data and send true i2c. Making me able to get data true i2c and not UART

                  • 6. Re: Adafruit GPS and javascript - Help needed
                    KimLorentz

                    I found out what was wrong. Due to software serial to serial programming on the edison board without use of string and buffer the sparkfun board does not transmitt the software serial to serial the right way. By connecting the GPS board to the TXB0104 level shifter and then to the uart1 pin on the Edison board I was able to get the correct data.

                    Only bad part is it does not working sending data to the GPS module.

                     

                    So I programmed the Sparkfun Arduino board.

                    #include <SoftwareSerial.h>
                    
                    
                    SoftwareSerial mySerial(10, 11); // TX - GSM, RX - GSM
                    
                    
                    void setup() 
                    {
                      // Open serial communications and wait for port to open:
                      Serial.begin(9600);
                      mySerial.begin(9600);
                    }
                    
                    
                    void loop() // run over and over
                    {
                    if (mySerial.available())
                        Serial.write(mySerial.read());
                       
                    if (Serial.available())
                      {
                        while(Serial.available())
                        {
                          mySerial.write(Serial.read());
                        }
                        mySerial.println();
                      }
                    }
                    
                    

                     

                    And edit the JavaScript code.

                    var m = require('mraa'); //require mraa
                    var fs = require('fs'); // require filesystem
                    
                    
                    u = new m.Uart(0);              // /dev/ttyMFD1
                    console.log(u.getDevicePath());
                    
                    
                    var SerialPort = require("serialport").SerialPort; // npm install serialport
                    var serialPort = new SerialPort("/dev/ttyMFD1", {
                      baudrate: 9600
                    });
                    
                    
                    // receive GPS (data)
                    var PMTK_SET_NMEA_UPDATE_1HZ = "$PMTK220,1000*1F"
                    var PMTK_SET_NMEA_UPDATE_5HZ = "$PMTK220,200*2C"
                    var PMTK_SET_NMEA_UPDATE_10HZ = "$PMTK220,100*2F"
                    
                    
                    // turn on only the second sentence (GPRMC)
                    var PMTK_SET_NMEA_OUTPUT_RMCONLY = "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
                    // turn on RMC and GGA
                    var PMTK_SET_NMEA_OUTPUT_RMCGGA = "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
                    // turn on RMC, GGA and GSA
                    var PMTK_SET_NMEA_OUTPUT_RMCGGAGSA = "$PMTK314,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
                    // turn on ALL THE DATA
                    var PMTK_SET_NMEA_OUTPUT_ALLDATA = "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
                    // turn off output
                    var PMTK_SET_NMEA_OUTPUT_OFF = "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
                    // Standby
                    var PMTK_STANDBY = "$PMTK161,0*28"
                    //
                    var PMTK_Q_RELEASE = "$PMTK605*31"
                    // Ant off
                    var PMTK_ANT_OFF = "$PGCMD,33,0*6D"
                    // Active Interference Cancellation (AIC) Disable
                    var PMTK_AIC_OFF = "$PMTK286,0*22"
                    // Active Interference Cancellation (AIC) Enable
                    var PMTK_AIC_ON = "$PMTK286,1*23"
                    
                    
                    serialPort.on("open", function () {
                      console.log('GET GPS data');
                        serialPort.write(PMTK_SET_NMEA_OUTPUT_RMCGGA + "\r\n");     // RMC and GGA
                        serialPort.write(PMTK_SET_NMEA_UPDATE_1HZ + "\r\n");        // 5Hz
                        serialPort.write(PMTK_AIC_ON + "\r\n");                     // AIC ON
                      serialPort.on('data', function(data) {
                          var data_string = '' + data
                          //console.log(data_string);
                          if (data_string.substring(0,6) == '$GPGGA') {
                              gpgga_string = data_string.split('\n')[0];
                              gpgga_string = gpgga_string.replace('\n', '');
                              gps_data = gpgga_string.split(',');
                              console.log('data received: ' + gps_data);
                              var time_string = gps_data[1];
                              var gps_time = new Date();
                              var gps_time_hours = parseInt(gps_data[1].substring(0,2));
                              var gps_time_minutes = parseInt(gps_data[1].substring(2,4));
                              var gps_time_seconds = parseInt(gps_data[1].substring(4,6));
                              gps_time.setHours(gps_time_hours);
                              gps_time.setMinutes(gps_time_minutes);
                              gps_time.setSeconds(gps_time_seconds);
                             
                              gps_lat = gps_data[2];
                              gps_lat_ns = gps_data[3];
                              gps_lon = gps_data[4];
                              gps_lon_ew = gps_data[5];
                              gps_pos_fix = gps_data[6];
                              gps_satt_qty = gps_data[7];
                              gps_hdop = gps_data[8];
                              gps_msl_alt = gps_data[9];
                              gps_unit = gps_data[10];
                              gps_geo = gps_data[11];
                              gps_geo_unit = gps_data[12];
                             
                              if (gps_pos_fix == '1') {
                                  console.log('GPS Fixed');
                                  console.log('Time: ', gps_time);
                                  console.log('Position: ' + gps_lat + gps_lat_ns + ',' + gps_lon + gps_lon_ew);
                                  console.log('Altitude: ' + gps_msl_alt + 'M' + ' +/- ' + gps_hdop + 'M');
                                  console.log('Satellites Qty: ' + gps_satt_qty + '\n');
                              }
                             
                              if (gps_pos_fix == '0') {
                                  console.log('No GPS Fix');
                              }
                    
                          }
                         
                      });
                    });
                    
                    

                     

                    Only need to find out how to read GGA and RMC data and not only GGA