GPS.read() only reading -1??

I am trying to use a GPS Parallax 28146 for a project. I’m just doing some testing on Arduino to make sure it works and is accurate.

I’m new to Arduino and I’m having a hard time figuring out what’s wrong with my code. When I run the code, the only thing my GPS.read() is picking up is a value of -1. The GPS has acquired the satellites (the LED is not blinking), I’m obviously just not reading the info correctly. The link to the datasheet for the GPS is below:

http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/GPSManualV1.1.pdf

I have attached my code (this is my first time posting to the forum, so I’m not sure I attached the code correctly…).

Any help would be greatly appreciated.

#include <SoftwareSerial.h>

SoftwareSerial GPS(10, 10);

void setup(){
  Serial.begin(9600);
  GPS.begin(4800);
}


void loop(){
  delay(3000);
  GPS.write('!GPS');
  GPS.write(0x01);
  if (GPS.read() > 0){
    Serial.println("Signal Valid");
  }
  else Serial.println("Signal Not Valid");
  
 GPS.write(0x02);
 Serial.print("# of Acquired Satellites: ");
 Serial.println(GPS.read());
 
 GPS.write(0x03);
 Serial.print("Time: ");
 Serial.println(GPS.read());
 
 GPS.write(0x04);
 Serial.print("Date: ");
 Serial.println(GPS.read());
 
 GPS.write(0x05);
 Serial.print("Latitude: ");
 Serial.println(GPS.read());
 
 GPS.write(0x06);
 Serial.print("Longitude: ");
 Serial.println(GPS.read());
 
 GPS.write(0x09);
 Serial.print("Heading: ");
 Serial.println(GPS.read()); 
 
}

GPS.ino (737 Bytes)

I don't think these should be the same: SoftwareSerial GPS(10, 10);

First is the rxPin, second is the txPin.

Well here are my connections:

I’m using Arduino Mega2560

GPS Vcc to Arduino 3.3V
GPS GND to Arduino GND
GPS SIO to Arduino Pin 10

The only other connection on the GPS is raw, but that doesn’t need to be connected.

How else could I use the pins?

Also, I actually have it hooked up to Arduino Pin 49, not 10. Still reading -1

To be honest, I have used only the NMEA0183 protocol. That is a “talker”. You don’t/can’t send it anything. You just listen.

If you are using a Mega, you have 3 free hardware serial ports. Might want to try one of them.

So if I only have one SIO connection to the GPS, where do I hook it up to?

According to the datasheet for this GPS, you can send commands to get the readings you want…so that’s what I’m doing. I really just think I initialized something incorrectly.

I don't think the Arduino supports a one wire rx/tx in a hardware mode. You might be able to pull it off with software.

Just for a test (if you can), connect that I/O wire to a hardware serial rx pin. Set the GPS in NMEA0183 mode. Set that serial port at 4800 baud, and see if you get anything.

I see what you mean...I've been searching all over and I can't seem to find anything that doesn't have separate rx and tx pins.

I'm not sure how to code it at all in RAW Mode. I know that I connect the RAW pin and set it LOW. But I'm still not sure what to do with the SIO pin...I tried to write a sample code, but all I am reading is a string of "KL".

I have seen some people who redid the wiring. The GPS I'm using (Parallax 28146) has 6 black wires coming out of it labeled txd, rxd, vin, tx, rx, GND as shown in the picture below:

I have been using the Vcc, SIO, GND, and now RAW pins, but I'm wondering if it would just be easier with Arduino to use the black wires. I'm very nervous to do that tho because I don't wanna eff up the GPS...my team is on a budget and we can't afford another one :/

The black wires! I think that is what you need to use. :)

I have not looked at the datasheet, but it appears those have separate tx and rx wires. I don't know which you should use (with or without the 'd') without looking at the datasheet.

The data sheet is located here: http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/GPSManualV1.1.pdf

I tried a code that should give me the string of NMEA data (I took it from a youtube video by Kevin Darrah). I'm getting -1 again...

I think I'm gonna try to black wires now and see if that works

I found a reference in a spec sheet (not a datasheet) that mention there is both TTL and RS232 interfaces. That would mean the txd and rxd would probably be the ones to use. A o-scope would probably be the best way to check if you have one available. One of the tx (probably txd) lines will be changing 0-4v and the other (probably tx) will be changing positive/negative 6v or more.

That seems to be the same thing the guy in the video did...although it's weird, he only used the one of the txd/rxd wires (I don't remember which one). I'll have to do some test runs after I find the right connection for the wires. If the code the guy did in the video works, I'll move on to the smart mode and try to tackle that again

I'll bet he used txd and NMEA0183 mode.

But YOU want to use the proprietary mode. So pick an available hardware serial port, and connect txd to the rx and rxd to the tx. The rest you should know. If not, ask!

I rewired the GPS and now have txd hooked to pin 51, rxd hooked to pin 53, Vin hooked to Arduino power, and GND hooked to GND of course.

The good news: I am no longer getting -1
The bad new: my numbers still don’t make sense

This is a sample of a reading from the serial monitor:

Signal Valid

of Acquired Satellites: 55

Time: 44
Date: 78
Latitude: 44
Longitude: 48
Heading: 56

Idk if I just need to change the data type or what…here’s my code:

#include <SoftwareSerial.h>

SoftwareSerial GPS(51, 53);

void setup(){
  GPS.begin(4800);
  Serial.begin(9600);
}


void loop(){ 
  
  delay(2000);
  
  GPS.write('!GPS');
  GPS.write(0x01);
  if (GPS.read() > 0){
    Serial.println("Signal Valid");
  }
  else Serial.println("Signal Not Valid");
  
 GPS.write(0x02);
 Serial.print("# of Acquired Satellites: ");
 Serial.println(GPS.read());
 
 GPS.write(0x03);
 Serial.print("Time: ");
 Serial.println(GPS.read());
 
 GPS.write(0x04);
 Serial.print("Date: ");
 Serial.println(GPS.read());
 
 GPS.write(0x05);
 Serial.print("Latitude: ");
 Serial.println(GPS.read());
 
 GPS.write(0x06);
 Serial.print("Longitude: ");
 Serial.println(GPS.read());
 
 GPS.write(0x09);
 Serial.print("Heading: ");
 Serial.println(GPS.read());
}

I rewired the GPS and now have txd hooked to pin 51, rxd hooked to pin 53, Vin hooked to Arduino power, and GND hooked to GND of course.

Why?

SoftwareSerial GPS(51, 53);

SoftwareSerial does not work on the Mega. You have 4 hardware serial ports. Why are you not using one of them?

Because I did not know I could. I'm very new to Arduino. I keep seeing that tx and rx need to be switched around. So if I hook up txd to pin 15 (rx3) and rxd to pin 14 (tx3), then how do I code it?

In setup()

Serial.begin(9600);
Serial3.begin(4800);

Then in loop(), use something like this:

if(Serial3.available())
{
   Serial.write(Serial3.read());
}

That doesn't seem to work...if I use Serial.write(Serial3.read()) I get a weird y symbol and if I use Serial.println(Serial3.read()) I get -1 again...

void setup(){
  Serial3.begin(4800);
  Serial.begin(9600);
}


void loop(){ 
  
  delay(2000);
  
  Serial3.write('!GPS');
  Serial3.write(0x01);
  if (Serial3.read() > 0)
  {
    Serial.println("Signal Valid");
  }
  else Serial.println("Signal Not Valid");
  
 Serial3.write(0x02);
 Serial.print("# of Acquired Satellites: ");
 Serial.println(Serial3.read());
}

I don't know what the heck I'm doing wrong

I also tried the following code and nothing showed up in the serial monitor at all:

void loop(){ 
  
  delay(2000);
  
  Serial3.write('!GPS');
  Serial3.write(0x01);
  if(Serial3.available()){
    Serial.write(Serial3.read());
  }
}

I don't know what the heck I'm doing wrong

The "weird y symbol" and the -1 are clues. The "weird y symbol" is what is in the ASCII table at position 255, which is the value that you get when you try to store -1 in a byte.

Both mean that there was no data to read. Before trying to read, you need to test how much data is available to read, and don't bother reading if there is no data.

If there never is any data, you do not have the GPS connected correctly.

How is the GPS connected to the Mega? A picture is worth a thousand words. A good picture, in focus, properly lit, shot from the proper direction, and cropped to show just the relevant part is even more useful.