Arduino GPS shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
daveoregon
 
Posts: 31
Joined: Fri Aug 24, 2012 3:27 pm

Arduino GPS shield

Post by daveoregon »

HI, I have just assembled the GPS logger shield.....got the "SD_GPSLogger" code to compile (pls. see below) and the flashing LED on the GPS module is flashing red....

but I upload the code I get this msg

"avrdude: stk500_getsync () : not in sync: resp=0x00"

also, the seral monitor just shows jibberish

How can I fix this? Thanks!

Here's the code:

Code: Select all

// Ladyada's logger modified by Bill Greiman to use the SdFat library

// this is a generic logger that does checksum testing so the data written should be always good
// Assumes a sirf III chipset logger attached to pin 2 and 3

#include <SD.h>
#include <avr/sleep.h>
#include "GPSconfig.h"

// If using Arduino IDE prior to 1.0,
// make sure to install newsoftserial from Mikal Hart
// http://arduiniana.org/libraries/NewSoftSerial/
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

// power saving modes
#define SLEEPDELAY 0    /* power-down time in seconds. Max 65535. Ignored if TURNOFFGPS == 0 */
#define TURNOFFGPS 0    /* set to 1 to enable powerdown of arduino and GPS. Ignored if SLEEPDELAY == 0 */
#define LOG_RMC_FIXONLY 0  /* set to 1 to only log to SD when GPD has a fix */

// what to log
#define LOG_RMC 1 // RMC-Recommended Minimum Specific GNSS Data, message 103,04
#define LOG_GGA 0 // GGA-Global Positioning System Fixed Data, message 103,00
#define LOG_GLL 0 // GLL-Geographic Position-Latitude/Longitude, message 103,01
#define LOG_GSA 0 // GSA-GNSS DOP and Active Satellites, message 103,02
#define LOG_GSV 0 // GSV-GNSS Satellites in View, message 103,03
#define LOG_VTG 0 // VTG-Course Over Ground and Ground Speed, message 103,05



// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
#if ARDUINO >= 100
 SoftwareSerial gpsSerial =  SoftwareSerial(2, 3);
#else
 NewSoftSerial gpsSerial =  NewSoftSerial(2, 3);
#endif
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800

// Set the pins used 
#define powerPin 4
#define led1Pin 5
#define led2Pin 6
#define chipSelect 10


#define BUFFSIZE 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;
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) {
    for (i=0; i<errno; i++) {
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, HIGH);
      delay(100);
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, LOW);
      delay(100);
    }
    for (; i<10; i++) {
      delay(200);
    }
  }
}

void setup() {
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0;
  Serial.begin(9600);
  Serial.println("\r\nGPSlogger");
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(powerPin, OUTPUT);
  digitalWrite(powerPin, LOW);

  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card init. failed!");
    error(1);
  }

  strcpy(buffer, "GPSLOG00.TXT");
  for (i = 0; i < 100; i++) {
    buffer[6] = '0' + i/10;
    buffer[7] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(buffer)) {
      break;
    }
  }

  logfile = SD.open(buffer, FILE_WRITE);
  if( ! logfile ) {
    Serial.print("Couldnt create "); Serial.println(buffer);
    error(3);
  }
  Serial.print("Writing to "); Serial.println(buffer);
  
  // connect to the GPS at the desired rate
  gpsSerial.begin(GPSRATE);
  
  Serial.println("Ready!");
  
  gpsSerial.print(SERIAL_SET);
  delay(250);

#if (LOG_DDM == 1)
     gpsSerial.print(DDM_ON);
#else
     gpsSerial.print(DDM_OFF);
#endif
  delay(250);
#if (LOG_GGA == 1)
    gpsSerial.print(GGA_ON);
#else
    gpsSerial.print(GGA_OFF);
#endif
  delay(250);
#if (LOG_GLL == 1)
    gpsSerial.print(GLL_ON);
#else
    gpsSerial.print(GLL_OFF);
#endif
  delay(250);
#if (LOG_GSA == 1)
    gpsSerial.print(GSA_ON);
#else
    gpsSerial.print(GSA_OFF);
#endif
  delay(250);
#if (LOG_GSV == 1)
    gpsSerial.print(GSV_ON);
