Code:
#include <ctype.h>
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6; // EM406A GPS tx line connected to pin 6 on Arduino (4800baud)
byte SWval;
char line[80]="";
void setup() {
pinMode(rx,INPUT);
digitalWrite(13,HIGH); // turn on debugging LED
Serial.begin(4800); // Setup USB serial port monitor to 4800baud
}
int 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 getLine()
{
int i = 0;
line[0] = SWread();
if (line[0] == 36) //string starts with $
{
i++;
line[i] = SWread();
while(line[i] != 13 & i<80) //carriage return or max size
{
i++;
line[i] = SWread();
}
line[i+1] = 0; //make end to string
}
} // end getLine()
void loop()
{
SWval = SWread();
Serial.print(SWval);
// getLine();
// Serial.println(line);
}
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6; // EM406A GPS tx line connected to pin 6 on Arduino (4800baud)
byte SWval;
char line[80]="";
void setup() {
pinMode(rx,INPUT);
digitalWrite(13,HIGH); // turn on debugging LED
Serial.begin(4800); // Setup USB serial port monitor to 4800baud
}
int 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 getLine()
{
int i = 0;
line[0] = SWread();
if (line[0] == 36) //string starts with $
{
i++;
line[i] = SWread();
while(line[i] != 13 & i<80) //carriage return or max size
{
i++;
line[i] = SWread();
}
line[i+1] = 0; //make end to string
}
} // end getLine()
void loop()
{
SWval = SWread();
Serial.print(SWval);
// getLine();
// Serial.println(line);
}
Am currently using the code at the following URL with perfect results using the EM-406 instead of the Parallax module (also connected via 3 wires pwr/gnd/tx):
http://www.arduino.cc/playground/Tutorials/GPS
