From ad5e4caef8e38cbfcc7bb9ac25576104e702db13 Mon Sep 17 00:00:00 2001 From: driverblock Date: Tue, 5 Feb 2013 11:58:43 -0500 Subject: [PATCH] Added examples for use with Leonardo Leonardo versions of echo, locus_dumpbasic, locus_erase, locus_start, locus_status, and parsing sketches --- examples/leo_echo/leo_echo.ino | 77 +++++++++++ .../leo_locus_dumpbasic.ino | 65 ++++++++++ examples/leo_locus_erase/leo_locus_erase.ino | 64 ++++++++++ examples/leo_locus_start/leo_locus_start.ino | 73 +++++++++++ .../leo_locus_status/leo_locus_status.ino | 113 +++++++++++++++++ examples/leo_parsing/leo_parsing.ino | 120 ++++++++++++++++++ 6 files changed, 512 insertions(+) create mode 100644 examples/leo_echo/leo_echo.ino create mode 100644 examples/leo_locus_dumpbasic/leo_locus_dumpbasic.ino create mode 100644 examples/leo_locus_erase/leo_locus_erase.ino create mode 100644 examples/leo_locus_start/leo_locus_start.ino create mode 100644 examples/leo_locus_status/leo_locus_status.ino create mode 100644 examples/leo_parsing/leo_parsing.ino diff --git a/examples/leo_echo/leo_echo.ino b/examples/leo_echo/leo_echo.ino new file mode 100644 index 0000000..2f75f1f --- /dev/null +++ b/examples/leo_echo/leo_echo.ino @@ -0,0 +1,77 @@ +// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver +// +// This code just echos whatever is coming from the GPS unit to the +// serial monitor, handy for debugging! +// +// Tested and works great with the Adafruit Ultimate GPS module +// using MTK33x9 chipset +// ------> http://www.adafruit.com/products/746 +// Pick one up today at the Adafruit electronics shop +// and help support open source hardware & software! -ada + +//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos + +#include +#include + +// Connect the GPS Power pin to 5V +// Connect the GPS Ground pin to ground +// If using software serial (sketch example default): +// Connect the GPS TX (transmit) pin to Digital 8 +// Connect the GPS RX (receive) pin to Digital 7 +// If using hardware serial: +// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0) +// Connect the GPS RX (receive) pin to matching TX1 (Digital 1) + +// 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 + +void setup() +{ + // connect at 115200 so we can read the GPS fast enuf and + // also spit it out + Serial.begin(115200); + delay(2000); + Serial.println("Adafruit GPS library basic test!"); + + // 9600 NMEA is the default baud rate for MTK - some use 4800 + GPS.begin(9600); + + // 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); + + delay(1000); +} + +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); +} diff --git a/examples/leo_locus_dumpbasic/leo_locus_dumpbasic.ino b/examples/leo_locus_dumpbasic/leo_locus_dumpbasic.ino new file mode 100644 index 0000000..b52b7bb --- /dev/null +++ b/examples/leo_locus_dumpbasic/leo_locus_dumpbasic.ino @@ -0,0 +1,65 @@ +// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver +// +// This code turns on the LOCUS built-in datalogger. The datalogger +// turns off when power is lost, so you MUST turn it on every time +// you want to use it! +// +// Tested and works great with the Adafruit Ultimate GPS module +// using MTK33x9 chipset +// ------> http://www.adafruit.com/products/746 +// Pick one up today at the Adafruit electronics shop +// and help support open source hardware & software! -ada + +//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos + +#include +#include + +// Connect the GPS Power pin to 5V +// Connect the GPS Ground pin to ground +// If using software serial (sketch example default): +// Connect the GPS TX (transmit) pin to Digital 8 +// Connect the GPS RX (receive) pin to Digital 7 +// If using hardware serial: +// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0) +// Connect the GPS RX (receive) pin to matching TX1 (Digital 1) + +// 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; + +void setup() +{ + // connect at 115200 so we can read the GPS fast enuf and + // also spit it out + Serial.begin(115200); + delay(2000); + Serial.println("Adafruit GPS logging start test!"); + + // 9600 NMEA is the default baud rate for MTK - some use 4800 + GPS.begin(9600); + + GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF); + + while (mySerial.available()) + mySerial.read(); + + delay(1000); + GPS.sendCommand("$PMTK622,1*29"); + Serial.println("----------------------------------------------------"); +} + + +void loop() // run over and over again +{ + if (mySerial.available()) { + Serial.write(mySerial.read()); + } +} + diff --git a/examples/leo_locus_erase/leo_locus_erase.ino b/examples/leo_locus_erase/leo_locus_erase.ino new file mode 100644 index 0000000..4d68476 --- /dev/null +++ b/examples/leo_locus_erase/leo_locus_erase.ino @@ -0,0 +1,64 @@ +// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver +// +// This code erases the LOCUS built-in datalogger storage +// +// Tested and works great with the Adafruit Ultimate GPS module +// using MTK33x9 chipset +// ------> http://www.adafruit.com/products/746 +// Pick one up today at the Adafruit electronics shop +// and help support open source hardware & software! -ada + +//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos + +#include +#include + +// Connect the GPS Power pin to 5V +// Connect the GPS Ground pin to ground +// If using software serial (sketch example default): +// Connect the GPS TX (transmit) pin to Digital 8 +// Connect the GPS RX (receive) pin to Digital 7 +// If using hardware serial: +// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0) +// Connect the GPS RX (receive) pin to matching TX1 (Digital 1) + +// 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; + +void setup() +{ + // connect at 115200 so we can read the GPS fast enuf and + // also spit it out + Serial.begin(115200); + delay(2000); + Serial.println("Adafruit GPS erase FLASH!"); + + // 9600 NMEA is the default baud rate for MTK + GPS.begin(9600); + + GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF); + + + Serial.println("This code will ERASE the data log stored in the FLASH - Permanently!"); + Serial.print("Are you sure you want to do this? [Y/N]: "); + while (Serial.read() != 'Y') delay(10); + Serial.println("\nERASING! UNPLUG YOUR ARDUINO WITHIN 5 SECONDS IF YOU DIDNT MEAN TO!"); + delay(5000); + GPS.sendCommand(PMTK_LOCUS_ERASE_FLASH); + Serial.println("Erased"); +} + +void loop() // run over and over again +{ + if (mySerial.available()) { + Serial.write(mySerial.read()); + } +} + diff --git a/examples/leo_locus_start/leo_locus_start.ino b/examples/leo_locus_start/leo_locus_start.ino new file mode 100644 index 0000000..ff21122 --- /dev/null +++ b/examples/leo_locus_start/leo_locus_start.ino @@ -0,0 +1,73 @@ +// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver +// +// This code turns on the LOCUS built-in datalogger. The datalogger +// turns off when power is lost, so you MUST turn it on every time +// you want to use it! +// +// Tested and works great with the Adafruit Ultimate GPS module +// using MTK33x9 chipset +// ------> http://www.adafruit.com/products/746 +// Pick one up today at the Adafruit electronics shop +// and help support open source hardware & software! -ada +//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos + +#include +#include + +// Connect the GPS Power pin to 5V +// Connect the GPS Ground pin to ground +// If using software serial (sketch example default): +// Connect the GPS TX (transmit) pin to Digital 8 +// Connect the GPS RX (receive) pin to Digital 7 +// If using hardware serial: +// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0) +// Connect the GPS RX (receive) pin to matching TX1 (Digital 1) + +// 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 + +void setup() +{ + // connect at 115200 so we can read the GPS fast enuf and + // also spit it out + Serial.begin(115200); + delay(2000); + Serial.println("Adafruit GPS logging start test!"); + + // 9600 NMEA is the default baud rate for MTK - some use 4800 + GPS.begin(9600); + + // You can adjust which sentences to have the module emit, below + // Default is RMC + GGA + GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); + // Default is 1 Hz update rate + GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); + + delay(500); + Serial.print("\nSTARTING LOGGING...."); + if (GPS.LOCUS_StartLogger()) + Serial.println(" STARTED!"); + else + Serial.println(" no response :("); + delay(1000); +} + +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 ((c) && (GPSECHO)) + Serial.write(c); +} + diff --git a/examples/leo_locus_status/leo_locus_status.ino b/examples/leo_locus_status/leo_locus_status.ino new file mode 100644 index 0000000..7f735a1 --- /dev/null +++ b/examples/leo_locus_status/leo_locus_status.ino @@ -0,0 +1,113 @@ +// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver +// +// This code turns on the LOCUS built-in datalogger. The datalogger +// turns off when power is lost, so you MUST turn it on every time +// you want to use it! +// +// Tested and works great with the Adafruit Ultimate GPS module +// using MTK33x9 chipset +// ------> http://www.adafruit.com/products/746 +// Pick one up today at the Adafruit electronics shop +// and help support open source hardware & software! -ada + +//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos + +#include +#include + +// Connect the GPS Power pin to 5V +// Connect the GPS Ground pin to ground +// If using software serial (sketch example default): +// Connect the GPS TX (transmit) pin to Digital 8 +// Connect the GPS RX (receive) pin to Digital 7 +// If using hardware serial: +// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0) +// Connect the GPS RX (receive) pin to matching TX1 (Digital 1) + +// 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 false + +void setup() +{ + // connect at 115200 so we can read the GPS fast enuf and + // also spit it out + Serial.begin(115200); + delay(5000); + Serial.println("Adafruit GPS logging start test!"); + + // 9600 NMEA is the default baud rate for MTK - some use 4800 + GPS.begin(9600); + + // You can adjust which sentences to have the module emit, below + // Default is RMC + GGA + GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); + // Default is 1 Hz update rate + GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); + + while (true) { + Serial.print("Starting logging...."); + if (GPS.LOCUS_StartLogger()) { + Serial.println(" STARTED!"); + break; + } else { + Serial.println(" no response :("); + } + } +} + +uint32_t updateTime = 1000; + +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 ((c) && (GPSECHO)) + Serial.write(c); + + if (millis() > updateTime) + { + updateTime = millis() + 1000; + if (GPS.LOCUS_ReadStatus()) { + Serial.print("\n\nLog #"); + Serial.print(GPS.LOCUS_serial, DEC); + if (GPS.LOCUS_type == LOCUS_OVERLAP) + Serial.print(", Overlap, "); + else if (GPS.LOCUS_type == LOCUS_FULLSTOP) + Serial.print(", Full Stop, Logging"); + + if (GPS.LOCUS_mode & 0x1) Serial.print(" AlwaysLocate"); + if (GPS.LOCUS_mode & 0x2) Serial.print(" FixOnly"); + if (GPS.LOCUS_mode & 0x4) Serial.print(" Normal"); + if (GPS.LOCUS_mode & 0x8) Serial.print(" Interval"); + if (GPS.LOCUS_mode & 0x10) Serial.print(" Distance"); + if (GPS.LOCUS_mode & 0x20) Serial.print(" Speed"); + + Serial.print(", Content "); Serial.print((int)GPS.LOCUS_config); + Serial.print(", Interval "); Serial.print((int)GPS.LOCUS_interval); + Serial.print(" sec, Distance "); Serial.print((int)GPS.LOCUS_distance); + Serial.print(" m, Speed "); Serial.print((int)GPS.LOCUS_speed); + Serial.print(" m/s, Status "); + if (GPS.LOCUS_status) + Serial.print("LOGGING, "); + else + Serial.print("OFF, "); + Serial.print((int)GPS.LOCUS_records); Serial.print(" Records, "); + Serial.print((int)GPS.LOCUS_percent); Serial.print("% Used "); + + }//if (GPS.LOCUS_ReadStatus()) + }//if (millis() > updateTime) +}//loop + + + diff --git a/examples/leo_parsing/leo_parsing.ino b/examples/leo_parsing/leo_parsing.ino new file mode 100644 index 0000000..7acf704 --- /dev/null +++ b/examples/leo_parsing/leo_parsing.ino @@ -0,0 +1,120 @@ +// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver +// +// This code shows how to listen to the GPS module in an interrupt +// which allows the program to have more 'freedom' - just parse +// when a new NMEA sentence is available! Then access data when +// desired. +// +// Tested and works great with the Adafruit Ultimate GPS module +// using MTK33x9 chipset +// ------> http://www.adafruit.com/products/746 +// Pick one up today at the Adafruit electronics shop +// and help support open source hardware & software! -ada + +//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos + +#include +#include + +// Connect the GPS Power pin to 5V +// Connect the GPS Ground pin to ground +// If using software serial (sketch example default): +// Connect the GPS TX (transmit) pin to Digital 8 +// Connect the GPS RX (receive) pin to Digital 7 +// If using hardware serial: +// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0) +// Connect the GPS RX (receive) pin to matching TX1 (Digital 1) + +// 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 + +void setup() +{ + + // connect at 115200 so we can read the GPS fast enough and echo without dropping chars + // also spit it out + Serial.begin(115200); + delay(5000); + Serial.println("Adafruit GPS library basic test!"); + + // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800 + GPS.begin(9600); + + // 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 + //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); + // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since + // the parser doesn't care about other sentences at this time + + // Set the update rate + GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate + // For the parsing code to work nicely and have time to sort thru the data, and + // print it out we don't suggest using anything higher than 1 Hz + + delay(1000); + // Ask for firmware version + mySerial.println(PMTK_Q_RELEASE); +} + +uint32_t timer = millis(); +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 ((c) && (GPSECHO)) + Serial.write(c); + + // if a sentence is received, we can check the checksum, parse it... + if (GPS.newNMEAreceived()) { + // a tricky thing here is if we print the NMEA sentence, or data + // we end up not listening and catching other sentences! + // so be very wary if using OUTPUT_ALLDATA and trytng to print out data + //Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false + + if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false + return; // we can fail to parse a sentence in which case we should just wait for another + } + + // if millis() or timer wraps around, we'll just reset it + if (timer > millis()) timer = millis(); + + // approximately every 2 seconds or so, print out the current stats + if (millis() - timer > 2000) { + timer = millis(); // reset the timer + + Serial.print("\nTime: "); + Serial.print(GPS.hour, DEC); Serial.print(':'); + Serial.print(GPS.minute, DEC); Serial.print(':'); + Serial.print(GPS.seconds, DEC); Serial.print('.'); + Serial.println(GPS.milliseconds); + Serial.print("Date: "); + Serial.print(GPS.day, DEC); Serial.print('/'); + Serial.print(GPS.month, DEC); Serial.print("/20"); + Serial.println(GPS.year, DEC); + Serial.print("Fix: "); Serial.print((int)GPS.fix); + Serial.print(" quality: "); Serial.println((int)GPS.fixquality); + if (GPS.fix) { + Serial.print("Location: "); + Serial.print(GPS.latitude, 4); Serial.print(GPS.lat); + Serial.print(", "); + Serial.print(GPS.longitude, 4); Serial.println(GPS.lon); + + Serial.print("Speed (knots): "); Serial.println(GPS.speed); + Serial.print("Angle: "); Serial.println(GPS.angle); + Serial.print("Altitude: "); Serial.println(GPS.altitude); + Serial.print("Satellites: "); Serial.println((int)GPS.satellites); + } + } +}