#else
    gpsSerial.print(GSV_OFF);
#endif
  delay(250);
#if (LOG_RMC == 1)
    gpsSerial.print(RMC_ON);
#else
    gpsSerial.print(RMC_OFF);
#endif
  delay(250);

#if (LOG_VTG == 1)
    gpsSerial.print(VTG_ON);
#else
    gpsSerial.print(VTG_OFF);
#endif
  delay(250);

#if (USE_WAAS == 1)
    gpsSerial.print(WAAS_ON);
#else
    gpsSerial.print(WAAS_OFF);
#endif
}

void loop() {
  //Serial.println(Serial.available(), DEC);
  char c;
  uint8_t sum;

  // read one 'line'
  if (gpsSerial.available()) {
    c = gpsSerial.read();
#if ARDUINO >= 100
    //Serial.write(c);
#else
    //Serial.print(c, BYTE);
#endif
    if (bufferidx == 0) {
      while (c != '$')
        c = gpsSerial.read(); // wait till we get a $
    }
    buffer[bufferidx] = c;

#if ARDUINO >= 100
    //Serial.write(c);
#else
    //Serial.print(c, BYTE);
#endif
    if (c == '\n') {
      //putstring_nl("EOL");
      //Serial.print(buffer);
      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");
      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);
          fix = true;
        }
      }
      if (LOG_RMC_FIXONLY) {
        if (!fix) {
          Serial.print('_');
          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++;

        digitalWrite(led2Pin, HIGH);      // Turn on LED 2 (indicates write to SD)

        logfile.write((uint8_t *) buffer, bufferidx);    //write the string to the SD file
        logfile.flush();
        /*
        if( != bufferidx) {
           putstring_nl("can't write!");
           error(4);
        }
        */

        digitalWrite(led2Pin, LOW);    //turn off LED2 (write to SD is finished)

        bufferidx = 0;    //reset buffer pointer

        if (fix) {  //(don't sleep if there's no fix)
          
          if ((TURNOFFGPS) && (SLEEPDELAY)) {      // turn off GPS module? 
          
            digitalWrite(powerPin, HIGH);  //turn off GPS

            delay(100);  //wait for serial monitor write to finish
            sleep_sec(SLEEPDELAY);  //turn off CPU
  
            digitalWrite(powerPin, LOW);  //turn on GPS
          } //if (TURNOFFGPS) 
         
        } //if (fix)
        
        return;
      }//if (gotGPRMC)
      
    }
    bufferidx++;
    if (bufferidx == BUFFSIZE-1) {
       Serial.print('!');
       bufferidx = 0;
    }
  } else {

  }

}

void sleep_sec(uint16_t x) {
  while (x--) {
     // set the WDT to wake us up!
    WDTCSR |= (1 << WDCE) | (1 << WDE); // enable watchdog & enable changing it
    WDTCSR = (1<< WDE) | (1 <<WDP2) | (1 << WDP1);
    WDTCSR |= (1<< WDIE);
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 //   sleep_enable();
    sleep_mode();
//    sleep_disable();
  }
}

SIGNAL(WDT_vect) {
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0;
}

/* End code */
Attachments
image of the shield attached to Arduino Uno
image of the shield attached to Arduino Uno
121024_0000.jpg (238.94 KiB) Viewed 1566 times

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino GPS shield

Post by adafruit_support_bill »

"avrdude: stk500_getsync () : not in sync: resp=0x00"
That means that the upload failed. Check that you have the right board-type and COM port selected.

User avatar
arctic_eddie
 
Posts: 233
Joined: Tue Feb 28, 2012 6:01 pm

Re: Arduino GPS shield

Post by arctic_eddie »

Selecting the wrong baud value for the serial monitor will produce trash characters. Connecting the GPS to serial port 0, RX0/TX0, will cause the sync problem. The SoftwareSerial port should be RX=2 and TX=3 and the baud should be 4800.

User avatar
daveoregon
 
Posts: 31
Joined: Fri Aug 24, 2012 3:27 pm

Re: Arduino GPS shield

Post by daveoregon »

Thanks very much.
I uploaded the "Blink" program

Code: Select all

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

and still get the
"avrdude: stk500_getsync(): not in sync: resp=0x00" response when uploading (why?...I did check serial port, it is indeed COM4)

