GPS logger shield + MEGA 2560

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
Zeppelin
 
Posts: 3
Joined: Sat May 14, 2011 12:56 pm

GPS logger shield + MEGA 2560

Post by Zeppelin »

Hello,

I recently recieved my Adafruit GPS logger shield kit - v1.1 w/ GPS 406A module and I am trying to make it work on my Arduino MEGA 2560 board.

I am mainly interested in the gps function for now.

I am using the test code provided at http://www.ladyada.net/make/gpsshield/GPStest_RMC.pde.

Firstly I tried the code as it is with out any luck.

Then I googleit a bit and found a new SoftSerial library version by Mikal which seems to support the mega chip (http://arduiniana.org/2011/01/newsoftserial-11-beta/).
[...] Changes since version 10 include:[...] support for Arduino Mega and Mega 2560 [...] only a small number of the pins on the Mega are available for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, and 69.
I changed the RX/TX to 50/52 (making the appropriate connections) but again nothing good happened.

Also GPS seems to be able to lock (smd led is blinking).

As it might be obvious am I totally new to arduino world and any help would be more than appreciated.


Code: Select all

// A simple sketch to read GPS data and parse the $GPRMC string 
// see http://www.ladyada.net/make/gpsshield for more info

#include <SoftwareSerial.h>

SoftwareSerial mySerial =  SoftwareSerial(50, 52);
#define powerpin 4

#define GPSRATE 4800
//#define GPSRATE 38400


// GPS parser for 406a
#define BUFFSIZ 90 // plenty big
char buffer[BUFFSIZ];
char *parseptr;
char buffidx;
uint8_t hour, minute, second, year, month, date;
uint32_t latitude, longitude;
uint8_t groundspeed, trackangle;
char latdir, longdir;
char status;

void setup() 
{ 
  if (powerpin) {
    pinMode(powerpin, OUTPUT);
  }
  pinMode(13, OUTPUT);
  Serial.begin(GPSRATE);
  mySerial.begin(GPSRATE);
   
  // prints title with ending line break 
  Serial.println("GPS parser"); 
 
   digitalWrite(powerpin, LOW);         // pull low to turn on!
} 
 
 
void loop() 
{ 
  uint32_t tmp;
  
  Serial.print("\n\rread: ");
  readline();
  
  // check if $GPRMC (global positioning fixed data)
  if (strncmp(buffer, "$GPRMC",6) == 0) {
    
    // hhmmss time data
    parseptr = buffer+7;
    tmp = parsedecimal(parseptr); 
    hour = tmp / 10000;
    minute = (tmp / 100) % 100;
    second = tmp % 100;
    
    parseptr = strchr(parseptr, ',') + 1;
    status = parseptr[0];
    parseptr += 2;
    
    // grab latitude & long data
    // latitude
    latitude = parsedecimal(parseptr);
    if (latitude != 0) {
      latitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      latitude += parsedecimal(parseptr);
    }
    parseptr = strchr(parseptr, ',') + 1;
    // read latitude N/S data
    if (parseptr[0] != ',') {
      latdir = parseptr[0];
    }
    
    //Serial.println(latdir);
    
    // longitude
    parseptr = strchr(parseptr, ',')+1;
    longitude = parsedecimal(parseptr);
    if (longitude != 0) {
      longitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      longitude += parsedecimal(parseptr);
    }
    parseptr = strchr(parseptr, ',')+1;
    // read longitude E/W data
    if (parseptr[0] != ',') {
      longdir = parseptr[0];
    }
    

    // groundspeed
    parseptr = strchr(parseptr, ',')+1;
    groundspeed = parsedecimal(parseptr);

    // track angle
    parseptr = strchr(parseptr, ',')+1;
    trackangle = parsedecimal(parseptr);


    // date
    parseptr = strchr(parseptr, ',')+1;
    tmp = parsedecimal(parseptr); 
    date = tmp / 10000;
    month = (tmp / 100) % 100;
    year = tmp % 100;
    
    Serial.print("\nTime: ");
    Serial.print(hour, DEC); Serial.print(':');
    Serial.print(minute, DEC); Serial.print(':');
    Serial.println(second, DEC);
    Serial.print("Date: ");
    Serial.print(month, DEC); Serial.print('/');
    Serial.print(date, DEC); Serial.print('/');
    Serial.println(year, DEC);
    
    Serial.print("Lat: "); 
    if (latdir == 'N')
       Serial.print('+');
    else if (latdir == 'S')
       Serial.print('-');

    Serial.print(latitude/1000000, DEC); Serial.print('\°', BYTE); Serial.print(' ');
    Serial.print((latitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
    Serial.print((latitude%10000)*6/1000, DEC); Serial.print('.');
    Serial.print(((latitude%10000)*6/10)%100, DEC); Serial.println('"');
   
    Serial.print("Long: ");
    if (longdir == 'E')
       Serial.print('+');
    else if (longdir == 'W')
       Serial.print('-');
    Serial.print(longitude/1000000, DEC); Serial.print('\°', BYTE); Serial.print(' ');
    Serial.print((longitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
    Serial.print((longitude%10000)*6/1000, DEC); Serial.print('.');
    Serial.print(((longitude%10000)*6/10)%100, DEC); Serial.println('"');
   
  }
  //Serial.println(buffer);
}

uint32_t parsedecimal(char *str) {
  uint32_t d = 0;
  
  while (str[0] != 0) {
   if ((str[0] > '9') || (str[0] < '0'))
     return d;
   d *= 10;
   d += str[0] - '0';
   str++;
  }
  return d;
}

void readline(void) {
  char c;
   buffidx = 0; // start at begninning
  while (1) {
      c=mySerial.read();

///Debugging????    
  Serial.print(c);
///Debugging????

      if (c == -1)
        continue;
      Serial.print(c);
      if (c == '\n')
        continue;
      if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
        buffer[buffidx] = 0;
        return;
      }
      buffer[buffidx++]= c;
  }
}

output

Code: Select all

GPS parser
read: ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

Zeppelin
 
Posts: 3
Joined: Sat May 14, 2011 12:56 pm

Re: GPS logger shield + MEGA 2560

Post by Zeppelin »

Any suggestions? :cry:

User avatar
code4food
 
Posts: 1
Joined: Sat May 15, 2010 8:40 pm

Re: GPS logger shield + MEGA 2560

Post by code4food »

Hi Zepplin,
I am using an Arduino Mega, and the Adafruit gpsshield. I have the power pin set to pin 2, and I am reading the gps data from Serial1, which looks at pins 18 and 19. So plug TX on the gpsshield into pin 20 on the Arduino, and RX into pin 19 on the Arduino. Then comment out the "SoftwareSerial mySerial = SoftwareSerial(50, 52);" and the SoftwareSerial.h include as well in your code, and replace all occurrances of mySerial with Serial1 (see my example below). Compile and upload to the Arduino and you are in business:

Code: Select all

// A simple sketch to read GPS data and parse the $GPRMC string 
// see http://www.ladyada.net/make/gpsshield for more info

//#include <SoftwareSerial.h>

//SoftwareSerial mySerial =  SoftwareSerial(50, 52);
#define powerpin 2

#define GPSRATE 4800
//#define GPSRATE 38400


// GPS parser for 406a
#define BUFFSIZ 90 // plenty big
char buffer[BUFFSIZ];
char *parseptr;
char buffidx;
uint8_t hour, minute, second, year, month, date;
uint32_t latitude, longitude;
uint8_t groundspeed, trackangle;
char latdir, longdir;
char status;

void setup() 
{ 
  if (powerpin) {
    pinMode(powerpin, OUTPUT);
  }
  pinMode(13, OUTPUT);
  Serial.begin(GPSRATE);
  Serial1.begin(GPSRATE);
   
  // prints title with ending line break 
  Serial.println("GPS parser"); 

   digitalWrite(powerpin, LOW);         // pull low to turn on!
} 


void loop() 
{ 
  uint32_t tmp;
  
  Serial.print("\n\rread: ");
  readline();
  
  // check if $GPRMC (global positioning fixed data)
  if (strncmp(buffer, "$GPRMC",6) == 0) {
    
    // hhmmss time data
    parseptr = buffer+7;
    tmp = parsedecimal(parseptr); 
    hour = tmp / 10000;
    minute = (tmp / 100) % 100;
    second = tmp % 100;
    
    parseptr = strchr(parseptr, ',') + 1;
    status = parseptr[0];
    parseptr += 2;
    
    // grab latitude & long data
    // latitude
    latitude = parsedecimal(parseptr);
    if (latitude != 0) {
      latitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      latitude += parsedecimal(parseptr);
    }
    parseptr = strchr(parseptr, ',') + 1;
    // read latitude N/S data
    if (parseptr[0] != ',') {
      latdir = parseptr[0];
    }
    
    //Serial.println(latdir);
    
    // longitude
    parseptr = strchr(parseptr, ',')+1;
    longitude = parsedecimal(parseptr);
    if (longitude != 0) {
      longitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      longitude += parsedecimal(parseptr);
    }
    parseptr = strchr(parseptr, ',')+1;
    // read longitude E/W data
    if (parseptr[0] != ',') {
      longdir = parseptr[0];
    }
    

    // groundspeed
    parseptr = strchr(parseptr, ',')+1;
    groundspeed = parsedecimal(parseptr);

    // track angle
    parseptr = strchr(parseptr, ',')+1;
    trackangle = parsedecimal(parseptr);


    // date
    parseptr = strchr(parseptr, ',')+1;
    tmp = parsedecimal(parseptr); 
    date = tmp / 10000;
    month = (tmp / 100) % 100;
    year = tmp % 100;
    
    Serial.print("\nTime: ");
    Serial.print(hour, DEC); Serial.print(':');
    Serial.print(minute, DEC); Serial.print(':');
    Serial.println(second, DEC);
    Serial.print("Date: ");
    Serial.print(month, DEC); Serial.print('/');
    Serial.print(date, DEC); Serial.print('/');
    Serial.println(year, DEC);
    
    Serial.print("Lat: "); 
    if (latdir == 'N')
       Serial.print('+');
    else if (latdir == 'S')
       Serial.print('-');

    Serial.print(latitude/1000000, DEC); Serial.print('\°', BYTE); Serial.print(' ');
    Serial.print((latitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
    Serial.print((latitude%10000)*6/1000, DEC); Serial.print('.');
    Serial.print(((latitude%10000)*6/10)%100, DEC); Serial.println('"');
   
    Serial.print("Long: ");
    if (longdir == 'E')
       Serial.print('+');
    else if (longdir == 'W')
       Serial.print('-');
    Serial.print(longitude/1000000, DEC); Serial.print('\°', BYTE); Serial.print(' ');
    Serial.print((longitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
    Serial.print((longitude%10000)*6/1000, DEC); Serial.print('.');
    Serial.print(((longitude%10000)*6/10)%100, DEC); Serial.println('"');
   
  }
  //Serial.println(buffer);
}

uint32_t parsedecimal(char *str) {
  uint32_t d = 0;
  
  while (str[0] != 0) {
   if ((str[0] > '9') || (str[0] < '0'))
     return d;
   d *= 10;
   d += str[0] - '0';
   str++;
  }
  return d;
}

void readline(void) {
  char c;
   buffidx = 0; // start at begninning
  while (1) {
      c=Serial1.read();

///Debugging????    
  Serial.print(c);
///Debugging????

      if (c == -1)
        continue;
      Serial.print(c);
      if (c == '\n')
        continue;
      if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
        buffer[buffidx] = 0;
        return;
      }
      buffer[buffidx++]= c;
  }
}
Let me know if that works.

:)

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: GPS logger shield + MEGA 2560

Post by adafruit »

hey we've recently updated the documentation to work better with the mega, do you mind trying it out?

http://www.ladyada.net/make/gpsshield/logging.html

Zeppelin
 
Posts: 3
Joined: Sat May 14, 2011 12:56 pm

Re: GPS logger shield + MEGA 2560

Post by Zeppelin »

Thank you very much for the replies.

Yes it does actually work. Both the GPS and the Logger!.

Thanks a lot !!! :D :D

edit:
I will post my code for further reference once it is ready :)

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: GPS logger shield + MEGA 2560

Post by adafruit »

fantastic! thank you for trying it

randal
 
Posts: 1
Joined: Thu Jan 27, 2011 7:44 am

Re: GPS logger shield + MEGA 2560

Post by randal »

Hi,
Would appreciate assistance as can't get my GPS logger shield running!!
I have a mega 1280, which I connected to the GPS shield with logger but can't get any GPS data logging to the SD card or appearing on the serial monitor.
I have updated to V22 of the IDE and also the latest adafruit documentation & code for the mega from: http://www.ladyada.net/make/gpsshield/logging.html.
I amended the GPS rate to match my logger using #define GPSRATE 38400 in the __.pde file and also changed the line in the Sd2Card.h file to #define MEGA_SOFT_SPI 1

Current status:
The SD card creates sequential __.txt files on startup / reset, but these are empty.
Serial monitor also displays "GPS logger, writing to GPSLOG__.TXT, Ready!", but nothing more.
GPS shows the locked light on when I went outside, and I confirmed it was reading correctly by using a recently purchased FDTI cable and viewing valid GPS sentances via the GPS shield and serial monitor .
The LED's on the GPS shield don't light up at all during this process, but did work when I inserted test lines in the .pde file to send them high for 5 seconds.
I have checked the wiring several times against the photos

To try and locate the problem, I tried removing the // from the standard .pde sketch, which resulted in a series of zeros appearing on the monitor.

I then inserted several test print lines in the .pde file, including the code extract below.
It looks like the if(gpsSerial.available()..... is failing, as the test print line following is never reached

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

// read one 'line'
if (gpsSerial.available()) {
Serial.println("Ready_postGPS_serial available!");


Thanks in anticipation - I have limited computing knowledge and must be missing some minor item!!
Randal

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

Re: GPS logger shield + MEGA 2560

Post by adafruit_support_bill »

Sounds like you have all the major components working separately. The problem is most likely with your serial wiring. Double check your Rx/Tx connections and make sure that they are on the same pins you have defined for AFSoftSerial.

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

Return to “Arduino Shields from Adafruit”