GPS Tracker Creation

hi i have followed the diagram from this tutorial https://core-electronics.com.au/tutorials/how-to-use-gps-with-arduino.html however i get an error about myserial was not declared in this scope any ideas please
i am using the code provided in the tutorial

Can someone advise what value i need to add in the merserial and where do i find said value

Hey Claude,
That sample code didn’t specifically declare any object called myserial. You’ll just need to do it in the step before that reads:
SoftwareSerial OurGPSModule(RxPin, TxPin);

For example:
SoftwareSerial mySerial(3, 2);

Let us know if that gets you through it.

Hi

In the tutorial it clearly shows that line as per screen shot

When I comment that line out I then get the following error further down the code

Serial does not have a name type

Below is the full sketch I am using

#include <Adafruit_GPS.h>

#include <SofwareSerial.h>

SoftwareSerial OurGPSModule(2, 3);

// Adafruit_GPS GPS(&mySerial)

Serial.begin(115200); //This baud rate will help a lot in printing all of the data that comes from the GPS Module to the serial monitor

GPS.begin(9600);

GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Sets output to only RMC and GGA sentences

GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); //Sets the output to 1/second. If you want you can go higher/lower

GPS.sendCommand(PGCMD_ANTENNA); //Can report if antenna is connected or not

GPS.parse(GPS.lastNMEA()); //This is going to parse the last NMEA sentence the Arduino has received, breaking it down into its constituent parts.

GPS.newNMEAreceived(); //This will return a boolean TRUE/FALSE depending on the case.

Serial.print("\nTime: ");

    Serial.print(GPS.hour, DEC); Serial.print(':');

    Serial.print(GPS.minute, DEC); Serial.print(':');

    Serial.print(GPS.seconds, DEC); Serial.print('.');

    Serial.println(GPS.milliseconds);

    Serial.print("Date: ");

    Serial.print(GPS.day, DEC); Serial.print('/');

    Serial.print(GPS.month, DEC); Serial.print("/20");

    Serial.println(GPS.year, DEC);

    Serial.print("Fix: "); Serial.print((int)GPS.fix);

    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);

    if (GPS.fix) {

      Serial.print("Location: ");

      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);

      Serial.print(", ");

      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);

      Serial.print("Location (in degrees, works with Google Maps): ");

      Serial.print(GPS.latitudeDegrees, 4);

      Serial.print(", ");

      Serial.println(GPS.longitudeDegrees, 4);

      Serial.print("Speed (knots): "); Serial.println(GPS.speed);

      Serial.print("Angle: "); Serial.println(GPS.angle);

      Serial.print("Altitude: "); Serial.println(GPS.altitude);

      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);

Regards

Claude

Heyo,

Did you include the Adafruit library?

  • Adafruit GPS library - Open up your Arduino IDE and head to your Sketch > Include Library > Manage Libraries window. Search for GPS and select the option, “Adafruit GPS Library”.

Also i am using the following for my gps hardware

The hardware in the tutorial is the ultimate gps module and from the images i do not see the gps chip set just the aerial ???

Claude Raiola

0414 228 948

Yes

Claude Raiola

0414 228 948

Hey Claude,
The name of the Software Serial Object you set up needs to match the one you are calling in the GPS line

SoftwareSerial mySerial(2, 3);
Adafruit_GPS GPS(&mySerial);

Sorry i do not understand

I transposed the tx,rx values to 2,3 to reflect the connection ports on the arduino board

And the this line

GPS(&amp;mySerial);

Is used as shown in the instructions of the tutorial

May be the tutorial needs to give more detail as clearly i cannot get it working from following it

Claude Raiola

0414 228 948

1 Like

Hi Aidan

PROGESS

I have sorted the code as per your last email

SoftwareSerial mySerial(2, 3);

Adafruit_GPS GPS(&mySerial);

My next compile error is

Serial does not have a name

And it relates to

Serial.print(" quality: "); Serial.println((int)GPS.fixquality);

You assistance is much appreciated

Regards

Claude Raiola

0414 228 948

Hi Again

Sorry the error message is

Serial does not name a type

Relating to

Serial.print(" quality: "); Serial.println((int)GPS.fixquality);

Regards

Claude Raiola

0414 228 948

Hi Claude,

I can’t see a problem with that specific line are you able to post the line previous as well.

Here is the full code i am using

#include <Adafruit_GPS.h>
#include <SofwareSerial.h>
SoftwareSerial mySerial(2, 3);
Adafruit_GPS GPS(&mySerial);
Serial.begin(115200); //This baud rate will help a lot in printing all of the data that comes from the GPS Module to the serial monitor
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Sets output to only RMC and GGA sentences
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); //Sets the output to 1/second. If you want you can go higher/lower
GPS.sendCommand(PGCMD_ANTENNA); //Can report if antenna is connected or not
GPS.parse(GPS.lastNMEA()); //This is going to parse the last NMEA sentence the Arduino has received, breaking it down into its constituent parts.
GPS.newNMEAreceived(); //This will return a boolean TRUE/FALSE depending on the case.
Serial.print("\nTime: ");
Serial.print(GPS.hour, DEC); Serial.print(’:’);
Serial.print(GPS.minute, DEC); Serial.print(’:’);
Serial.print(GPS.seconds, DEC); Serial.print(’.’);
Serial.println(GPS.milliseconds);
Serial.print(“Date: “);
Serial.print(GPS.day, DEC); Serial.print(’/’);
Serial.print(GPS.month, DEC); Serial.print(”/20”);
Serial.println(GPS.year, DEC);
Serial.print("Fix: “); Serial.print((int)GPS.fix);
Serial.print(” quality: "); Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print("Location: “);
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(”, ");
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print("Location (in degrees, works with Google Maps): “);
Serial.print(GPS.latitudeDegrees, 4);
Serial.print(”, ");
Serial.println(GPS.longitudeDegrees, 4);
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);

i have just tried another sketch as per below and it generates a serial2 error

i am spending days search the web trying supposed solutions and none of them work each having one error on another its totally frustrating when i am following the steps exactly

I want to be able to store geo fence co ordinates on the arduino so that as the unit detects entering one of the geo fences then the unit alerts via light flash or sound

sadly despite my tenacity i am getting no where fast

the sketch is as follows

#include <Arduino.h>
#include “NMEAGPS.h”

NMEAGPS gps;
gps_fix fix; // the current GPS fix
HardwareSerial & gps_port = Serial2; // an alias

NeoGPS::Location_t home( 254139360L, 682662360L ); // degrees * 10,000,000
const float thresholdDistance = 1.00; //km
uint8_t gpsSeconds; // for counting elapsed time instead of using delay

void setup()
{
Serial.begin(9600);
Serial.println(“Hello!”);

gps_port.begin(9600);

} // setup

void loop()
{
while (gps.available( gps_port )) {
fix = gps.read(); // save the latest

// Instead of delay, count the number of GPS fixes
gpsSeconds++;
if (gpsSeconds >= 3) {
  gpsSeconds = 0;

  displayInfo();
  checkDist();
}

}
} // loop

void displayInfo()
{
Serial.print("Position: ");

if (fix.valid.location) {
Serial.print("lat: “); Serial.print(fix.latitude(), 6); Serial.print(” ");// print latitude
Serial.print("lon: "); Serial.println(fix.longitude(), 6); // print longitude
} else
Serial.println( ‘?’ );

} //end displayInfo()

void checkDist()
{
if (fix.valid.location) {
float dist = fix.location.DistanceKm( home );

if (dist >= thresholdDistance )
{
  Serial.print("Subject is ");
  Serial.print(dist - thresholdDistance, 6);
  Serial.println("KM beyond threshold");
}
else
{
  Serial.println("Subject within threshold, no worries!");
}

}
}

Hey Claude,
It turns out there have been some updates to the IDE, and the SoftwareSerial command is now inbuilt. I’ve made the changes required to that tutorial and posted them. Bear in mind this tutorial assumes that you have correctly installed the Adafruit GPS Library and simply shows you how you can read GPS data from the Adafruit Ultimate GPS Module.

Moving forward, can you try the code again (in a new sketch) and see if it compiles and runs (by opening the Serial Monitor @ 115200 Baud).

You should see data being written out that looks like this:

1 Like

Hi Aiden

\Well the good news is that it works and i am getting the same output as you have indicated so thats progress indeed

HOWEVER i am now sitting outside to open sky and when i run the process i still recieve the same output without any gps fix / quality or date / time from gps

given we have jumped over hurdle one can you direct me where i can learn why i am not getting gps data given i am outside

1 Like

That sounds normal - A cold start can take a few minutes to get a lock

Photo of hardware used

Claude Raiola

0414 228 948

1 Like

Hey Claude,
That’s good to hear. Take a look at this tutorial for more information about GPS and it’s operation. I’d specifically note the Cold/Warm/Hot start section toward the bottom.

Thanks

Ok will do

I am wanting to store at least 100 records of geofence co ordinates for my project without having to go to the next step of adding an sd card to the project

Do you think the memory of the arduino uno will be able to hold that data as well as the program code ??

I need the geofences to be checked if they have been entered every 3-4 seconds

Thanks in advance

Claude Raiola

0414 228 948

Hi Claude,

If the area is a rectangle, you only need 8 floating point numbers (32-bit values) to build that logic, along with inclusion of some floating point math. It’s very possible to do with an Arduino.

With that said, you’ll quickly hit the RAM limits on the ATmega328 if the project becomes more complicated. If that happens, it would be best to consider other hardware with more elbow room such as the Particle Photon or some newer Arduino.

1 Like