Programming nano GPS click (UART) with Arduino Mega 2560

Hello there,

First, sorry for bad english :blush:

I’m doing a project with a nano GPS click using Nano Hornet GPS (https://shop.mikroe.com/click/wireless-connectivity/nano-gps) and an Arduino Mega 2560. For the moment, I just need to print the longitude and latitude on the Serial terminal. I’m a beginner when it comes to Arduino coding so I searched for some basic codes working with a GPS and I made myself this one :

// TinyGPS - a small GPS library from Mikal Hart
#include <TinyGPS.h>

TinyGPS gps;
long lat,lon;

boolean DataReceived = false;

void setup()
{

Serial.begin(4800);
Serial1.begin(4800);
Serial.println(“Nano GPS Click Demo started”);

}

void loop()
{
while(Serial1.available()>0){

if(gps.encode(Serial1.read())){
gps.get_position(&lat,&lon);
Serial.println("//latitude :");
Serial.print(lat);
Serial.println("//longitude :");
Serial.print(lon);
}
}

}

The problem is : it only print Nano GPS Click Demo started and nothing else.
So I suppose that Serial1 does not work but I did connect RX from the GPS to TX1(pin 19) and TX to RX1(pin 18).

I found others project which had the same problem: it seems that the communication pins ( RX1 TX1 RX2 TX2 …) have an issue with RS232 but I didn’t quite understand. Well, I did try to connect RX1 to TX2 and RX2 to TX1 and print data from Serial2 but that didn’t work as well…

I also tried to connect to RX0 and TX0 the RX TX from the GPS and it also didn’t work. Every time, Serial1.available() return 0. Should I activate the GPS with some kind of START pin ? The nano Click GPS doesn’t have a real datasheet so I don’t know what does it specifically need. I only know this : the device has 9 I/O : RX/TX/GND/GND/3.3V/5V (which are essential) and RST/WUP/PWR( which seem not important but I might be wrong …)

I’m open to every suggestions or documentation.

guiguims: I found others project which had the same problem: it seems that the communication pins ( RX1 TX1 RX2 TX2 ....) have an issue with RS232 but I didn't quite understand

Thats news to me, never had a problem with the Serial Ports on a Mega 2560.

Try this simple bit of code;

void loop()                    
{
  while (Serial1.available() > 0)
  Serial.write(Serial1.read());
}


void setup()
{
  Serial.begin(115200);                        //connect at 115200 so we can read the GPS fast enough and also spit it out
  Serial1.begin(4800);                         
}

It reads the characters coming from the GPS and prints them on the Serial Monitor, you should see a series of NMEA sentences, $GPGGA, $GPRMC etc.

And it definetly works on a MEGA2560 here.

Ok I tried your code and it worked but only one time and I saw the NMEA sentences @srnet . After I did, I disconnected the device and after using the same code today it didn't worked, why ? I tried multiple times and without changing your code but that won't work again ...

But that's good news, at least I know it can work. What should I do to resolve this new problem ? Thank you by the way for your help !

I just contacted the company which did the nano GPS click and they told me that this GPS need another pin to activate to power up the GPS , it's the PWR pin. Here is what I did :

void loop()                    
{
  while (Serial1.available() > 0)
  Serial.write(Serial1.read());
}


void setup()
{
  
  Serial.begin(115200);                        //connect at 115200 so we can read the GPS fast enough and also spit it out
  Serial1.begin(4800);  
  pinMode(5, OUTPUT);                        //activate the PWR pin
  digitalWrite(5, HIGH);                       
}

And it works ! But I don't know how it worked without the PWR pin in the first place :sweat_smile:

Now I'm going to translate the NMEA sentences.

Now I'm going to translate the NMEA sentences.

There are a bunch of libraries already that can parse NMEA sentences. No real need to re-invent the wheel.

... like NeoGPS. It's smaller, faster, more reliable and more accurate than all other libraries. If you want to try it, NeoGPS and NeoSWSerial are available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries. The example NMEAsimple.ino and NMEAloc.ino are a good place to start. Tabular.ino displays all the pieces in the default configuration.

Even if you don't use it, be sure to read the Troubleshooting page. It describes many of the problems that you would run into, especially if you try other libraries' examples. We get many questions about why modifying those examples don't work any more. The NeoGPS examples are structured properly, so that you can usually modify them without breaking them.

Be sure to avoid using delay and printing too much information -- those are the two most common problems.

Cheers, /dev