The two codes that I talk about throughout are here:
Paralax Code:
/*
Example code for connecting a Parallax GPS module to the Arduino
Igor Gonzlez Martn. 05-04-2007
English translation by djmatic 19-05-2007
Listen for the $GPRMC string and extract the GPS location data from this.
Display the result in the Arduino's serial monitor.
*/
#include
#include
int ledPin = 13; // LED test pin
int rxPin = 0; // RX PIN
int txPin = 1; // TX TX
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
void setup() {
pinMode(ledPin, OUTPUT); // Initialize LED pin
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(4800);
for (int i=0;i<300;i++){ // Initialize a buffer for received data
linea[i]=' ';
}
}
void loop() {
digitalWrite(ledPin, HIGH);
byteGPS=Serial.read(); // Read a byte of the serial port
if (byteGPS == -1) { // See if the port is empty yet
delay(100);
} else {
linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer
conta++;
Serial.print(byteGPS, BYTE);
if (byteGPS==13){ // If the received byte is = to 13, end of transmission
digitalWrite(ledPin, LOW);
cont=0;
bien=0;
for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (linea[i]==comandoGPR[i-1]){
bien++;
}
}
if(bien==6){ // If yes, continue and process the data
for (int i=0;i<300;i++){
if (linea[i]==','){ // check for the position of the "," separator
indices[cont]=i;
cont++;
}
if (linea[i]=='*'){ // ... and the "*"
indices[12]=i;
cont++;
}
}
Serial.println(""); // ... and write to the serial port
Serial.println("");
Serial.println("---------------");
for (int i=0;i<12;i++){
switch(i){
case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
case 1 :Serial.print("Status (A=OK,V=KO): ");break;
case 2 :Serial.print("Latitude: ");break;
case 3 :Serial.print("Direction (N/S): ");break;
case 4 :Serial.print("Longitude: ");break;
case 5 :Serial.print("Direction (E/W): ");break;
case 6 :Serial.print("Velocity in knots: ");break;
case 7 :Serial.print("Heading in degrees: ");break;
case 8 :Serial.print("Date UTC (DdMmAa): ");break;
case 9 :Serial.print("Magnetic degrees: ");break;
case 10 :Serial.print("(E/W): ");break;
case 11 :Serial.print("Mode: ");break;
case 12 :Serial.print("Checksum: ");break;
}
for (int j=indices[i];j<(indices[i+1]-1);j++){
Serial.print(linea[j+1]);
}
Serial.println("");
}
Serial.println("---------------");
}
conta=0; // Reset the buffer
for (int i=0;i<300;i++){ //
linea[i]=' ';
}
}
}
}
Arduino Forums Code
//Created August 15 2006
//Heather Dewey-Hagborg
//reworked to GPS reader
//Dirk, december 2006
#include
#include
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6;
byte tx = 7;
byte SWval;
char dataformat[7] = "$GPRMC";
char messageline[80] = "";
int i= 0;
void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
SWprint('h'); //debugging hello
SWprint('i');
SWprint(10); //carriage return
Serial.begin(9600);
}
void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit4800Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit4800Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit4800Delay);
}
char SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit4800Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit4800Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit4800Delay);
delayMicroseconds(bit4800Delay);
return val;
}
}
void char2string()
{
i = 0;
messageline[0] = SWread();
if (messageline[0] == 36) //string starts with $
{
i++;
messageline[i] = SWread();
while(messageline[i] != 13 & i<80) //carriage return or max size
{
i++;
messageline[i] = SWread();
}
messageline[i+1] = 0; //make end to string
}
}
void loop()
{
digitalWrite(13,HIGH);
//only print string with the right dataformat
char2string();
if (strncmp(messageline, dataformat, 6) == 0 & i>4)
{
for (int i=0;i
{
Serial.print(messageline[i], BYTE);
}
}
//Serial.print(SWread(),BYTE); //use this to get all GPS output, comment out from char2string till here
}
This Blog was also invaluable! Many Thanks!
http://upuptothesky.blogspot.com/2009/04/gps-module-up-and-running.html