From 1b3b0b08368e1c2635a04ab6cbc91eee0a9ca762 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 18 Feb 2013 15:57:47 -0500 Subject: [PATCH] Adding note about shield --- examples/parsing/parsing.pde | 31 ++--- examples/shield_sdlog/shield_sdlog.ino | 164 +++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 18 deletions(-) create mode 100644 examples/shield_sdlog/shield_sdlog.ino diff --git a/examples/parsing/parsing.pde b/examples/parsing/parsing.pde index 86403ad..ce485a0 100644 --- a/examples/parsing/parsing.pde +++ b/examples/parsing/parsing.pde @@ -12,15 +12,9 @@ // 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 +// If you're using a GPS module: // Connect the GPS Power pin to 5V // Connect the GPS Ground pin to ground // If using software serial (sketch example default): @@ -30,13 +24,14 @@ // 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 you're using the Adafruit GPS shield, change +// SoftwareSerial mySerial(3, 2); -> SoftwareSerial mySerial(8, 7); +// and make sure the switch is set to SoftSerial + // 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: @@ -44,7 +39,7 @@ Adafruit_GPS GPS(&mySerial); // 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 // this keeps track of whether we're using the interrupt @@ -93,10 +88,12 @@ void setup() SIGNAL(TIMER0_COMPA_vect) { char c = GPS.read(); // if you want to debug, this is a good time to do it! +#ifdef UDR0 if (GPSECHO) if (c) 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) { @@ -123,9 +120,7 @@ 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) UDR0 = c; - // writing direct to UDR0 is much much faster than Serial.print - // but only one character can be written at a time. + if (c) Serial.print(c); } // if a sentence is received, we can check the checksum, parse it... @@ -169,4 +164,4 @@ void loop() // run over and over again Serial.print("Satellites: "); Serial.println((int)GPS.satellites); } } -} +} \ No newline at end of file diff --git a/examples/shield_sdlog/shield_sdlog.ino b/examples/shield_sdlog/shield_sdlog.ino new file mode 100644 index 0000000..8c871cb --- /dev/null +++ b/examples/shield_sdlog/shield_sdlog.ino @@ -0,0 +1,164 @@ + +#include +#include +#include +#include +#include "GPSconfig.h" + +// Ladyada's logger modified by Bill Greiman to use the SdFat library +// +// 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 Shield +// using MTK33x9 chipset +// ------> http://www.adafruit.com/products/ +// Pick one up today at the Adafruit electronics shop +// and help support open source hardware & software! -ada + +SoftwareSerial mySerial(8, 7); +Adafruit_GPS GPS(&mySerial); + +// 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 +/* set to true to only log to SD when GPS has a fix, for debugging, keep it false */ +#define LOG_FIXONLY false + +// Set the pins used +#define chipSelect 10 +#define ledPin 13 + +File logfile; + +// 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; +} + +// blink out an error code +void error(uint8_t errno) { +/* + if (SD.errorCode()) { + putstring("SD error: "); + Serial.print(card.errorCode(), HEX); + Serial.print(','); + Serial.println(card.errorData(), HEX); + } + */ + while(1) { + uint8_t i; + for (i=0; i