Go Down

Topic: Arduino GPS Shield by iteadstudio.com (Read 39 times) previous topic - next topic

BlackDice

Is there a working code from PJ_123?
I'm using this code but I'm not be able to write the data on a SD card  :~
Can anyone help me or upload a working program?
BlackDice

pRabbit

BlackDice-

Have you tried the "CardInfo" example in the SD library to see if your card is working?  Are you using a Mega?

For me the SD card example "CardInfo" in the examples works great on an Uno.  On the Mega, the SPI is on a different set of pins (D50-D53 on Mega rather than D10-13 on the Uno).  The itead GPS shield doesn't reach the D50-D53 SPI pins on the Mega so I had to run jumper wires from D50-52 on the Mega to D11-13 on the itead GPS sheild, I configured D11-13 as inputs in software but still used pin D10 as chip select (CS).  After that the Mega was able to access the SD card.

I took it a step farther and got it working on the Due, which required wiring up to the SPI connector in the middle of the board (why is this pins when everything else is sockets?  What a pain).  For the Due there is some good reading on Arduino.cc on the extended functionality of the Due SPI: http://arduino.cc/en/Reference/DueExtendedSPI.

gwcohn

Using the code in reply #5, change the references for SoftwareSerial to NewSoftSerial and change the GPS shield baud rate to 9600.

Make sure you have the jumpers and the RX and TX reference in the code correct.

I have the rx jumper on 3 and the tx jumper on two using an arduino UNO.

That agrees with this line of code: NewSoftSerial nss(2, 3);//tx and rx pins in my itead GPS shield

Take a look at your serial terminal and the rx chars and sentences should be incrementing.  If not, you may have your jumpers wrong on the GPS board.

It may take about 10 seconds to acquire three or more satellites before the lat and lon starts getting populated.

My house has a wood and built up roof so it works fine inside.  If you have any kind of metallic roofing, it may prevent you from receiving signals from the satellite.

#include <NewSoftSerial.h>

#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
*/

TinyGPS gps;
NewSoftSerial nss(2, 3);//tx and rx pins in my arduino GPS shield

static void gpsdump(TinyGPS &gps);
static bool feedgps();
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

void setup()
{
  Serial.begin(9600);
  nss.begin(9600);//baud rate for the GPS shield
 
  Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS));
  Serial.println();
  Serial.println("Sats HDOP Latitude Longitude Fix  Date       Time       Date Alt     Course Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)    (deg)     Age                        Age  (m)     --- from GPS ----  ---- to London  ----  RX    RX        Fail");
  Serial.println("--------------------------------------------------------------------------------------------------------------------------------------");
}

void loop()
{
  bool newdata = false;
  unsigned long start = millis();
 
  // Every second we print an update
  while (millis() - start < 1000)
  {
    if (feedgps())
      newdata = true;
  }
 
  gpsdump(gps);
}

static void gpsdump(TinyGPS &gps)
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const float LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
 
  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);

  print_date(gps);

  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0UL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128002), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);

  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz = ' ';
  if (len > 0)
    sz[len-1] = ' ';
  Serial.print(sz);
  feedgps();
}

static void print_float(float val, float invalid, int len, int prec)
{
  char sz[32];
  if (val == invalid)
  {
    strcpy(sz, "*******");
    sz[len] = 0;
        if (len > 0)
          sz[len-1] = ' ';
    for (int i=7; i<len; ++i)
        sz = ' ';
    Serial.print(sz);
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1);
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(" ");
  }
  feedgps();
}

static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("*******    *******    ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d   ",
        month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  feedgps();
}

static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str : ' ');
  feedgps();
}

static bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

Docedison

SoftwareSerial became a part of the IDE in Ver 1.0 it is the official replacement for the older NewsoftSerial and it works just fine with an Uno a pro-mini and several bare chips and at least 2 different GPS devices on my bench.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

ubruns


...
On the Mega, the SPI is on a different set of pins (D50-D53 on Mega rather than D10-13 on the Uno).  The itead GPS shield doesn't reach the D50-D53 SPI pins on the Mega so I had to run jumper wires from D50-52 on the Mega to D11-13 on the itead GPS sheild, I configured D11-13 as inputs in software but still used pin D10 as chip select (CS).  After that the Mega was able to access the SD card.


Code: [Select]
Used the following wiring:
G    D10 - D53  M
P    D11 - D50  E
S    D12 - D51  G
     D13 - D52  A


After that I loaded the example sketch "CardInfo" and changed the following lines:
Code: [Select]
const int chipSelect = 53;   
....
pinMode(53, OUTPUT);     // change this to 53 on a mega


The SD card is a 8GB card, repartioned with a 1.9GB primary FAT16 partition.

Can't get it to work.... init failed.

Anyone suggestions ?

Go Up