Here is my code:
//Team Magnomap
//October 25, 2009
//Texas A&M University
#include <ctype.h>
#include <string.h>
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
byte GPSrx = 9;
byte GPStx = 10;
byte SWval;
//char dataformat[7] = "$ÇPG";
char dataformat[7] = "$GPGGA";
char messageline[80] = "";
char thesubstring[6] = "";
int i= 0;
void setup() {
pinMode(GPSrx,INPUT);
pinMode(GPStx,OUTPUT);
digitalWrite(GPStx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
Serial.begin(9600);
dataformat[0] = 00100100;
dataformat[1] = 11000111;
dataformat[2] = 11010000;
dataformat[3] = 11000111;
dataformat[4] = 11000111;
dataformat[5] = 11000001;
}
void SWprint(int data, byte rx, byte tx)
{
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 rx, byte tx)
{
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;
//val = val | (digitalRead(rx)<<offset);
}
//wait for stop bit + extra
delayMicroseconds(bit4800Delay);
delayMicroseconds(bit4800Delay);
return val;
}
}
void char2string(byte rx, byte tx)
{
i = 0;
messageline[0] = SWread(rx, tx);
if (messageline[0] == 36) //string starts with $
{
while(messageline[i] != 13 & i<80) //carriage return or max size
{
i++;
messageline[i] = SWread(rx, tx);
}
messageline[i+1] = 0; //make end to string
}
}
void loop()
{
digitalWrite(13,HIGH);
//only print string with the right dataformat
char2string(GPSrx, GPStx);
Serial.println(messageline);
/*
if (strncmp(messageline, dataformat, 6) == 0)
{
Serial.println(messageline);
}
*/
//Serial.print(SWread(GPSrx, GPStx),BYTE); //use this to get all GPS output, comment out from char2string till here
//Serial.println(SWread(GPSrx, GPStx));
}
And here are a few lines of the results I am getting. Everything looks good except for the Message ID.
$ÇÐGSÖ,3,1,12,29,71,204,46,21,43,318,49,18,42,261,40,06,62,190,76
$ÇPGSÖ,3,2,12,26,46,166,,24,45,076,,15,40,317,,10,36,040,7F
$GÐÇSV,3,3,12,02,29,094,,05,08,217,,30,07,208,,16,07,302,78
$GPRÍC,015832.125,A,3037.1242,Î,09620.3205,W,0.27,109.83,261009,,1Â
$GÐGGA,015833.125,3037.1242,Î,09620.3205,W,1,03,3.0,23.3,Í,-23.3,Í,,000052
$ÇPGSÁ,A,2,18,21,29,,,,,,,,,,3.2,3.0,1.031 //GSA-GNSS DOP (Table B-5)
$GÐÒMC,015833.125,A,3037.1242,N,09620.3205,W,0.16,176.45,261009,,1A
$GPGÇÁ,015834.128,3037.1242,N,09620.3205,W,1,03,3.0,23.3,M,-23.3,M,,000058
$GPÇÓA,Á,2,18,21,29,,,,,,,,,,3.2,3.0,1.031
$ÇPRMÃ,015834.128,Á,3037.1242,Î,09620.3205,×,0.19,185.51,261009,,16
$ÇPGÇÁ,015835.128,3037.1242,N,09620.3205,W,1,03,3.0,23.3,M,-23.3,M,,000059
$GPGÓA,A,2,18,21,29,,,,,,,,,,3.2,3.0,1.031
$ÇÐRMÃ,015835.128,Á,3037.1242,N,09620.3205,×,0.22,121.59,261009,,19
$ÇPGGÁ,015836.125,3037.1242,N,09620.3205,W,1,03,3.0,23.3,M,-23.3,Í,,000057
$GPGÓÁ,A,2,18,21,29,,,,,,,,,,3.2,3.0,1.031
$ÇÐRMC,015836.125,Á,3037.1242,N,09620.3205,W,0.17,143.56,261009,,1A
$ÇÐGGÁ,015837.125,3037.1242,N,09620.3205,W,1,03,3.0,23.3,Í,-23.3,Í,,000056
$ÇPGÓÁ,A,2,18,21,29,,,,,,,,,,3.2,3.0,1.031
And not all of the characters have the 128 bit as one. Every once and a while you can see the first character comes out as a G as it should.