Created
May 4, 2014 18:54
-
-
Save dwhacks/11521907 to your computer and use it in GitHub Desktop.
Attiny softserial and gps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Original code come from Adafruit GPS logger shield kit - v1.1 | |
http://www.adafruit.com/products/98 | |
http://www.ladyada.net/make/gpsshield/download.html | |
All of this example Arduino code is Public Domain. Enjoy! | |
http://en.wikipedia.org/wiki/GNU_General_Public_License | |
Modified by DWHacks for use with U-blox PCI-5S. | |
Info about U-blox PCI-5S here: http://emerythacks.blogspot.ca/2013/01/u-blox-pci-5s-cheap-gps-module-for-your.html | |
Info about DWHacks: daynewaterlow.com | |
Settings for U-blox device: | |
RATES | |
Measurment period: 500ms (2 Hz) | |
PRT | |
Target: 1 UART1 | |
Protocol in: 1 - NMEA | |
Protocol out: 1 - NMEA | |
Baudrate: 9600 | |
Remove un neccessary data | |
*/ | |
#include <SoftwareSerial.h> | |
#include <Morse.h> | |
SoftwareSerial gpsSerial(0, 1); //RX TX connections on attiny85 | |
Morse morse(4, 20, 1); //set up the Morse Pin, Speed, type | |
// Set the pins used | |
#define led1Pin 2 //Get data from GPS | |
#define BUFFSIZE 90 //90 | |
char buffer[BUFFSIZE]; | |
uint8_t bufferidx = 0; | |
bool fix = false; // current fix data | |
bool gotGPRMC; //true if current data is a GPRMC strinng | |
uint8_t i; | |
// read a Hex value and return the decimal equivalent | |
uint8_t parseHex(char c) { | |
if (c < '0') | |
return 0; | |
if (c <= '9') | |
return c - '0'; | |
if (c < 'A') | |
return 0; | |
if (c <= 'F') | |
return (c - 'A')+10; | |
} | |
void setup() { | |
// Serial.begin(115200); | |
gpsSerial.begin(9600); | |
//gpsSerial.print("$PSRF103,04,00,00,01*25\r\n"); // | |
//gpsSerial.print("$PMTK251,9600*27\r\n"); //force 9600bps | |
//gpsSerial.print("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2C\r\n"); | |
//Serial.println("\r\nStarting..."); | |
pinMode(led1Pin, OUTPUT); | |
//pinMode(pin16, OUTPUT); | |
} | |
void loop() { | |
//digitalWrite(powerLed, HIGH); //indicate teensy is getting power | |
//Serial.println(Serial.available(), DEC); | |
char c; | |
uint8_t sum; | |
// read one 'line' | |
if (gpsSerial.available()) { | |
c = gpsSerial.read(); | |
if (bufferidx == 0) { | |
while (c != '$') | |
c = gpsSerial.read(); // wait till we get a $ | |
} | |
buffer[bufferidx] = c; | |
if (c == '\n') { | |
buffer[bufferidx+1] = 0; // terminate it | |
if (buffer[bufferidx-4] != '*') { | |
// no checksum? | |
//Serial.print('*'); | |
bufferidx = 0; | |
return; | |
} | |
// get checksum | |
sum = parseHex(buffer[bufferidx-3]) * 16; | |
sum += parseHex(buffer[bufferidx-2]); | |
// check checksum | |
for (i=1; i < (bufferidx-4); i++) { | |
sum ^= buffer[i]; | |
} | |
if (sum != 0) { | |
//putstring_nl("Cxsum mismatch"); | |
//Serial.print('~'); | |
bufferidx = 0; | |
return; | |
} | |
// got good data! | |
gotGPRMC = strstr(buffer, "GPRMC"); //GPRMC | |
if (gotGPRMC) | |
{ | |
// find out if we got a fix | |
char *p = buffer; | |
p = strchr(p, ',')+1; | |
p = strchr(p, ',')+1; // skip to 3rd item | |
if (p[0] == 'V') { | |
digitalWrite(led1Pin, LOW); | |
fix = false; | |
} else { | |
digitalWrite(led1Pin, HIGH); //Turn on LED1 when we have a fix | |
fix = true; | |
} | |
} | |
if (!fix) { | |
//Serial.print('_'); | |
morse.sendmsg("NO FIX"); | |
delay(50); | |
bufferidx = 0; | |
return; | |
} | |
// rad. lets log it! | |
//Serial.print(buffer); //first, write it to the serial monitor | |
//Serial.print('#'); | |
if (gotGPRMC) //If we have a GPRMC string | |
{ | |
// Bill Greiman - need to write bufferidx + 1 bytes to getCR/LF | |
bufferidx++; | |
delay(1000); //Origonal 10000 | |
//put transmit code here | |
morse.sendmsg(buffer); | |
bufferidx = 0; //reset buffer pointer | |
return; | |
}//if (gotGPRMC) | |
} | |
bufferidx++; | |
if (bufferidx == BUFFSIZE-1) { | |
//Serial.print('!'); | |
bufferidx = 0; | |
} | |
} else { | |
} | |
} | |
/* End code */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment