---

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.

About the Author
These are my books. Click on the image below to find out more about them.


19 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?

Unknown said...

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

Unknown said...

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

What could be the problem?

Unknown 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

Anonymous 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.

Unknown said...

Hello Guy i'm a electronic french student and in my project i would have the velocity in km/h how can i make this??
Thanks for your answer! And sorry for m'y poor english :(

Scott said...

To log all info to an SD card, simply use the SD library on the Arduino instead of outputting it to the serial port.

To get the velocity in km/hr, use the VTG output in the datasheet that Sparkfun lists on their site. The binary command set will tell you how to turn on the VTG output.

If you are still getting
Lat: 2400.0000N Long: 12100.0000E
*the GPS does not have a fix* - you must have an antenna and also be outside (or be able to see the sky) for the signal to reach the antenna.

Jiehao said...

Hi, i did everything the same, but there is nothing on the serial monitor after i uploaded my program.
anyone know why?

Jiehao said...

Hi , i did everything the same, but there is nothing shown on my serial monitor.
can anyone help me ?

Jiehao said...

Anyone know why what is the problem of not getting "$GPRMC" after the code:

void displayGPS()
{
char field[20];
getField(field, 0);
Serial.print(field);
}

in my serial monitor(i tried to print the field) ,there are only "$GPGGA" instead of "$GPGGA,$GPGSA,$GPGSV,$GPRMC"
The rest of them are missing except for "$GPGGA".

Calin Dragos said...

​In this tutorial I find what I need to start interfacing the gps sensor with a SBC. And because I want to help many more hobbyists to start building robots, I share this tutorial on my post ​http://www.intorobotics.com/gps-sensors-tutorials-resources/. Thank you!

Rahid said...

Hi, this is a very good tutorial. I am getting the values. But, I can not plot those data realtime in google earth.Can you please help me , how to do that?

Thanks in advance :)

Rahid said...

Hi, this is a very good tutorial. I am getting the values but I have failed to plot those data real-time in google earth. Will you please help me to do that? I will be very grateful if you please help me.

Again, thank you very much for the tutorial.

Unknown said...

Hello,
Do you have some code to disable the Nav speed treshold? for low speed application (below 1km/uur).
Thanks in advantage,
Rien

Unknown said...

I'm having a problem controlling a servo with this gps, it makes the servo crazy
I tried ServoTimer2 and yet it is not working
help plz ?