Can not Serial.read() from 10Hz GPS

Hi,

I have simple sketch to write GPS data to SD card.
But when I try to power Arduino without USB and GPS module in RX/TX pins, nothing happens.

Am I missing some simple thing, like some kind of handshake between GPS module and Serial? :slight_smile:
I can not use any SoftwareSerial library as my GPS module is 10Hz with baud rate 115200 and the libraries does not support it.

Arduino :

BN: Arduino/Genuino Uno
VID: 2341
PID: 0043

I have tested few things that the system should work.

Test 1.
I connect GPS module to RX/TX pins and 5V and Ground.
I upload empty sketch to Arduino.
USB connected.
I open Serial Monitor in Arduino IDE and with the right baud rate (115200) I can see the data flowing just fine.

...
$GPRMC,001534.000,V,,,,,0.00,0.00,060180,,,N*41
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,001534.100,,,,,0,0,,,M,,M,,*4A
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
...

Test 2.
I upload the following sketch.

#include <SPI.h>
#include <SD.h>

String dataString = "";
void setup() {
  Serial.begin(115200);
  while(!Serial){
    ;
  }
  Serial.flush();
  SD.begin(4);
}

void loop() {
  char c;
  if(Serial.available() > 0){
    c = Serial.read();
    if(c == '

I open Serial Monitor in Arduino IDE and send for example "$TEST$" to Arduino.
The message gets saved ("$TEST") to the file.

Test 3.
With that sketch, I connect GPS module to Arduino TX/RX, 5V and Ground.
I power the Arduino with the 12V. (USB is disconnected)
Everything should work according to my knowledge... but it's not. Nothing happens.

Summary
In Test 1. I clearly see data coming in Serial with baud rate 115200.
In Test 2. I clearly see data moving from Serial to SD card.
Why Test 3. does not work?

ps. I also tried Arduino Nano as Serial writer, no luck so I don't think the GPS module is faulty or anything like that. I also tried to cast the byte from Serial.read() to int, char etc. but it works in Test 2. but not in Test 3.){
      File dataFile = SD.open("datalog.txt", FILE_WRITE);
      if (dataFile) {
        dataFile.println(dataString);
        dataFile.close();
        dataString = c;
      }
    }
    else{
      dataString += c;
    }
  }
}


I open Serial Monitor in Arduino IDE and send for example "$TEST$" to Arduino.
The message gets saved ("$TEST") to the file.

**Test 3.**
With that sketch, I connect GPS module to Arduino TX/RX, 5V and Ground.
I power the Arduino with the 12V. (USB is disconnected)
Everything should work according to my knowledge... but it's not. Nothing happens.

**Summary**
In Test 1. I clearly see data coming in Serial with baud rate 115200.
In Test 2. I clearly see data moving from Serial to SD card.
Why Test 3. does not work? 

ps. I also tried Arduino Nano as Serial writer, no luck so I don't think the GPS module is faulty or anything like that. I also tried to cast the byte from Serial.read() to int, char etc. but it works in Test 2. but not in Test 3.

If you are using an Uno or a Nano it would be simpler to use SoftwareSerial to get data from the GPS and leave Serial for communication with the PC. However note that SoftwareSerial won't work at 115200 baud. Start with 9600 baud and you should be able to get it to work at 38400 baud. There are other libraries - AltSofSerial and NeoSoftSerial which are probably better.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

There are also specialised libraries for using GPS data which may make life easier.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

...R

Yes software serials would of course be best to use but the 10Hz 115200 baud rate just does not work with the Arduino Uno...

With AltSoftSerial I have managed to get almost usable data.. the are wrong chars and line breaks are missing etc...

Input:

#include <AltSoftSerial.h>

// AltSoftSerial always uses these pins:
//
// Board          Transmit  Receive   PWM Unusable
// -----          --------  -------   ------------
// Teensy 3.0 & 3.1  21        20         22
// Teensy 2.0         9        10       (none)
// Teensy++ 2.0      25         4       26, 27
// Arduino Uno        9         8         10
// Arduino Leonardo   5        13       (none)
// Arduino Mega      46        48       44, 45
// Wiring-S           5         6          4
// Sanguino          13        14         12

// This example code is in the public domain.

AltSoftSerial altSerial;

void setup() {
  Serial.begin(230400);
  while (!Serial) ; // wait for Arduino Serial Monitor to open
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(115200);
}

void loop() {
  char c;

  if (Serial.available()) {
    c = Serial.read();
    altSerial.print(c);
  }
  if (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
  }
}

Output

...
$GPGGA,002447.500,,,,0,0,,,M,,M,,*48
$GPGLL,,,,,002447.500,V,N*7A
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*7NC!⸮%⸮
⸮002447.500,V,,,,,0.00,0.00,060180,,,N*42
...

Suggest-
Stick with HW serial
Remove GPS TX to upload code to Arduino
Use NEOGPS for minimum memory usage
Do you need all sentences to be read ?
This is a lot of data at 10hz
Best of luck

Gerihatrick:
Suggest-
Stick with HW serial
Remove GPS TX to upload code to Arduino
Use NEOGPS for minimum memory usage
Do you need all sentences to be read ?
This is a lot of data at 10hz
Best of luck

All good pieces of advice, but I would suggest one more: Disable all sentences you don't care about. Usually RMC sentences are all you need for nav purposes.

If you must use HardwareSerial for the GPS then, if you need to communicate with your PC I suggest you use SoftwareSerial for that coupled with a USB-TTL cable.

...R