Ultimate GPS Module

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
dwhacks
 
Posts: 3
Joined: Sun Sep 22, 2013 6:29 pm

Ultimate GPS Module

Post by dwhacks »

To use this module at 10hz refresh rate the NMEA output baud much be changed. Since we cannot save this in the firmware (that I am able to find) it looks like the only was is to tell it:

Code: Select all

PMTK251,115200*27
My problem that is to send this message, we much be in the default baud, 9600, but after sending that message we can no longer read because our baudrate has changed. How can I solve this?

My code is a modified version of a modified version of your code for teensy using hardware serial.

Code: Select all

/* 
Original code come from Adafruit GPS logger shield kit - v1.1
http://www.adafruit.com/products/98
http://www.ladyada.net/make/gpsshield/download.html
All of this example Arduino code is Public Domain. Enjoy!
http://en.wikipedia.org/wiki/GNU_General_Public_License

Code from: TeenLogger, a Teensy GPS Logger http://www.weirdlab.fr/?p=39

Modified by DWHacks for use with hardware serial, and faster log rate.

GPS TX to Pin 7 on teensy2
GPS RX to Pin 8 on teensy2


*/

#include <SD.h>


HardwareSerial Uart = HardwareSerial();

// Set the pins used 
#define led2Pin 15 //Get data from GPS
#define led1Pin 16 //LED to indicate we have a fix

//ADCSRA = 0;   // shut off ADC


const int powerLed = 11; //teensy 2 onboard led
const int chipSelect = 0;

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

void setup() {
  Serial.begin(115200);
  Uart.begin(115200);
  
  Uart.print("$PMTK251,115200*27\r\n"); //force 115200bps
  
  Uart.print("$PMTK220,100*2F\r\n"); //set 10hz
 
  Uart.print("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n"); // select NMEA data
  
  
  
   
  Serial.println("\r\nStarting...");
  pinMode(led2Pin, OUTPUT);
  pinMode(led1Pin, OUTPUT);
  pinMode(powerLed, OUTPUT);
 
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(0, 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("Starting to log on ..."); 
  Serial.println(buffer);
  //pinMode(buttonPin, INPUT_PULLUP); // Set input buttonpin & pull-up on analog pin 17
}

void loop() {
  
  digitalWrite(powerLed, HIGH); //indicate teensy is getting power
  //Serial.println(Serial.available(), DEC);
  char c;
  uint8_t sum;

  // read one 'line'
  if (Uart.available()) {
    c = Uart.read();

    if (bufferidx == 0) {
      while (c != '$')
        c = Uart.read(); // wait till we get a $
    }
    buffer[bufferidx] = c;

    if (c == '\n') {

      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"); //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);  //Turn on LED1 when we have a fix
          fix = true;
        }
      }      
      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++;
        delay(100); //Origonal 10000
        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
        
        return;
      }//if (gotGPRMC)
      
    }
    bufferidx++;
    if (bufferidx == BUFFSIZE-1) {
       Serial.print('!');
       bufferidx = 0;
    }
  } else {

  }
  
 
}
/* End code */

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Ultimate GPS Module

Post by 1chicagodave »

Have you tried something like this?

Code: Select all


  Uart.begin(9600);   // Set baud rate to 9600 

  Uart.print("$PMTK251,115200*27\r\n"); //force 115200bps

  Uart.begin(115200);   // set baud rate to 115200
Perhaps put a small delay, or "listen" for the acknowledgement confirmation from GPS before the third step.

...are you sure the checksum is "27"? I have mine as being "1F".

dwhacks
 
Posts: 3
Joined: Sun Sep 22, 2013 6:29 pm

Re: Ultimate GPS Module

Post by dwhacks »

I actually have no idea where to find the checksum, where do I get that info?

And I just assumed you couldnt call the begin twice. I will try it after I look into the checksums, thanks.

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Ultimate GPS Module

Post by 1chicagodave »

Checksum calculator:

http://www.hhhh.org/wiml/proj/nmeaxor.html

Paste everything from PMTK string between (but not including) the "$" and "*" into box on that page.
And I just assumed you couldnt call the begin twice
I'm pretty sure that's how I did it.
Best way to find out is to compile & test.
Worst case...you could always add

Code: Select all

Serial.end()
to code before re-starting it with the new baud rate.

dwhacks
 
Posts: 3
Joined: Sun Sep 22, 2013 6:29 pm

Re: Ultimate GPS Module

Post by dwhacks »

seems to work like this:

Code: Select all

  Uart.begin(9600);
  delay(100);
  Uart.print("$PMTK251,115200*1F\r\n"); //force 115200bps
  delay(100);
  Uart.begin(115200);
If anyone sees a problem, please let me know

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

Return to “Other Products from Adafruit”