I was excited to locate your code as I have been having a hard time getting my GPS and SD card to talk to each other.
I'm also new to Arduino and the code.
I have the latest Sparkfun GPS shield and SDcard shield. I have made adjustments in your code for the pin locations etc. Assuming that I have those things correct it still doesn't work.
I get to "initialization failed".
If I comment out the "return" it goes to "initialization done" and stops there.
Any suggestions or tips / Thanks
Below is your code with my changes
#include <SoftwareSerial.h>
#include < TinyGPS.cpp>
#include <TinyGPS.h>
#include <SD.h> // Standard Arduino SD card library
File myFile;
TinyGPS gps;
SoftwareSerial nss(3, 4);
///
int CS_pin = 8;
int pow_pin = 3;
///
void setup() {
Serial.begin(115200);
nss.begin(4800);
Serial.println("Reading GPS");
// Initialize SD card
Serial.print("Initializing SD card...");
pinMode(CS_pin, OUTPUT);
pinMode(pow_pin, OUTPUT);
digitalWrite(pow_pin, HIGH);
if (!SD.begin(CS_pin)) {
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("LOG.csv, 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;
}