I already connected the gps sensor to my arduino like this: Vcc->5V, GND->GND, RX->TX0, TX->RX0, the only thing missing is the program and that's the problem. How do I do that?
I found online this example project, but it didn't work because of the incompatibility of the SoftwareSerial library with a Arduino Due, which I later found out isn't needed. I also read a lot how to program the gps neo-6m, but never specific with an Arduino Due.
So if anyone could help me out, I would really appreciate it.
You should use one of the hardware serial ports for the GPS device: Serial1 (pins 18 & 19), Serial2 (pins 16 and 17) or Serial3 (pins 14 and 15).
You might be interested in my NeoGPS library. It's smaller, faster, more reliable and more accurate than all other GPS libraries, and the examples are properly structured. It is very common for the other libraries' examples to break when they are modified. The NeoGPS library is compatible with the Due.
NeoGPS is available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries. Even if you don't use it, there is lots of information on the Installation and Troubleshooting pages.
thank you for your answer. I included your library and since I am not so familiar with it, could you give me an example program with the hardware serial ports, Serial1(pins 18 & 19), declared as my gps pins?
I know it is much to ask for, but it would really help me out to look if everything is working.
NeoGPS comes with many example programs. All the examples include a file that specifies which serial port you want to use: GPSport.h. Just edit that file in your Libraries/NeoGPS/src directory, and replace it with the few lines of code described here. Enter "Serial1" instead of "Serial". This is all you should have in your GPSport.h:
Almost all libraries that you download will require similar modifications, either in each example or in a configuration file in the library source directory.
After trying the examples, you may want to write your own specific program. Here is the NeoGPS version of the sketch in your OP:
#include <NMEAGPS.h>
#define gpsPort Serial1 // just an alias, not a whole new variable
NMEAGPS gps;
gps_fix fix;
void setup()
{
Serial.begin( 9600 );
gpsPort.begin( 9600 );
}
void loop()
{
if (gps.available( gpsPort )) {
fix = gps.read();
Serial.println( fix.latitude(), 6 ); // positive for N, negative for S
Serial.println( fix.longitude(), 6 ); // positive for E, negative for W
}
}
Your sketch can be very short when you know exactly what you want to do. The examples are much longer, because they have many comments and extra code to help new users.
I should also point out that the above sketch prints lat/lon even if the GPS device does not have a fix yet. If you read the NeoGPS Data Model page, you will see that there are validity flags you need to check before using fix values:
if (fix.valid.location) {
Serial.println( fix.latitude(), 6 ); // positive for N, negative for S
Serial.println( fix.longitude(), 6 ); // positive for E, negative for W
} else {
Serial.println( '?' );
}
thank you very much for your support. First I made the mistake to just download the library via browser and drag & drop the whole folder into the libraries folder, which caused an unlogical error that shouldn't be happening. (To everyone: Don't do this!)
Then I tried your method through the Library Manger and now it's working fine. Also I find your links very helpful and they gave me a good understanding of the structure/background of the process.