0 Replies Latest reply on Jun 2, 2016 8:41 PM by gavinkoh70

    Grove GPS via Arduino IDE


      (Message updated with TinyGPS)

      I connected my GPS module (SIM28) to the UART port on the Grove only to find that SoftwareSerial doesn't work in the Arduino IDE. Looking around, I found discussions that either led on a wild goose chase or provided lengthy references to wade in.


      So for sharing, you will find below my basic Grove GPS sketch that works well with TinyGPS - you can get the TinyGps files from here. Download them and place Tinygps.cpp and Tinygps.h in the same folder as this sketch. (The sketch is based off simple_test.ino found in the Github repo). The most important lines that gets this working on the Intel Edison is found on lines 3, 4, 9, 10, 22, and 23; the rest of the code is similar.


      If you want to find out more about RingBuffer and TTYUARTClass, head over to this folder on your computer -

      "\AppData\Local\Arduino15\packages\Intel\hardware\i686\1.6.7+1.0\cores\arduino" and look up Ringbuffer.cpp and TTYUART.cpp


      #include "TinyGPS.h"
      RingBuffer rx_buffer_GPS;
      TTYUARTClass SerialGPS(&rx_buffer_GPS, 1, false);
      TinyGPS gps;
      void setup() {
      void loop() {
        bool newData = false;
        unsigned long chars;
        unsigned short sentences, failed;
        for (unsigned long start = millis(); millis() - start < 1000;)
          while (SerialGPS.available())
            char c = SerialGPS.read();
            //Serial.write(c); // uncomment this line if you want to see the GPS data flowing
            if (gps.encode(c))
              newData = true;
        if (newData)
          float flat, flon;
          unsigned long age;
          gps.f_get_position(&flat, &flon, &age);
          Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
          Serial.print(" LON=");
          Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
          Serial.print(" SAT=");
          Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
          Serial.print(" PREC=");
          Serial.println(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
        gps.stats(&chars, &sentences, &failed);
        Serial.print(" SENTENCES=");
        Serial.print(" CSUM ERR=");
        if (chars == 0)
          Serial.println("** No characters received from GPS: check wiring **");


      And here is the sample output observed while outdoors:

      LAT=1.377982 LON=103.855545 SAT=4 PREC=1626
      CHARS=15718 SENTENCES=44 CSUM ERR=17


      Hope this helps someone.