Go Down

Topic: Connecting Arduino Due to GPS neo-6m (Read 671 times) previous topic - next topic

CltrAltDelicious

Hello everyone,

I have an Arduino Due and want to read data from my gps neo-6m.

( Arduino datasheet: http://www.atmel.com/Images/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf)

(GPS sensor datasheet: https://www.u-blox.com/sites/default/files/products/documents/NEO-6_DataSheet_(GPS.G6-HW-09005).pdf)

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.

Thanks in advance

PS: Example Program i found:

#include <SoftwareSerial.h>
#include <Gpsneo.h>

Gpsneo gps;


char latitud[15];
char latitudHemisphere[2];
char longitud[15];
char longitudMeridiano[15];

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

void loop()
{
    gps.getDataGPRMC(latitud,latitudHemisphere,longitud,longitudMeridiano);

    Serial.println(latitud);
    Serial.println(latitudHemisphere);
    Serial.println(longitud);
    Serial.println(longitudMeridiano);
}

       

-dev

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.
Really, I used to be /dev.  :(

CltrAltDelicious

Hi -dev,

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.

Best wishes


CltrAltDelicious

-dev

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:

Code: [Select]
#ifndef GPSport_h
#define GPSport_h

#define gpsPort Serial1
#define GPS_PORT_NAME "Serial1"
#define DEBUG_PORT Serial1

#endif

This makes all the examples use Serial1.

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:

Code: [Select]
#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:

Code: [Select]
    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( '?' );
    }

Cheers,
/dev

Really, I used to be /dev.  :(

CltrAltDelicious

Hi,

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.

All the best

CltrAltDelicious

Go Up