Author Options:

Arduino and GPS data logging - code/hardwire glitch Answered

I've followed Gabriella Levine's code using an LS20031 GPS module. A couple of problems:

1. Can I run the SD card off the 3.3V arduino lead rather than using 5V and stepping it down (as one sketch suggested using a resister array)?
2. I've attached an image of what my Serial Monitor is reading and can't get it to align properly, feed consistently, etc. I've tried changing many aspects of the code, reverting back to original after each. Nothing seems to help. The only time I get a stream of NMEA data is when I reverse the Tx and Rx at the Arduino and hold the reset button - then it pours in.
3. I checked with my local hacker group last night but not too many are working on GPS projects - I've pasted my code below. If someone can confirm the wiring of this, that would be great. I'm still early in my Arduino project work. I made some notes in the code so you can see where I think the problems are. 
4. Could it be that the baud rate (57,600) of the LS20031 is just too high?


//Gabriella Levine - starting code
//code (no shield, just a MicroSD like mine, different GPS, same idea with some good additional ideas
// original code source: https://github.com/Protei/Protei-005-6/blob/master/GPS_GPRMCstringsParsed_toSD/GPS_GPRMCstringsParsed_toSD.pe
//See website saved in folder for instructions on wiring - she has clear, direct approaches - very good.
//My LS20031 GPS module (marked 1590R-A over a P) runs at a baud rate of 57600 (bytes per second)
#include <Wire.h>
#include <SD.h>
#include <string.h>//this seems to be in the library but unclear - why isn't it orange like the others?
#include <ctype.h>// same with this - not sure what it's doing
int ledPin = 13;                  // LED test pin
int ledState = LOW;
long previousMillise = 0;
long interval = 1000;
long previousMillis = 0;
const int ledPin12 = 12;
int rxPin = 0;                    // RX PIN
int txPin = 1;                    // TX TX
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
const int chipSelect = 8;//changed from 53 on the Arduino Mega which Gabriella used
const int LOCATION_FILE_NUMBER_LSB = 0x00;
const int LOCATION_FILE_NUMBER_MSB = 0x01;
File dataFile;
void setup() {
  pinMode(8, OUTPUT);
  pinMode(ledPin12, OUTPUT);
  pinMode(ledPin, OUTPUT);       // Initialize LED pin
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  Serial.begin(57600); //GPS baud rate

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
  Serial.println("card initialized.");

  Serial.println("Time, Status, Latitude, Direction, Longitude, Direction, Velocity, Heading, Date, Magnetic degrees, E/W, Checksum");
  delay(1000); //this is the point where it seems to loop through without writing GPS data properly

  // start the wire and RTC libraries:

  dataFile = SD.open("NewGPS.txt",FILE_WRITE); //removed space before "File Write"
  delay(20); //this also seems to work as the SD Card does have this file with a few NMEA lines and then it just stops

  for (int i=0;i<300;i++){       // Initialize a buffer for received data
    linea[i]=' ';
void loop() {
  digitalWrite(ledPin, HIGH);
  byteGPS=Serial.read();         // Read a byte of the serial port
  if (byteGPS == -1) {           // See if the port is empty yet.
  else {
    linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
    //Serial.write(byteGPS, 0);
    //dataFile.print(byteGPS, 0);
    if (byteGPS==13){            // If the received byte is = to 13, end of transmission
      digitalWrite(ledPin, LOW);
      for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
        if (linea[i]==comandoGPR[i-1]){
      if(bien==6){               // If yes, continue and process the data
        for (int i=0;i<300;i++){ 
          if (linea[i]==','){    // check for the position of the  "," separator
          if (linea[i]=='*'){    // ... and the "*"
        Serial.println("");      // ... and write to the serial port

        for (int i=0;i<12;i++){

          for (int j=indices[i];j<(indices[i+1]-1);j++){


          dataFile.println("");      // ... and write to the serial port
          digitalWrite(ledPin12, HIGH);

          for (int i=0;i<12;i++){
                         // case 0 :dataFile.print("Time in UTC (HhMmSs): ");break;
                         // case 1 :dataFile.print("Status (A=OK,V=KO): ");break;
                         // case 2 :dataFile.print("Latitude: ");break;
                         // case 3 :dataFile.print("Direction (N/S): ");break;
                         // case 4 :dataFile.print("Longitude: ");break;
                         // case 5 :dataFile.print("Direction (E/W): ");break;
                         // case 6 :dataFile.print("Velocity in knots: ");break;
                         // case 7 :dataFile.print("Heading in degrees: ");break;
                         // case 8 :dataFile.print("Date UTC (DdMmAa): ");break;
                         // case 9 :dataFile.print("Magnetic degrees: ");break;
                         // case 10 :dataFile.print("(E/W): ");break;
                         // case 11 :dataFile.print("Mode: ");break;
                         // case 12 :dataFile.print("Checksum: ");break;
            for (int j=indices[i];j<(indices[i+1]-1);j++){

          digitalWrite(ledPin12, LOW);


      conta=0;                    // Reset the buffer
      for (int i=0;i<300;i++){   
        linea[i]=' ';            


The forums are retiring in 2021 and are now closed for new topics and comments.