Added hardware serial support, back compatible w/Arduino 0023
This commit is contained in:
parent
47b173d6b2
commit
bd99b452fd
134
Adafruit_GPS.cpp
134
Adafruit_GPS.cpp
|
|
@ -1,11 +1,11 @@
|
||||||
/***********************************
|
/***********************************
|
||||||
This is a our GPS library
|
This is our GPS library
|
||||||
|
|
||||||
Adafruit invests time and resources providing this open source code,
|
Adafruit invests time and resources providing this open source code,
|
||||||
please support Adafruit and open-source hardware by purchasing
|
please support Adafruit and open-source hardware by purchasing
|
||||||
products from Adafruit!
|
products from Adafruit!
|
||||||
|
|
||||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||||
BSD license, check license.txt for more information
|
BSD license, check license.txt for more information
|
||||||
All text above must be included in any redistribution
|
All text above must be included in any redistribution
|
||||||
****************************************/
|
****************************************/
|
||||||
|
|
@ -161,42 +161,44 @@ boolean Adafruit_GPS::parse(char *nmea) {
|
||||||
char Adafruit_GPS::read(void) {
|
char Adafruit_GPS::read(void) {
|
||||||
char c = 0;
|
char c = 0;
|
||||||
|
|
||||||
if (paused)
|
if (paused) return c;
|
||||||
return c;
|
|
||||||
|
|
||||||
|
if(gpsSwSerial) {
|
||||||
if (gpsSwSerial->available()) {
|
if(!gpsSwSerial->available()) return c;
|
||||||
c = gpsSwSerial->read();
|
c = gpsSwSerial->read();
|
||||||
|
} else {
|
||||||
//Serial.print(c);
|
if(!gpsHwSerial->available()) return c;
|
||||||
|
c = gpsHwSerial->read();
|
||||||
if (c == '$') {
|
|
||||||
currentline[lineidx] = 0;
|
|
||||||
lineidx = 0;
|
|
||||||
}
|
|
||||||
if (c == '\n') {
|
|
||||||
currentline[lineidx] = 0;
|
|
||||||
|
|
||||||
if (currentline == line1) {
|
|
||||||
currentline = line2;
|
|
||||||
lastline = line1;
|
|
||||||
} else {
|
|
||||||
currentline = line1;
|
|
||||||
lastline = line2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Serial.println("----");
|
|
||||||
//Serial.println((char *)lastline);
|
|
||||||
//Serial.println("----");
|
|
||||||
lineidx = 0;
|
|
||||||
recvdflag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentline[lineidx++] = c;
|
|
||||||
if (lineidx >= MAXLINELENGTH)
|
|
||||||
lineidx = MAXLINELENGTH-1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Serial.print(c);
|
||||||
|
|
||||||
|
if (c == '$') {
|
||||||
|
currentline[lineidx] = 0;
|
||||||
|
lineidx = 0;
|
||||||
|
}
|
||||||
|
if (c == '\n') {
|
||||||
|
currentline[lineidx] = 0;
|
||||||
|
|
||||||
|
if (currentline == line1) {
|
||||||
|
currentline = line2;
|
||||||
|
lastline = line1;
|
||||||
|
} else {
|
||||||
|
currentline = line1;
|
||||||
|
lastline = line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Serial.println("----");
|
||||||
|
//Serial.println((char *)lastline);
|
||||||
|
//Serial.println("----");
|
||||||
|
lineidx = 0;
|
||||||
|
recvdflag = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentline[lineidx++] = c;
|
||||||
|
if (lineidx >= MAXLINELENGTH)
|
||||||
|
lineidx = MAXLINELENGTH-1;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,50 +206,53 @@ char Adafruit_GPS::read(void) {
|
||||||
#if ARDUINO >= 100
|
#if ARDUINO >= 100
|
||||||
Adafruit_GPS::Adafruit_GPS(SoftwareSerial *ser)
|
Adafruit_GPS::Adafruit_GPS(SoftwareSerial *ser)
|
||||||
#else
|
#else
|
||||||
Adafruit_GPS::Adafruit_GPS(NewSoftSerial *ser)
|
Adafruit_GPS::Adafruit_GPS(NewSoftSerial *ser)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
common_init(); // Set everything to common state, then...
|
common_init(); // Set everything to common state, then...
|
||||||
gpsSwSerial = ser; // ...override swSerial with value passed.
|
gpsSwSerial = ser; // ...override gpsSwSerial with value passed.
|
||||||
|
|
||||||
recvdflag = false;
|
|
||||||
paused = false;
|
|
||||||
lineidx = 0;
|
|
||||||
currentline = line1;
|
|
||||||
lastline = line2;
|
|
||||||
|
|
||||||
hour = minute = seconds = year = month = day = milliseconds = 0;
|
|
||||||
latitude = longitude = geoidheight = altitude = 0;
|
|
||||||
speed = angle = magvariation = HDOP = 0;
|
|
||||||
lat = lon = mag = 0;
|
|
||||||
fix = false;
|
|
||||||
fixquality = satellites = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constructor when using HardwareSerial
|
||||||
void Adafruit_GPS::begin(uint16_t baud)
|
Adafruit_GPS::Adafruit_GPS(HardwareSerial *ser) {
|
||||||
{
|
common_init(); // Set everything to common state, then...
|
||||||
gpsSwSerial->begin(baud);
|
gpsHwSerial = ser; // ...override gpsHwSerial with value passed.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialization code used by all constructor types
|
// Initialization code used by all constructor types
|
||||||
void Adafruit_GPS::common_init(void) {
|
void Adafruit_GPS::common_init(void) {
|
||||||
gpsSwSerial = NULL;
|
gpsSwSerial = NULL; // Set both to NULL, then override correct
|
||||||
gpsHwSerial = NULL;
|
gpsHwSerial = NULL; // port pointer in corresponding constructor
|
||||||
|
recvdflag = false;
|
||||||
|
paused = false;
|
||||||
|
lineidx = 0;
|
||||||
|
currentline = line1;
|
||||||
|
lastline = line2;
|
||||||
|
|
||||||
|
hour = minute = seconds = year = month = day =
|
||||||
|
fixquality = satellites = 0; // uint8_t
|
||||||
|
lat = lon = mag = 0; // char
|
||||||
|
fix = false; // boolean
|
||||||
|
milliseconds = 0; // uint16_t
|
||||||
|
latitude = longitude = geoidheight = altitude =
|
||||||
|
speed = angle = magvariation = HDOP = 0.0; // float
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Adafruit_GPS::begin(uint16_t baud)
|
||||||
|
{
|
||||||
|
if(gpsSwSerial) gpsSwSerial->begin(baud);
|
||||||
|
else gpsHwSerial->begin(baud);
|
||||||
|
}
|
||||||
|
|
||||||
void Adafruit_GPS::sendCommand(char *str) {
|
void Adafruit_GPS::sendCommand(char *str) {
|
||||||
gpsSwSerial->println(str);
|
if(gpsSwSerial) gpsSwSerial->println(str);
|
||||||
|
else gpsHwSerial->println(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
boolean Adafruit_GPS::newNMEAreceived(void) {
|
boolean Adafruit_GPS::newNMEAreceived(void) {
|
||||||
return recvdflag;
|
return recvdflag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Adafruit_GPS::pause(boolean p) {
|
void Adafruit_GPS::pause(boolean p) {
|
||||||
paused = p;
|
paused = p;
|
||||||
}
|
}
|
||||||
|
|
@ -257,7 +262,6 @@ char *Adafruit_GPS::lastNMEA(void) {
|
||||||
return (char *)lastline;
|
return (char *)lastline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// read a Hex value and return the decimal equivalent
|
// read a Hex value and return the decimal equivalent
|
||||||
uint8_t Adafruit_GPS::parseHex(char c) {
|
uint8_t Adafruit_GPS::parseHex(char c) {
|
||||||
if (c < '0')
|
if (c < '0')
|
||||||
|
|
@ -270,7 +274,6 @@ uint8_t Adafruit_GPS::parseHex(char c) {
|
||||||
return (c - 'A')+10;
|
return (c - 'A')+10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean Adafruit_GPS::waitForSentence(char *wait4me, uint8_t max) {
|
boolean Adafruit_GPS::waitForSentence(char *wait4me, uint8_t max) {
|
||||||
char str[20];
|
char str[20];
|
||||||
|
|
||||||
|
|
@ -296,7 +299,6 @@ boolean Adafruit_GPS::LOCUS_StartLogger(void) {
|
||||||
return waitForSentence(PMTK_LOCUS_LOGSTARTED);
|
return waitForSentence(PMTK_LOCUS_LOGSTARTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean Adafruit_GPS::LOCUS_ReadStatus(void) {
|
boolean Adafruit_GPS::LOCUS_ReadStatus(void) {
|
||||||
sendCommand(PMTK_LOCUS_QUERY_STATUS);
|
sendCommand(PMTK_LOCUS_QUERY_STATUS);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// this sketch will allow you to bypass the Atmega chip
|
// this sketch will allow you to bypass the Atmega chip
|
||||||
// and connect the fingerprint sensor directly to the USB/Serial
|
// and connect the GPS sensor directly to the USB/Serial
|
||||||
// chip converter.
|
// chip converter.
|
||||||
|
|
||||||
// Connect VIN to +5V
|
// Connect VIN to +5V
|
||||||
|
|
@ -8,4 +8,4 @@
|
||||||
// Connect GPS TX (data out from GPS) to Digital 1
|
// Connect GPS TX (data out from GPS) to Digital 1
|
||||||
|
|
||||||
void setup() {}
|
void setup() {}
|
||||||
void loop() {}
|
void loop() {}
|
||||||
|
|
@ -10,22 +10,36 @@
|
||||||
// and help support open source hardware & software! -ada
|
// and help support open source hardware & software! -ada
|
||||||
|
|
||||||
#include <Adafruit_GPS.h>
|
#include <Adafruit_GPS.h>
|
||||||
|
#if ARDUINO >= 100
|
||||||
// these are for Arduino 1.0
|
#include <SoftwareSerial.h>
|
||||||
#include <SoftwareSerial.h>
|
#else
|
||||||
SoftwareSerial mySerial(3, 2);
|
// Older Arduino IDE requires NewSoftSerial, download from:
|
||||||
|
// http://arduiniana.org/libraries/newsoftserial/
|
||||||
// if using Arduino v23 or earlier, uncomment these
|
#include <NewSoftSerial.h>
|
||||||
// two lines and comment out the above. You will
|
// DO NOT install NewSoftSerial if using Arduino 1.0 or later!
|
||||||
// need to install NewSoftSerial
|
#endif
|
||||||
// #include <NewSoftSerial.h>
|
|
||||||
// NewSoftSerial mySerial(3, 2);
|
|
||||||
|
|
||||||
// Connect the GPS Power pin to 5V
|
// Connect the GPS Power pin to 5V
|
||||||
// Connect the GPS Ground pin to ground
|
// Connect the GPS Ground pin to ground
|
||||||
// Connect the GPS TX (transmit) pin to Digital 3
|
// If using software serial (sketch example default):
|
||||||
// Connect the GPS RX (receive) pin to Digital 2
|
// Connect the GPS TX (transmit) pin to Digital 3
|
||||||
|
// Connect the GPS RX (receive) pin to Digital 2
|
||||||
|
// If using hardware serial (e.g. Arduino Mega):
|
||||||
|
// Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
|
||||||
|
// Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
|
||||||
|
|
||||||
|
// If using software serial, keep these lines enabled
|
||||||
|
// (you can change the pin numbers to match your wiring):
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
SoftwareSerial mySerial(3, 2);
|
||||||
|
#else
|
||||||
|
NewSoftSerial mySerial(3, 2);
|
||||||
|
#endif
|
||||||
Adafruit_GPS GPS(&mySerial);
|
Adafruit_GPS GPS(&mySerial);
|
||||||
|
// If using hardware serial (e.g. Arduino Mega), comment
|
||||||
|
// out the above six lines and enable this line instead:
|
||||||
|
//Adafruit_GPS GPS(&Serial1);
|
||||||
|
|
||||||
|
|
||||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||||
|
|
@ -34,6 +48,7 @@ Adafruit_GPS GPS(&mySerial);
|
||||||
// this keeps track of whether we're using the interrupt
|
// this keeps track of whether we're using the interrupt
|
||||||
// off by default!
|
// off by default!
|
||||||
boolean usingInterrupt = false;
|
boolean usingInterrupt = false;
|
||||||
|
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,35 @@
|
||||||
// and help support open source hardware & software! -ada
|
// and help support open source hardware & software! -ada
|
||||||
|
|
||||||
#include <Adafruit_GPS.h>
|
#include <Adafruit_GPS.h>
|
||||||
|
#if ARDUINO >= 100
|
||||||
// these are for Arduino 1.0
|
#include <SoftwareSerial.h>
|
||||||
#include <SoftwareSerial.h>
|
#else
|
||||||
SoftwareSerial mySerial(3, 2);
|
// Older Arduino IDE requires NewSoftSerial, download from:
|
||||||
|
// http://arduiniana.org/libraries/newsoftserial/
|
||||||
// if using Arduino v23 or earlier, uncomment these
|
#include <NewSoftSerial.h>
|
||||||
// two lines and comment out the above. You will
|
// DO NOT install NewSoftSerial if using Arduino 1.0 or later!
|
||||||
// need to install NewSoftSerial
|
#endif
|
||||||
// #include <NewSoftSerial.h>
|
|
||||||
// NewSoftSerial mySerial(3, 2);
|
|
||||||
|
|
||||||
// Connect the GPS Power pin to 5V
|
// Connect the GPS Power pin to 5V
|
||||||
// Connect the GPS Ground pin to ground
|
// Connect the GPS Ground pin to ground
|
||||||
// Connect the GPS TX (transmit) pin to Digital 3
|
// If using software serial (sketch example default):
|
||||||
// Connect the GPS RX (receive) pin to Digital 2
|
// Connect the GPS TX (transmit) pin to Digital 3
|
||||||
|
// Connect the GPS RX (receive) pin to Digital 2
|
||||||
|
// If using hardware serial (e.g. Arduino Mega):
|
||||||
|
// Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
|
||||||
|
// Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
|
||||||
|
|
||||||
|
// If using software serial, keep these lines enabled
|
||||||
|
// (you can change the pin numbers to match your wiring):
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
SoftwareSerial mySerial(3, 2);
|
||||||
|
#else
|
||||||
|
NewSoftSerial mySerial(3, 2);
|
||||||
|
#endif
|
||||||
Adafruit_GPS GPS(&mySerial);
|
Adafruit_GPS GPS(&mySerial);
|
||||||
|
// If using hardware serial (e.g. Arduino Mega), comment
|
||||||
|
// out the above six lines and enable this line instead:
|
||||||
|
//Adafruit_GPS GPS(&Serial1);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +52,8 @@ void setup()
|
||||||
GPS.begin(9600);
|
GPS.begin(9600);
|
||||||
|
|
||||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
|
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
|
||||||
|
|
||||||
|
// If using hardware serial (e.g. Arduino Mega), change this to Serial1, etc.
|
||||||
while (mySerial.available())
|
while (mySerial.available())
|
||||||
mySerial.read();
|
mySerial.read();
|
||||||
|
|
||||||
|
|
@ -51,10 +65,10 @@ void setup()
|
||||||
|
|
||||||
void loop() // run over and over again
|
void loop() // run over and over again
|
||||||
{
|
{
|
||||||
|
// If using hardware serial (e.g. Arduino Mega), change this to Serial1, etc.
|
||||||
if (mySerial.available()) {
|
if (mySerial.available()) {
|
||||||
char c = mySerial.read();
|
char c = mySerial.read();
|
||||||
if (c) UDR0 = c;
|
if (c) UDR0 = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -11,22 +11,36 @@
|
||||||
// and help support open source hardware & software! -ada
|
// and help support open source hardware & software! -ada
|
||||||
|
|
||||||
#include <Adafruit_GPS.h>
|
#include <Adafruit_GPS.h>
|
||||||
|
#if ARDUINO >= 100
|
||||||
// these are for Arduino 1.0
|
#include <SoftwareSerial.h>
|
||||||
#include <SoftwareSerial.h>
|
#else
|
||||||
SoftwareSerial mySerial(3, 2);
|
// Older Arduino IDE requires NewSoftSerial, download from:
|
||||||
|
// http://arduiniana.org/libraries/newsoftserial/
|
||||||
// if using Arduino v23 or earlier, uncomment these
|
#include <NewSoftSerial.h>
|
||||||
// two lines and comment out the above. You will
|
// DO NOT install NewSoftSerial if using Arduino 1.0 or later!
|
||||||
// need to install NewSoftSerial
|
#endif
|
||||||
// #include <NewSoftSerial.h>
|
|
||||||
// NewSoftSerial mySerial(3, 2);
|
|
||||||
|
|
||||||
// Connect the GPS Power pin to 5V
|
// Connect the GPS Power pin to 5V
|
||||||
// Connect the GPS Ground pin to ground
|
// Connect the GPS Ground pin to ground
|
||||||
// Connect the GPS TX (transmit) pin to Digital 3
|
// If using software serial (sketch example default):
|
||||||
// Connect the GPS RX (receive) pin to Digital 2
|
// Connect the GPS TX (transmit) pin to Digital 3
|
||||||
|
// Connect the GPS RX (receive) pin to Digital 2
|
||||||
|
// If using hardware serial (e.g. Arduino Mega):
|
||||||
|
// Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
|
||||||
|
// Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
|
||||||
|
|
||||||
|
// If using software serial, keep these lines enabled
|
||||||
|
// (you can change the pin numbers to match your wiring):
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
SoftwareSerial mySerial(3, 2);
|
||||||
|
#else
|
||||||
|
NewSoftSerial mySerial(3, 2);
|
||||||
|
#endif
|
||||||
Adafruit_GPS GPS(&mySerial);
|
Adafruit_GPS GPS(&mySerial);
|
||||||
|
// If using hardware serial (e.g. Arduino Mega), comment
|
||||||
|
// out the above six lines and enable this line instead:
|
||||||
|
//Adafruit_GPS GPS(&Serial1);
|
||||||
|
|
||||||
|
|
||||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||||
|
|
@ -35,6 +49,7 @@ Adafruit_GPS GPS(&mySerial);
|
||||||
// this keeps track of whether we're using the interrupt
|
// this keeps track of whether we're using the interrupt
|
||||||
// off by default!
|
// off by default!
|
||||||
boolean usingInterrupt = false;
|
boolean usingInterrupt = false;
|
||||||
|
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,36 @@
|
||||||
// and help support open source hardware & software! -ada
|
// and help support open source hardware & software! -ada
|
||||||
|
|
||||||
#include <Adafruit_GPS.h>
|
#include <Adafruit_GPS.h>
|
||||||
|
#if ARDUINO >= 100
|
||||||
// these are for Arduino 1.0
|
#include <SoftwareSerial.h>
|
||||||
#include <SoftwareSerial.h>
|
#else
|
||||||
SoftwareSerial mySerial(3, 2);
|
// Older Arduino IDE requires NewSoftSerial, download from:
|
||||||
|
// http://arduiniana.org/libraries/newsoftserial/
|
||||||
// if using Arduino v23 or earlier, uncomment these
|
#include <NewSoftSerial.h>
|
||||||
// two lines and comment out the above. You will
|
// DO NOT install NewSoftSerial if using Arduino 1.0 or later!
|
||||||
// need to install NewSoftSerial
|
#endif
|
||||||
// #include <NewSoftSerial.h>
|
|
||||||
// NewSoftSerial mySerial(3, 2);
|
|
||||||
|
|
||||||
// Connect the GPS Power pin to 5V
|
// Connect the GPS Power pin to 5V
|
||||||
// Connect the GPS Ground pin to ground
|
// Connect the GPS Ground pin to ground
|
||||||
// Connect the GPS TX (transmit) pin to Digital 3
|
// If using software serial (sketch example default):
|
||||||
// Connect the GPS RX (receive) pin to Digital 2
|
// Connect the GPS TX (transmit) pin to Digital 3
|
||||||
|
// Connect the GPS RX (receive) pin to Digital 2
|
||||||
|
// If using hardware serial (e.g. Arduino Mega):
|
||||||
|
// Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
|
||||||
|
// Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
|
||||||
|
|
||||||
|
// If using software serial, keep these lines enabled
|
||||||
|
// (you can change the pin numbers to match your wiring):
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
SoftwareSerial mySerial(3, 2);
|
||||||
|
#else
|
||||||
|
NewSoftSerial mySerial(3, 2);
|
||||||
|
#endif
|
||||||
Adafruit_GPS GPS(&mySerial);
|
Adafruit_GPS GPS(&mySerial);
|
||||||
|
// If using hardware serial (e.g. Arduino Mega), comment
|
||||||
|
// out the above six lines and enable this line instead:
|
||||||
|
//Adafruit_GPS GPS(&Serial1);
|
||||||
|
|
||||||
|
|
||||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||||
|
|
@ -35,6 +49,7 @@ Adafruit_GPS GPS(&mySerial);
|
||||||
// this keeps track of whether we're using the interrupt
|
// this keeps track of whether we're using the interrupt
|
||||||
// off by default!
|
// off by default!
|
||||||
boolean usingInterrupt = false;
|
boolean usingInterrupt = false;
|
||||||
|
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
@ -89,17 +104,17 @@ void loop() // run over and over again
|
||||||
if (GPS.LOCUS_mode & 0x10) Serial.print(" Distance");
|
if (GPS.LOCUS_mode & 0x10) Serial.print(" Distance");
|
||||||
if (GPS.LOCUS_mode & 0x20) Serial.print(" Speed");
|
if (GPS.LOCUS_mode & 0x20) Serial.print(" Speed");
|
||||||
|
|
||||||
Serial.print(", Content "); Serial.print(GPS.LOCUS_config);
|
Serial.print(", Content "); Serial.print((int)GPS.LOCUS_config);
|
||||||
Serial.print(", Interval "); Serial.print(GPS.LOCUS_interval);
|
Serial.print(", Interval "); Serial.print((int)GPS.LOCUS_interval);
|
||||||
Serial.print(" sec, Distance "); Serial.print(GPS.LOCUS_distance);
|
Serial.print(" sec, Distance "); Serial.print((int)GPS.LOCUS_distance);
|
||||||
Serial.print(" m, Speed "); Serial.print(GPS.LOCUS_speed);
|
Serial.print(" m, Speed "); Serial.print((int)GPS.LOCUS_speed);
|
||||||
Serial.print(" m/s, Status ");
|
Serial.print(" m/s, Status ");
|
||||||
if (GPS.LOCUS_status)
|
if (GPS.LOCUS_status)
|
||||||
Serial.print("LOGGING, ");
|
Serial.print("LOGGING, ");
|
||||||
else
|
else
|
||||||
Serial.print("OFF, ");
|
Serial.print("OFF, ");
|
||||||
Serial.print(GPS.LOCUS_records); Serial.print(" Records, ");
|
Serial.print((int)GPS.LOCUS_records); Serial.print(" Records, ");
|
||||||
Serial.print(GPS.LOCUS_percent); Serial.print("% Used ");
|
Serial.print((int)GPS.LOCUS_percent); Serial.print("% Used ");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,31 +12,45 @@
|
||||||
// and help support open source hardware & software! -ada
|
// and help support open source hardware & software! -ada
|
||||||
|
|
||||||
#include <Adafruit_GPS.h>
|
#include <Adafruit_GPS.h>
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
#else
|
||||||
|
// Older Arduino IDE requires NewSoftSerial, download from:
|
||||||
|
// http://arduiniana.org/libraries/newsoftserial/
|
||||||
|
#include <NewSoftSerial.h>
|
||||||
|
// DO NOT install NewSoftSerial if using Arduino 1.0 or later!
|
||||||
|
#endif
|
||||||
|
|
||||||
// these are for Arduino 1.0
|
// Connect the GPS Power pin to 5V
|
||||||
#include <SoftwareSerial.h>
|
// Connect the GPS Ground pin to ground
|
||||||
SoftwareSerial mySerial(3, 2);
|
// If using software serial (sketch example default):
|
||||||
|
// Connect the GPS TX (transmit) pin to Digital 3
|
||||||
|
// Connect the GPS RX (receive) pin to Digital 2
|
||||||
|
// If using hardware serial (e.g. Arduino Mega):
|
||||||
|
// Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
|
||||||
|
// Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
|
||||||
|
|
||||||
|
// If using software serial, keep these lines enabled
|
||||||
|
// (you can change the pin numbers to match your wiring):
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
SoftwareSerial mySerial(3, 2);
|
||||||
|
#else
|
||||||
|
NewSoftSerial mySerial(3, 2);
|
||||||
|
#endif
|
||||||
|
Adafruit_GPS GPS(&mySerial);
|
||||||
|
// If using hardware serial (e.g. Arduino Mega), comment
|
||||||
|
// out the above six lines and enable this line instead:
|
||||||
|
//Adafruit_GPS GPS(&Serial1);
|
||||||
|
|
||||||
// if using Arduino v23 or earlier, uncomment these
|
|
||||||
// two lines and comment out the above. You will
|
|
||||||
// need to install NewSoftSerial
|
|
||||||
// #include <NewSoftSerial.h>
|
|
||||||
// NewSoftSerial mySerial(3, 2);
|
|
||||||
|
|
||||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||||
#define GPSECHO true
|
#define GPSECHO true
|
||||||
|
|
||||||
// Connect the GPS Power pin to 5V
|
|
||||||
// Connect the GPS Ground pin to ground
|
|
||||||
// Connect the GPS TX (transmit) pin to Digital 3
|
|
||||||
// Connect the GPS RX (receive) pin to Digital 2
|
|
||||||
Adafruit_GPS GPS(&mySerial);
|
|
||||||
|
|
||||||
|
|
||||||
// this keeps track of whether we're using the interrupt
|
// this keeps track of whether we're using the interrupt
|
||||||
// off by default!
|
// off by default!
|
||||||
boolean usingInterrupt = false;
|
boolean usingInterrupt = false;
|
||||||
|
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
@ -136,8 +150,8 @@ void loop() // run over and over again
|
||||||
Serial.print(GPS.day, DEC); Serial.print('/');
|
Serial.print(GPS.day, DEC); Serial.print('/');
|
||||||
Serial.print(GPS.month, DEC); Serial.print("/20");
|
Serial.print(GPS.month, DEC); Serial.print("/20");
|
||||||
Serial.println(GPS.year, DEC);
|
Serial.println(GPS.year, DEC);
|
||||||
Serial.print("Fix: "); Serial.print(GPS.fix);
|
Serial.print("Fix: "); Serial.print((int)GPS.fix);
|
||||||
Serial.print(" quality: "); Serial.println(GPS.fixquality);
|
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
|
||||||
if (GPS.fix) {
|
if (GPS.fix) {
|
||||||
Serial.print("Location: ");
|
Serial.print("Location: ");
|
||||||
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
|
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
|
||||||
|
|
@ -147,7 +161,7 @@ void loop() // run over and over again
|
||||||
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
|
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
|
||||||
Serial.print("Angle: "); Serial.println(GPS.angle);
|
Serial.print("Angle: "); Serial.println(GPS.angle);
|
||||||
Serial.print("Altitude: "); Serial.println(GPS.altitude);
|
Serial.print("Altitude: "); Serial.println(GPS.altitude);
|
||||||
Serial.print("Satellites: "); Serial.println(GPS.satellites);
|
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue