From 3b48046a6e395ff13696969146e4f7ab3f8028fd Mon Sep 17 00:00:00 2001 From: ladyada Date: Tue, 26 Feb 2013 15:24:17 -0500 Subject: [PATCH] cleaned up a tad --- Adafruit_GPS.h | 1 + examples/leo_echo/leo_echo.ino | 77 ++++++++++---------- examples/locus_dumpbasic/locus_dumpbasic.pde | 10 ++- examples/locus_start/locus_start.pde | 10 ++- examples/locus_status/locus_status.pde | 27 +++---- 5 files changed, 67 insertions(+), 58 deletions(-) diff --git a/Adafruit_GPS.h b/Adafruit_GPS.h index 53c607a..273097d 100644 --- a/Adafruit_GPS.h +++ b/Adafruit_GPS.h @@ -64,6 +64,7 @@ All text above must be included in any redistribution // request for updates on antenna status #define PGCMD_ANTENNA "$PGCMD,33,1*6C" +#define PGCMD_NOANTENNA "$PGCMD,33,0*6C" // how long to wait when we're looking for a response #define MAXWAITSENTENCE 5 diff --git a/examples/leo_echo/leo_echo.ino b/examples/leo_echo/leo_echo.ino index 2f75f1f..8830a2a 100644 --- a/examples/leo_echo/leo_echo.ino +++ b/examples/leo_echo/leo_echo.ino @@ -26,52 +26,51 @@ // If using software serial, keep these lines enabled // (you can change the pin numbers to match your wiring): //SoftwareSerial mySerial(8, 7); -//Adafruit_GPS GPS(&mySerial); // If using hardware serial, comment // out the above two lines and enable these two lines instead: -Adafruit_GPS GPS(&Serial1); HardwareSerial mySerial = Serial1; -// 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 -#define GPSECHO true +#define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F" +#define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C" +#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F" -void setup() -{ - // connect at 115200 so we can read the GPS fast enuf and - // also spit it out - Serial.begin(115200); +// turn on only the second sentence (GPRMC) +#define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" +// turn on GPRMC and GGA +#define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28" +// turn on ALL THE DATA +#define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28" +// turn off output +#define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28" + +#define PMTK_Q_RELEASE "$PMTK605*31" + +void setup() { + while (!Serial); // wait for leo to be ready + + Serial.begin(57600); // this baud rate doesn't actually matter! + Serial1.begin(9600); delay(2000); - Serial.println("Adafruit GPS library basic test!"); - - // 9600 NMEA is the default baud rate for MTK - some use 4800 - GPS.begin(9600); + Serial.println("Get version!"); + Serial1.println(PMTK_Q_RELEASE); - // You can adjust which sentences to have the module emit, below - - // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude - GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); - // uncomment this line to turn on only the "minimum recommended" data for high update rates! - //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); - // uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate - //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA); - - // Set the update rate - // 1 Hz update rate - //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); - // 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above) - GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); - // 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above) - //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ); + // you can send various commands to get it started + //mySerial.println(PMTK_SET_NMEA_OUTPUT_RMCGGA); + mySerial.println(PMTK_SET_NMEA_OUTPUT_ALLDATA); - delay(1000); -} + mySerial.println(PMTK_SET_NMEA_UPDATE_1HZ); + } -void loop() // run over and over again -{ - char c = GPS.read(); - // if you want to debug, this is a good time to do it! - if (GPSECHO) - if (c) Serial.write(c); -} + +void loop() { + if (Serial.available()) { + char c = Serial.read(); + Serial.write(c); + mySerial.write(c); + } + if (mySerial.available()) { + char c = mySerial.read(); + Serial.write(c); + } +} \ No newline at end of file diff --git a/examples/locus_dumpbasic/locus_dumpbasic.pde b/examples/locus_dumpbasic/locus_dumpbasic.pde index bed78d2..9a89a61 100644 --- a/examples/locus_dumpbasic/locus_dumpbasic.pde +++ b/examples/locus_dumpbasic/locus_dumpbasic.pde @@ -43,6 +43,8 @@ Adafruit_GPS GPS(&mySerial); void setup() { + while (!Serial); // Leonardo will wait till serial connects + // connect at 115200 so we can read the GPS fast enuf and // also spit it out Serial.begin(115200); @@ -68,7 +70,13 @@ void loop() // run over and over again // If using hardware serial (e.g. Arduino Mega), change this to Serial1, etc. if (mySerial.available()) { char c = mySerial.read(); - if (c) UDR0 = c; + if (c) { +#ifdef UDR0 + UDR0 = c; +#else + Serial.print(c); +#endif + } } } diff --git a/examples/locus_start/locus_start.pde b/examples/locus_start/locus_start.pde index 210983b..272be30 100644 --- a/examples/locus_start/locus_start.pde +++ b/examples/locus_start/locus_start.pde @@ -53,6 +53,8 @@ void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy void setup() { + while (!Serial); // the Leonardo will 'wait' until the USB plug is connected + // connect at 115200 so we can read the GPS fast enuf and // also spit it out Serial.begin(115200); @@ -88,14 +90,18 @@ void loop() // run over and over again } /******************************************************************/ + // Interrupt is called once a millisecond, looks for any new GPS data, and stores it SIGNAL(TIMER0_COMPA_vect) { char c = GPS.read(); // if you want to debug, this is a good time to do it! - if (GPSECHO) - if (c) UDR0 = c; + if (GPSECHO && c) { +#ifdef UDR0 + UDR0 = c; // writing direct to UDR0 is much much faster than Serial.print // but only one character can be written at a time. +#endif + } } void useInterrupt(boolean v) { diff --git a/examples/locus_status/locus_status.pde b/examples/locus_status/locus_status.pde index dda1b6d..b746e75 100644 --- a/examples/locus_status/locus_status.pde +++ b/examples/locus_status/locus_status.pde @@ -11,14 +11,7 @@ // and help support open source hardware & software! -ada #include -#if ARDUINO >= 100 - #include -#else - // Older Arduino IDE requires NewSoftSerial, download from: - // http://arduiniana.org/libraries/newsoftserial/ -// #include - // DO NOT install NewSoftSerial if using Arduino 1.0 or later! -#endif +#include // Connect the GPS Power pin to 5V // Connect the GPS Ground pin to ground @@ -31,11 +24,8 @@ // 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 +SoftwareSerial mySerial(3, 2); + Adafruit_GPS GPS(&mySerial); // If using hardware serial (e.g. Arduino Mega), comment // out the above six lines and enable this line instead: @@ -53,6 +43,8 @@ void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy void setup() { + while (!Serial); // the Leonardo will 'wait' until the USB plug is connected + // connect at 115200 so we can read the GPS fast enuf and // also spit it out Serial.begin(115200); @@ -124,13 +116,16 @@ void loop() // run over and over again SIGNAL(TIMER0_COMPA_vect) { char c = GPS.read(); // if you want to debug, this is a good time to do it! - if (GPSECHO) - if (c) UDR0 = c; + if (GPSECHO && c) { +#ifdef UDR0 + UDR0 = c; // writing direct to UDR0 is much much faster than Serial.print // but only one character can be written at a time. - +#endif + } } + void useInterrupt(boolean v) { if (v) { // Timer0 is already used for millis() - we'll just interrupt somewhere