# Problems with GPS and SD card reader

**URL:** <https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453>\
**Category:** Programming\
**Created:** [June 2, 2018, 6:22am UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453 "2018-06-02T06:22:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivanbrm](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@Ivanbrm](https://forum.arduino.cc/u/Ivanbrm)\
**Post date:** [June 2, 2018, 6:22am UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/1 "2018-06-02T06:22:57Z")

</div>

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](https://forum.arduino.cc/uploads/short-url/mKGYqKxt5DEZBxHPviQv6FCFnDy.ino) (677 Bytes)

---

<div class="post-metadata">

**Author:** ![anilkunchalaece](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@anilkunchalaece](https://forum.arduino.cc/u/anilkunchalaece)\
**Post date:** [June 2, 2018, 7:16am UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/2 "2018-06-02T07:16:37Z")

</div>

how are you interfacing SD card to arduino ?

---

<div class="post-metadata">

**Author:** ![Ivanbrm](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@Ivanbrm](https://forum.arduino.cc/u/Ivanbrm)\
**Post date:** [June 2, 2018, 8:36am UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/3 "2018-06-02T08:36:33Z")

</div>

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

![CATALEX.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/4/e/8/4e802c51dd98f89f9afdf9a3ab7af78b89940c59.jpeg)

---

<div class="post-metadata">

**Author:** ![dev\_1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dev_1/32/215847_2.png) [@dev\_1](https://forum.arduino.cc/u/dev_1)\
**Post date:** [June 2, 2018, 2:30pm UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/4 "2018-06-02T14:30:28Z")

</div>

Image embedded for our convenience:

![CATALEX.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/4/e/8/4e802c51dd98f89f9afdf9a3ab7af78b89940c59.jpeg)

Technique described [here](https://forum.arduino.cc/index.php?topic=519037.0).

How is everything connected?

Choosing the serial connection is very important on the Nano. All the choices are listed [here](https://github.com/SlashDevin/NeoGPS/blob/master/extras/doc/Installing.md#2-choose-a-serial-port), 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:

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

NeoSWSerial GPSserial(2,3);
NMEAGPS gps;
gps_fix fix;

File d;

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

void setup() {
  Serial.begin(9600);
  GPSserial.begin(9600);
  SD.begin(4);
  d = SD.open("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 = gps.read();

    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() );

    tee.println();
    d.flush();
  }
}

```

This uses my [NeoGPS](https://github.com/SlashDevin/NeoGPS) and [NeoSWSerial](https://github.com/SlashDevin/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](https://github.com/SlashDevin/NeoTee)). 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.

---

<div class="post-metadata">

**Author:** ![Ivanbrm](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@Ivanbrm](https://forum.arduino.cc/u/Ivanbrm)\
**Post date:** [June 2, 2018, 6:47pm UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/5 "2018-06-02T18:47:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dev\_1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dev_1/32/215847_2.png) [@dev\_1](https://forum.arduino.cc/u/dev_1)\
**Post date:** [June 3, 2018, 3:41am UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/6 "2018-06-03T03:41:11Z")

</div>

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** ,

```arduino
 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.

---

<div class="post-metadata">

**Author:** ![1hitarth](https://avatars.discourse-cdn.com/v4/letter/1/da6949/32.png) [@1hitarth](https://forum.arduino.cc/u/1hitarth)\
**Post date:** [January 22, 2020, 4:04am UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/7 "2020-01-22T04:04:07Z")

</div>

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](https://forum.arduino.cc/uploads/short-url/mXzd3IFtvR8tEviGexgjfgGRyxI.ino) (5.12 KB)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:13pm UTC](https://forum.arduino.cc/t/problems-with-gps-and-sd-card-reader/529453/8 "2021-05-05T23:13:18Z")

</div>

Closed on May 5, 2021, 11:13pm UTC


