Problems with GPS and SD card reader

I’m pretty new to Arduino, my problem is that using the tinygps++ library I’m recollecting certain data (long lat and alt) from the GPS NEO-7M, that is the data I want to save on my micro SD, the problem is that when the micro SD card is inserted into the SD adapter values won’t show in serial port and also the values won’t save into the micro SD. As soon as I take the micro SD out of the adapter values print fine into the serial port.

Here’s my code

gps.ino (677 Bytes)

how are you interfacing SD card to arduino ?

I’m using an Arduino nano and this is the card module.


Image embedded for our convenience:


Technique described here.

How is everything connected?

Choosing the serial connection is very important on the Nano. All the choices are listed here, from BEST to WORST. SoftwareSerial is the worst choice.

You should avoid the String class, as it can cause problems on these limited-RAM devices. There's no reason to build one big String for printing. Just print the pieces.

You should open the file just once, in setup. Then you can flush the file once per second, or connect a push button that closes the file and stops the sketch. Then it is safe to remove the card.

Here is your sketch, incorporating all those suggestions:

#include <NeoSWSerial.h>
#include <NeoTee.h>
#include <NMEAGPS.h>
#include <SdFat.h>
SdFat SD;

NeoSWSerial GPSserial(2,3);
gps_fix fix;

File d;

Print *prints[] = { &Serial, &d };
NeoTee tee( prints, 2 );

void setup() {
  d ="datalog.txt", FILE_WRITE);

void loop(){
  // check for characters from the GPS device and parse them
  if (gps.available( GPSserial )) {

    // Once per second, a complete fix structure is ready.
    fix =;

    if (fix.valid.location)
      tee.print( fix.latitude(), 6 );
    tee.print( ',' );
    if (fix.valid.location)
      tee.print( fix.longitude(), 6 );
    tee.print( ',' );

    if (fix.valid.altitude)
      tee.print( fix.altitude() );


This uses my NeoGPS and NeoSWSerial libraries. They are available from the Arduino Library Manager, under the menu Sketch-> Include Library-> Manage Libraries.

To print the GPS info to 2 destinations at the same time (the Serial port and the SD file), it also uses my NeoTee library (available here). You have to manually install this library: download the zip, and extract it to a temporary location. From the temporary location, copy the nested NeoTee-master subdirectory into your Arduino/Libraries directory.

Notice that the sketch checks the validity flags before printing lat, lon or alt values. Your GPS may not know these values yet, so you shouldn't print them if the GPS device hasn't sent them.

The sketch also uses the SdFat library instead of SD. SdFat is newer and has many bug fixes and performance enhancements over the old SD library. It is available from the Library Manager.

Thanks a lot it works, the only problem that I have now is that after a certain time, the values are printed as if it was typed, meaning it prints 1 character till it ends the whole line.

How is everything connected? (again…)

after a certain time

How long would that be?

the values are printed as if it was typed

I can type quite a few different ways.

meaning it prints 1 character till it ends the whole line.

In the Serial Monitor window or in the SD file?

Show us the output in code tags,

 so it looks

   like this.

Copy the text from the Serial Monitor window, and paste it into the post editor field. Then select the text and press the “</>” button in the upper left corner of the editor. You should see [code] and [/code] before and after the output.

When you press Preview, it is displayed in the white code box.

same problem but i am using Arduino UNO and i am using same micro sd card module. here is my code

gps_data_logging.ino (5.12 KB)