GPS + SD module interface

#include <SoftwareSerial.h>
#include <TinyGPS.h>
 
long lat,lon; // create variable for latitude and longitude object
 
SoftwareSerial gpsSerial(10, 3); // create gps sensor connection
TinyGPS gps; // create gps object
 
void setup(){
  Serial.begin(9600); // connect serial
  gpsSerial.begin(9600); // connect gps sensor
}
 
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("Position: ");
    Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
    Serial.print("lon: ");Serial.println(lon); // print longitude
   }
  }
}

when i use the above program then there is display latitude and longitude co-ordinate.
But when i try to interface the SD card module(below the programe) there is not any co-ordinate. Where is the problem i don't understand.

#include <SoftwareSerial.h>
#include <TinyGPS.h>

#include <SD.h> 
#include <TMRpcm.h>
#include <SPI.h>
const int CS_PIN = 4;

TMRpcm tmrpcm;
char mychar;

long lat,lon; // create variable for latitude and longitude object
 
SoftwareSerial gpsSerial(10, 3); // create gps sensor connection
TinyGPS gps; // create gps object
 
void setup(){
   tmrpcm.speakerPin = 9;
 Serial.begin(9600);
 gpsSerial.begin(9600); // connect gps sensor
 
  pinMode(CS_PIN, OUTPUT);
  if(!SD.begin(CS_PIN)) {
    Serial.println("Card Failure");
    return;
  
}
  
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
   
    Serial.print("Position: ");   // display position
    Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
    Serial.print("lon: ");Serial.println(lon); // print longitude

       }
    }
 }

Please put [code] and [/code] tags around your code sections.

From the TMRpcm author:

TMRh20:
This library can be very processor intensive... May interfere with other libraries that rely on interrupts.

In your case, using a software serial library is probably not feasible. It might work with AltSoftSerial (requires pins 8 & 9, no PWM on 10). I doubt it would work with my NeoSWSerial. It definitely won't work with SoftwareSerial.

You will probably have to connect the GPS to Serial. Connect the GPS TX to Arduino pin 0 (RX) and GPS RX to Arduino pin 1 (TX). You will have to disconnect the GPS TX wire every time you want to upload a new sketch. You can still print debug statements.

You should probably use the new SdFat library instead of the SD library that comes with the IDE. It has many bug fixes and improvements. After you download the library, uncomment this line in pcmConfig.h

And you may want to try my NeoGPS library. It is smaller, faster, more accurate and more reliable than all other libraries. Because the TMRpcm library is so processor-intensive, NeoGPS can help free up a little more CPU time.

Here is a NeoGPS version of your sketch with those changes (with code tags!):

#include <SdFat.h> 
#include <SPI.h>
const int CS_PIN = 4;
SdFat SD;

#include <TMRpcm.h>
TMRpcm tmrpcm;
 
#include <NMEAGPS.h>
NMEAGPS gps;
#define gpsPort Serial

void setup()
{
  tmrpcm.speakerPin = 9;
  Serial.begin(9600);
  //gpsPort.begin(9600); // It's really on Serial, so it's already started

  pinMode(CS_PIN, OUTPUT);

  if(!SD.begin(CS_PIN)) {
    Serial.println( F("Card Failure") ); // F macro saves RAM
    return;
  }
  
  tmrpcm.play("hello.wav");
  delay(5000);
}
  
void loop()
{
  while (gps.available( gpsPort )) { // check for gps data
    gps_fix fix = gps.read(); // get latitude and longitude (everything, really)
   
    Serial.print( F("Position: ") );
    Serial.print( F("lat: ") );
    Serial.print( fix.latitude(), 5 );
    Serial.print( ' ' );
    Serial.print( F("lon: ") );
    Serial.println( fix.longitude(), 5 ); // print longitude
  }
}

Your original sketch uses 20304 bytes of program space and 1352 bytes of RAM (66%).
The NeoGPS version uses 17146 bytes of program space and 1054 bytes of RAM (51%), a significant savings.

If you want to try it, NeoGPS is available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.

Cheers,
/dev

Invalid library found in C:\Users\RAIN\Desktop\arduino-1.8.2\libraries\SdFat-master:

You did not follow the SdFat Installation instructions. The "src" directory must be in the "libraries/SdFat" subdiretory. Move the SdFat-master subdirectory somewhere else, then move ror copy the SdFat-master/SdFat directory to the Arduino/Libraries subdirectory. Then you will have Arduino/libraries/SdFat/src, among others.

Be sure to do this, too:

After you download the library, uncomment this line in pcmConfig.h

Also, you are still not using code tags around the code in your post. For example, this text IS NOT in a code block.

This text IS in a code block

You can also modify your previous posts to add the code tags

It worked perfectly.Thank you so much sir.. :slight_smile:

You should start a new topic, because your new question is not related to GPS or SD cards.