***Updated
Got the code to work with GPS UP501 and Seeed Studio SD Shield (using Arduino Uno R3)
The text file produced does not have a decimal point or headers to specify latitude or longitude (if you don't know the first column will be latitude and second will be longitude, GPS visualizer needs the column to be specified).
The way to work around this is to open your text file in MS Excel once you are done tracking.
Move the two columns down and enter Latitude for the first column and Longitude for the second.
Then scroll to the last entry of your coordinates and next to them (column 3) write 0.00001.
Select that one cell and hit ctrl+C to copy the cell (not the number but the cell itself).
Select the last two coordinates and hit ctrl+shift+HOME (this should select all values in columns one and two.
Right click the highlighted area and select Paste Special. Select Multiply and hit okay. Now your values should look right.
Save this and select yes when MS asks if you want to keep format. Now when you check back to your SD file it should have been modified. You can exit Excel and select no when it asks to save again. Now go to GPSvisualizer.com and select plain text file and upload it from your SD and BAM there is your GPS trail.
This code does not show speed, elevation, or duration but it will show the length of the distance traveled.
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SD.h>
//created by adrenaline360
const int chipSelect = 10;
long lat,lon; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(2, 3); // create gps sensor connection
TinyGPS gps; // create gps object
void setup(){
Serial.begin(57600); // try 9600 if this does not work, check w/your gps data sheet
gpsSerial.begin(9600); // try 4800 if this does not work, check w/ your gps data sheet
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Is your card plugged in, FAT16/32 formatted, are you DRUNK?, , unplug your Arduino then plug in your SD to your computer if it works disconnect it THEN plug in your Arduino, if not run ReadWrite to see if your SD works");
return; //Sometimes Windows7 will confuse the SD card if that and the Arduino is plug in and it will ask to reformat the disk.
}
Serial.println("card initialized.");
}
void loop(){
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
gps.get_position(&lat,&lon); // get latitude and longitude
// display position
Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
Serial.print("lon: ");Serial.println(lon); // print longitude
File dataFile = SD.open("Tracking.txt", FILE_WRITE);
if (dataFile) {
dataFile.print(lat);
dataFile.print('\t');
dataFile.print(lon);
dataFile.println();
dataFile.close();
}
}
}
}
***ORIGINAL QUESTION
Hello Arduino World,
I have a standalone GPS Module (UP501) connected to an Arduino Uno R3 in this configuration:
However, I do have a Seeed Studio SD Shield connected to the Arduino as well.
I have been working for around 10 hours trying to get GPS data written to the SD card but to no avail. I am using a MicroSD with a normal SD adapter. I went through all the examples and I can read and write to the MicroSD no problem. I also tested the GPS module and I do get the correct strings in the Serial Monitor (at 57600 baud).
I have used every conceivable sketch available online for GPS loggers to no avail. I settled on trying to get this following sketch to work because it makes much more sense than others. When I upload the sketch and open the serial monitor I get:
Reading GPS
Initializing SD card...initialization done.
After that nothing happens, the RX or TX leds do not flash (indicating no GPS signal is being received)
You will notice in the code there is NSS instead of Serial, well I did try replacing nss with serial but I get the same results.
I then remove the SD card to see if at least a file was created and NOTHING at all. After spending 10+ hours I decided I need the more experienced community to help me out. Please
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SD.h> // Standard Arduino SD card library
File myFile;
TinyGPS gps;
SoftwareSerial nss(2, 3);
void setup() {
Serial.begin(57600);
nss.begin(4800);
Serial.println("Reading GPS");
// Initialize SD card
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// End initialize SD Card
}
void loop() {
bool newdata = false;
unsigned long start = millis();
while (millis() - start < 5000) { // Update every 5 seconds
if (feedgps())
newdata = true;
}
if (newdata) {
gpsdump(gps);
}
}
// Get and process GPS data
void gpsdump(TinyGPS &gps) {
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.print(flat, 4);
Serial.print(", ");
Serial.println(flon, 4);
/// And write it to SD card
myFile = SD.open("tracking.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to tracking.txt...");
myFile.print(flat, 4);
myFile.print(", ");
myFile.println(flon, 4);
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening tracking.txt");
}
///
}
// Feed data as it becomes available
bool feedgps() {
while (nss.available()) {
if (gps.encode(nss.read()))
return true;
}
return false;
}