Go Down

Topic: GPS data logger with SD card and Mega (Read 3 times) previous topic - next topic

Steve_JB

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: [Select]
#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);
}

dxw00d

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

liudr


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.

Steve_JB

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

Cheers

liudr


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.

Go Up