Then I changed I changed the baud rate to 4800 (was 9600)
and now I get response on the COM4 serial monitor that looks like GPS data!

---------------
$GPGSA,A,3,29,21,30,26,18,05,02,15,16,25,12,,1.3,0.7,1.1*31
$GPRMC,205635.000,A,4435.0727,N,12314.5474,W,0.06,16.98,061112,,,D*48
$GPGGA,205636.000,4435.0727,N,12314.5474,W,2,11,0.7,84.8,M,-20.9,M,1.8,0000*78
$GPGSA,A,3,29,21,30,26,18,05,02,15,16,25,12,,1.3,0.7,1.1*31
$GPRMC,205636.000,A,4435.0727,N,12314.5474,W,0.02,18.18,061112,,,D*49
$GPGGA,205637.000,4435.0727,N,12314.5474,W,2,11,0.7,84.9,M,-20.9,M,1.8,0000*78
$GPGSA,A,3,29,21,30,26,18,05,02,15,16,25,12,,1.3,0.7,1.1*31
$GPRMC,205637.000,A,4435.0727,N,12314.5474,W,0.06,11.93,061112,,,D*46
$GPGGA,205638.000,4435.0726,N,12314.5474,W,2,11,0.7,84.9,M,-20.9,M,2.8,0000*75
$GPGSA,A,3,29,21,30,26,18,05,02,15,16,25,12,,1.3,0.7,1.1*31
$GPRMC,205638.000,A,4435.0726,N,12314.5474,W,0.07,23.02,061112,,,D*40
$GPGGA,205639.000,4435.0726,N,12314.5474,W,2,11,0.7,84.9,M,-20.9,M,3.8,0000*75
$GPGSA,A,3,29,21,30,26,18,05,02,15,16,25,12,,1.3,0.7,1.1*31
$GPGSV,3,1,12,29,81,084,44,21,48,264,39,05,42,057,39,25,32,193,33*75
$GPGSV,3,2,12,30,28,307,39,18,17,201,37,26,13,101,40,02,10,071,35*75
$GPGSV,3,3,12,15,09,135,39,16,06,327,39,12,06,170,33,31,03,264,*75
$GPRMC,205639.000,A,4435.0726,N,12314.5474,W,0.13,23.54,061112,,,D*47
$GPGGA,205640.000,4435.0726,N,12314.5474,W,2,11,0.7,85.0,M,-20.9,M,4.8,0000*74
-----
etc.

Looks like I have something to work with now, thanks!

User avatar
daveoregon
 
Posts: 31
Joined: Fri Aug 24, 2012 3:27 pm

Re: Arduino GPS shield

Post by daveoregon »

I think I get it, now. The reason the code did not upload is that the Arduino micro has been removed!

The instructions said the micro had to be removed because it was "in the way" (http://www.ladyada.net/make/gpsshield/d ... nnect.html)....I presume this means just in the way for debugging purposes (?)

User avatar
daveoregon
 
Posts: 31
Joined: Fri Aug 24, 2012 3:27 pm

Re: Arduino GPS shield

Post by daveoregon »

One suggestion: the assy instructions for the GPS logger shield are a little confusing in that there is a mix of images of version 1.0 and 1.1. Thanks.

User avatar
daveoregon
 
Posts: 31
Joined: Fri Aug 24, 2012 3:27 pm

Re: Arduino GPS shield

Post by daveoregon »

Been playing with the finished shield, it works great, but I haven't figured how to get it to report anything but the $GPRMC NEMA sentence. I tried modifying the code so that I turned "ON" all the various logging modes but that didn't work, my log file had nothing in it....even setting only one of the other logging states (say, GSA) to "1" didn't work. Any suggestions?

Here's the code section I'm talking about

Code: Select all

// what to log
#define LOG_RMC 1 // RMC-Recommended Minimum Specific GNSS Data, message 103,04
#define LOG_GGA 1 // GGA-Global Positioning System Fixed Data, message 103,00
#define LOG_GLL 1 // GLL-Geographic Position-Latitude/Longitude, message 103,01
#define LOG_GSA 1 // GSA-GNSS DOP and Active Satellites, message 103,02
#define LOG_GSV 1 // GSV-GNSS Satellites in View, message 103,03
#define LOG_VTG 1 // VTG-Course Over Ground and Ground Speed, message 103,05
and here is the entire program:

Code: Select all

// what to log
#define LOG_RMC 1 // RMC-Recommended Minimum Specific GNSS Data, message 103,04
#define LOG_GGA 0 // GGA-Global Positioning System Fixed Data, message 103,00
#define LOG_GLL 0 // GLL-Geographic Position-Latitude/Longitude, message 103,01
#define LOG_GSA 0 // GSA-GNSS DOP and Active Satellites, message 103,02
#define LOG_GSV 0 // GSV-GNSS Satellites in View, message 103,03
#define LOG_VTG 0 // VTG-Course Over Ground and Ground Speed, message 103,05

THANKS!

User avatar
arctic_eddie
 
Posts: 233
Joined: Tue Feb 28, 2012 6:01 pm

Re: Arduino GPS shield

Post by arctic_eddie »

You may be getting only the first sentence that's enabled, RMC. Set all to 0 except GGA. This one contains time, lon, lat, alt, and some satellite data. The EM-406A spec sheet has info on sentence content and formatting. You can recover the data in a sketch by scanning the sentence and extracting text between the appropriate two commas. String variables have commands to do this kind of stuff.

User avatar
cbausmart
 
Posts: 8
Joined: Wed Nov 21, 2012 7:34 pm

Re: Arduino GPS shield

Post by cbausmart »

Hello world! anyone of you knows how to add some sensors to this definition?? I mean, how to logg the sensor data in the SDcard, geolocating the values. I took the same deffinition of Ladyada, but I don't know how to add some sensor code.
:wink:

Code: Select all

// Ladyada's logger modified by Bill Greiman to use the SdFat library

// this is a generic logger that does checksum testing so the data written should be always good
// Assumes a sirf III chipset logger attached to pin 2 and 3

#include <SD.h>
#include <avr/sleep.h>
#include "GPSconfig.h"

// If using Arduino IDE prior to 1.0,
// make sure to install newsoftserial from Mikal Hart
// http://arduiniana.org/libraries/NewSoftSerial/
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

// power saving modes
#define SLEEPDELAY 0    /* power-down time in seconds. Max 65535. Ignored if TURNOFFGPS == 0 */
#define TURNOFFGPS 0    /* set to 1 to enable powerdown of arduino and GPS. Ignored if SLEEPDELAY == 0 */
#define LOG_RMC_FIXONLY 0  /* set to 1 to only log to SD when GPD has a fix */

// what to log
#define LOG_RMC 1 // RMC-Recommended Minimum Specific GNSS Data, message 103,04
#define LOG_GGA 0 // GGA-Global Positioning System Fixed Data, message 103,00
#define LOG_GLL 0 // GLL-Geographic Position-Latitude/Longitude, message 103,01
#define LOG_GSA 0 // GSA-GNSS DOP and Active Satellites, message 103,02
#define LOG_GSV 0 // GSV-GNSS Satellites in View, message 103,03
#define LOG_VTG 0 // VTG-Course Over Ground and Ground Speed, message 103,05



// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
#if ARDUINO >= 100
 SoftwareSerial gpsSerial =  SoftwareSerial(2, 3);
#else
 NewSoftSerial gpsSerial =  NewSoftSerial(2, 3);
#endif
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800

// Set the pins used 
#define powerPin 4
#define led1Pin 5
#define led2Pin 6
#define chipSelect 10


#define BUFFSIZE 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;
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) {
    for (i=0; i<errno; i++) {
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, HIGH);
      delay(100);
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, LOW);
      delay(100);
    }
    for (; i<10; i++) {
      delay(200);
    }
  }
}

void setup() {
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0;
  Serial.begin(9600);
  Serial.println("\r\nGPSlogger");
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(powerPin, OUTPUT);
  digitalWrite(powerPin, LOW);

  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card init. failed!");
    error(1);
  }

  strcpy(buffer, "GPSLOG00.TXT");
  for (i = 0; i < 100; i++) {
    buffer[6] = '0' + i/10;
    buffer[7] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(buffer)) {
      break;
    }
  }

  logfile = SD.open(buffer, FILE_WRITE);
  if( ! logfile ) {
    Serial.print("Couldnt create "); Serial.println(buffer);
    error(3);
  }
  Serial.print("Writing to "); Serial.println(buffer);
  
  // connect to the GPS at the desired rate
  gpsSerial.begin(GPSRATE);
  
  Serial.println("Ready!");
  
  gpsSerial.print(SERIAL_SET);
  delay(250);

#if (LOG_DDM == 1)
     gpsSerial.print(DDM_ON);
#else
     gpsSerial.print(DDM_OFF);
#endif
  delay(250);
#if (LOG_GGA == 1)
    gpsSerial.print(GGA_ON);
#else
    gpsSerial.print(GGA_OFF);
#endif
  delay(250);
#if (LOG_GLL == 1)
    gpsSerial.print(GLL_ON);
#else
    gpsSerial.print(GLL_OFF);
#endif
  delay(250);
#if (LOG_GSA == 1)
    gpsSerial.print(GSA_ON);
#else
    gpsSerial.print(GSA_OFF);
#endif
  delay(250);
#if (LOG_GSV == 1)
    gpsSerial.print(GSV_ON);
#else
    gpsSerial.print(GSV_OFF);
#endif
  delay(250);
#if (LOG_RMC == 1)
    gpsSerial.print(RMC_ON);
#else
    gpsSerial.print(RMC_OFF);
#endif
  delay(250);

#if (LOG_VTG == 1)
    gpsSerial.print(VTG_ON);
#else
    gpsSerial.print(VTG_OFF);
#endif
  delay(250);

#if (USE_WAAS == 1)
    gpsSerial.print(WAAS_ON);
#else
    gpsSerial.print(WAAS_OFF);
#endif
}

void loop() {
  //Serial.println(Serial.available(), DEC);
  char c;
  uint8_t sum;

  // read one 'line'
  if (gpsSerial.available()) {
    c = gpsSerial.read();
#if ARDUINO >= 100
    //Serial.write(c);
#else
    //Serial.print(c, BYTE);
#endif
    if (bufferidx == 0) {
      while (c != '$')
        c = gpsSerial.read(); // wait till we get a $
    }
    buffer[bufferidx] = c;

#if ARDUINO >= 100
    //Serial.write(c);
#else
    //Serial.print(c, BYTE);
#endif
    if (c == '\n') {
      //putstring_nl("EOL");
      //Serial.print(buffer);
      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");
      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);
          fix = true;
        }
      }
      if (LOG_RMC_FIXONLY) {
        if (!fix) {
          Serial.print('_');
          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++;

        digitalWrite(led2Pin, HIGH);      // Turn on LED 2 (indicates write to SD)

        logfile.write((uint8_t *) buffer, bufferidx);    //write the string to the SD file
        logfile.flush();
        /*
        if( != bufferidx) {
           putstring_nl("can't write!");
           error(4);
        }
        */

        digitalWrite(led2Pin, LOW);    //turn off LED2 (write to SD is finished)

        bufferidx = 0;    //reset buffer pointer

        if (fix) {  //(don't sleep if there's no fix)
          
          if ((TURNOFFGPS) && (SLEEPDELAY)) {      // turn off GPS module? 
          
            digitalWrite(powerPin, HIGH);  //turn off GPS

            delay(100);  //wait for serial monitor write to finish
            sleep_sec(SLEEPDELAY);  //turn off CPU
  
            digitalWrite(powerPin, LOW);  //turn on GPS
          } //if (TURNOFFGPS) 
         
        } //if (fix)
        
        return;
      }//if (gotGPRMC)
      
    }
    bufferidx++;
    if (bufferidx == BUFFSIZE-1) {
       Serial.print('!');
       bufferidx = 0;
    }
  } else {

  }

}

void sleep_sec(uint16_t x) {
  while (x--) {
     // set the WDT to wake us up!
    WDTCSR |= (1 << WDCE) | (1 << WDE); // enable watchdog & enable changing it
    WDTCSR = (1<< WDE) | (1 <<WDP2) | (1 << WDP1);
    WDTCSR |= (1<< WDIE);
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 //   sleep_enable();
    sleep_mode();
//    sleep_disable();
  }
}

SIGNAL(WDT_vect) {
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0;
}

/* End code */

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”