Pages: [1]   Go Down
Author Topic: GPS data logger with SD card and Mega  (Read 3000 times)
0 Members and 1 Guest are viewing this topic.
Mildura, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am trying to create a GPS data logger using a EM-406 GPS, Arduino Ethernet shield with SD card, and a Mega 2560. I have used the SD, TinyGPS and SoftwareSerial libraries and I have tried to make the code as basic as possible at this stage. I have created the following code, which compiles ok.  When I open the serial port the data being printed is as follows.  I have the GPS hooked up to pin 51.

0.000000, 0.000000 
0.000000, 0.000000
0.000000, 0.000000
0.000000, 0.000000
etc

Where I was expecting to get the values of latitude and longitude to 6 decimal places.

Does anyone have any clues as to what I have missed in my programming?

Many thanks and Regards.




Code:
#include <SD.h>
#include "TinyGPS.h"
#include <SoftwareSerial.h>
TinyGPS gps;
SoftwareSerial ss(51, 3);


float fkmph;
float flat, flon, fix_age;
void setup()
{
  ss.begin(4800);
  Serial.begin(9600);
  SD.begin(4);
 
  pinMode(53, OUTPUT);
}

void loop()
{
 while (ss.available())
  {
    int c = ss.read();
    if (gps.encode(c))
    {
  // process new gps info here
      long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;

// retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);

// time in hhmmsscc, date in ddmmyy
gps.get_datetime(&date, &time, &fix_age);

// returns speed in 100ths of a knot
speed = gps.speed();

// course in 100ths of a degree
course = gps.course();

float flat, flon;

// returns +/- latitude/longitude in degrees
gps.f_get_position(&flat, &flon, &fix_age);
float falt = gps.f_altitude(); // +/- altitude in meters
float fc = gps.f_course(); // course in degrees
float fk = gps.f_speed_knots(); // speed in knots
float fmph = gps.f_speed_mph(); // speed in miles/hr
float fmps = gps.f_speed_mps(); // speed in m/sec
float fkmph = gps.f_speed_kmph(); // speed in km/hr

   }
  }
 
  File myFile = SD.open("GPSTEST.csv", FILE_WRITE);

  myFile.print(flat,6);
  myFile.print(",");
  myFile.println(flon,7);
  myFile.close();
 
 
  Serial.print(flat,6);
  Serial.print(",");
  Serial.println(flon,7);
 
  delay(500);
}
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The ethernet shield uses pin 51. Why use SoftwareSerial at all, when you have a Mega?
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7183
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why use SoftwareSerial at all, when you have a Mega?
To make it more clear, MEGA has 3 additional hardware serial ports, Serial1, Serial2, and Serial3.

http://arduino.cc/en/Main/ArduinoBoardMega2560

Read the input and output section.
Logged


Mildura, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so can I still use the TinyGPS library without the Softwareserial library if I use Serial or Serial1, Serial2 or Serial3?

Cheers
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7183
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so can I still use the TinyGPS library without the Softwareserial library if I use Serial or Serial1, Serial2 or Serial3?

Cheers

I have not used that library's most recent version but I think the place you want to look into might be the feedgps function that reads from serial port and feeds info to the library for processing. If you change that part from software serial to hardware serial, you will be able to do it.
Logged


Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 Looking at the TinyGPS example called "Test with GPS device" . I tried to find all the parts that need work, hopefully I found it all.

 Here is the part that determines serial input;

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

Change to this:
Code:
static bool feedgps()
{
  while (Serial1.available())
  {
    if (gps.encode(Serial1.read()))
      return true;
  }
  return false;
}

Remove this:
Code:
SoftwareSerial nss(3, 4);

Change this;
Code:
nss.begin(4800);

To this:
Code:
Serial1.begin(4800);


Logged


Mildura, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks cyclegadget and liudur, I will change my code and see how it goes, will update with results...
Logged

Mildura, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello again,

Well I have successfully got my GPS data logger working using a hardware serial port (Serial 3) of my Mega 2560.  The data is written to the SD card of the Ethernet shield and the csv file is set up for the GPS Visualizer software. 

Thanks again for your suggestions and advice.

The code below is my latest version. 

Cheers 

Code:
#include "TinyGPS.h"
#include <SD.h>
TinyGPS gps;

void setup()
{

 Serial.begin(115200);
 Serial3.begin(4800);
 SD.begin(4);
 
 pinMode(53, OUTPUT);
 
  File myFile = SD.open("trip.csv", FILE_WRITE);
  myFile.print("type,latitude,longitude,alt");
  myFile.close();
  Serial.print("type,latitude,longitude,alt");
}
void loop()
{
 bool newdata = false; // check if data is coming in
    if (feedgps())
      newdata = true;
 
  if (newdata)
  {   
 
  unsigned long chars;
  unsigned short sentences, failed;
 
  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
 
      // process new gps info here
      long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;

// retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);

// time in hhmmsscc, date in ddmmyy
gps.get_datetime(&date, &time, &fix_age);

// returns speed in 100ths of a knot
speed = gps.speed();

// course in 100ths of a degree
course = gps.course();

float flat, flon;

// returns +/- latitude/longitude in degrees
gps.f_get_position(&flat, &flon, &fix_age);
float falt = gps.f_altitude(); // +/- altitude in meters
float fc = gps.f_course(); // course in degrees
float fk = gps.f_speed_knots(); // speed in knots
float fmph = gps.f_speed_mph(); // speed in miles/hr
float fmps = gps.f_speed_mps(); // speed in m/sec
float fkmph = gps.f_speed_kmph(); // speed in km/hr

File myFile = SD.open("trip.csv", FILE_WRITE);

  myFile.print("T");
  myFile.print(",");
  myFile.print(flat,7);
  myFile.print(",");
  myFile.print(flon,7);
  myFile.print(",");
   myFile.println(falt);
  myFile.close();
 
Serial.print("T");
Serial.print(",");
Serial.print(flat,7);
Serial.print(",");
Serial.print(flon,7);
Serial.print(",");
Serial.println(falt);

delay(500);

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

Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7183
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great! Not everyone gets back to us.

For future project planning, you may want to add a user interface such as lcd and buttons. I have a complete GPS interactive logger project code wirh my lcd shield and EEPROM. Just go to

http://liudr.wordpress.com/phi-2-shield/

Tou are welcome to take the code and use it if you want.
Logged


Mildura, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks liudr.  I do intend on adding an LCD screen so I will check it out.

Regards
Logged

Pages: [1]   Go Up
Jump to: