Thursday, May 31, 2012

Sparkfun Venus GPS and Arduino

I've just been playing with the Sparkfun Venus GPS module.

Very neat! It comes with more interfaces than you can shake a stick at, see the spec on the Sparkfun page. But I decided to use good old serial (or to be accurate the Software Serial library on the Arduino), so I just attached header pins to the RX0, TX0, 3.3V and GND connections and pushed it into some breadboard.

Upload the following sketch to your Arduino BEFORE making any connections. 5V from an IO pin left high on the Arduino may well kill the 3.3V output from the Tx pin on the GPS module.

#include <SoftwareSerial.h>

SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
const int sentenceSize = 80;

char sentence[sentenceSize];

void setup()
{
  Serial.begin(9600);
  gpsSerial.begin(9600);
}

void loop()
{
  static int i = 0;
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();
    if (ch != '\n' && i < sentenceSize)
    {
      sentence[i] = ch;
      i++;
    }
    else
    {
     sentence[i] = '\0';
     i = 0;
     displayGPS();
    }
  }
}

void displayGPS()
{
  char field[20];
  getField(field, 0);
  if (strcmp(field, "$GPRMC") == 0)
  {
    Serial.print("Lat: ");
    getField(field, 3);  // number
    Serial.print(field);
    getField(field, 4); // N/S
    Serial.print(field);
    
    Serial.print(" Long: ");
    getField(field, 5);  // number
    Serial.print(field);
    getField(field, 6);  // E/W
    Serial.println(field);
  }
}

void getField(char* buffer, int index)
{
  int sentencePos = 0;
  int fieldPos = 0;
  int commaCount = 0;
  while (sentencePos < sentenceSize)
  {
    if (sentence[sentencePos] == ',')
    {
      commaCount ++;
      sentencePos ++;
    }
    if (commaCount == index)
    {
      buffer[fieldPos] = sentence[sentencePos];
      fieldPos ++;
    }
    sentencePos ++;
  }
  buffer[fieldPos] = '\0';
} 

Make the following connections
  • The red lead goes from 3.3V Arduino to 3.3V GPS Module
  • The blue lead, GND to GND
  • The yellow lead Arduino Pin 10 to TX0 on the GPS Module



Open the Serial Monitor and view your position!


There is a really useful resource here, on the Arduino Playground, that tells you all about the various fields that your GPS unit is sending.

9 comments:

leot said...

Hi, is there any chance you can post a sketch where I can log all the information of gps to a sd card?

leot said...

Hi is any cjance you can tell me how to log the gps information to a sd card?

Juan Pablo Cellanes said...

Hi!
I'm getting the same exact values of position (2400N/12100E) and i'm in Argentina! what could be the problem?

Juan Pablo Cellanes said...

Hi!
I'm getting the same reads, but i'm in argentina!
Lat: 2400.0000N Long: 12100.0000E

What could be the problem?

Ibrahem Batta said...

how to get speed in Km/h ?

Laurent said...

Those coordinates are telling you that the gps doesn't have a fix. Connect the VBAT as well as second ground and it should work

leot said...

Hi Laurent is there any chance you can tell how to log the information given by the gps into a sd card

leot said...

Hi Laurent is there any chance you can tell how can I i store the data given by the gps into a sd card, I'm working with arduino and the sd shield

Diego said...

Hi! I am having the same issue as Juan Pablo Cellanes, I did the conection of VBAT and GND but the problem remains the same. I conected it to the same 3,3V line. Any help is welcome.