GPS shields using Arduino

Solutions for Industry based on Open Source Hardware
February 7, 2019 by
GPS shields using Arduino
Bernat Garcia

Introduction

In this case we are using a GSP shields. Connecting these shields to an Arduino Uno we are able to get the location on our board. To use this hardware in our Arduino based PLC we just have to redirect the mapping of the connections to TX1 and RX1. 

Requirements

Arduino Uno

GPS Shields based in A1037B Tyco GPS

Connections

GPS ShieldsArduino UNO
VCC5V
GNDGND
RXTX
TXRX
 

Software

// Include the SoftwareSerial library
#include "SoftwareSerial.h"
// Constants
#define txPin 8     //tx pin in gps connection
#define rxPin 9      //rx pin in gps connection
// Set up the gps serial port
SoftwareSerial gps = SoftwareSerial(rxPin, txPin);
// Variables
byte bytegps = 0;  
int i = 0;
int state = 0;
char dataGPG[100]="";
char *pch;
char *GGA[15];
int sat = 0;
void setup(){
//setup for Serial Port
Serial.begin(9600);
Serial.flush();
 
//setup for gps Serial Port  
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
gps.begin(4800);
gps.flush();
//setup satellites signal
pinMode(13, OUTPUT);
digitalWrite(13, LOW);     // Turn off the led until a satellite signal
}
void loop(){
gps.flush();
Serial.flush();
Serial.println("Waiting gps data...");
// Prepare all for reading gps Serial Port
memset(dataGPG, 0, sizeof(dataGPG));    // Remove previous readings
bytegps = 0;                            // Remove data
bytegps = gps.read();                   // Read the byte that is in the gps serial port
delay(1000);
// Find the desired string
while(bytegps != '$'){
bytegps = gps.read();
} 
// Save the string in an array
i=1;
dataGPG[0] = '$';
while(bytegps != '*' ){
bytegps = gps.read();
dataGPG[i]=bytegps; 
i++;
} 
dataGPG[i]=bytegps;
string();         // Call to the function that manipulates our string
}
/*
This function will allow us to identify the data we need to get the longitude, latitude ...
*/
void string(){
i=0;
memset(GGA, 0, sizeof(GGA));          // Remove previous readings
pch = strtok (dataGPG,",");
// Analyze the saved interval in pch to see if it the needed string
if (strcmp(pch,"$GPGGA")==0){
while (pch != NULL){
pch = strtok (NULL, ",");
GGA[i]=pch;    
i++;
} 
plot(GGA,"$GPGGA");         // Call to the function that is going to display the data
}
}
/*
This function organize the gps data received for printing in the serial monitor.
*/
void plot(char **GGAPrint, char *trama){
state = atoi(GGAPrint[5]);
sat = atoi(GGAPrint[6]);
if(trama=="$GPGGA" && state==1){
digitalWrite(13, HIGH);      // Then there are satellites, the LED switch O
Serial.println("");
Serial.println("----------------------------------------------");
Serial.print("UTC Hour -> ");
Serial.println(GGAPrint[0]);
Serial.print("Latitude -> ");
Serial.print(GGAPrint[1]);
Serial.println(GGAPrint[2]);
Serial.print("Longitude -> ");
Serial.print(GGAPrint[3]);
Serial.println(GGAPrint[4]);
Serial.print("gps quality: 0=null; 1=gps fixed -> ");
Serial.println(GGAPrint[5]);
Serial.print("Number of satellites -> ");
Serial.println(sat);
Serial.print("Horizontal Dilution of Precision -> ");
Serial.println(GGAPrint[7]);
Serial.print("Antenna altitude -> ");
Serial.print(GGAPrint[8]);
Serial.println(GGAPrint[9]);
Serial.print("Geoid Separation -> ");
Serial.print(GGAPrint[10]);
Serial.println(GGAPrint[11]);
Serial.println("----------------------------------------------");
Serial.println("");
}
else{
digitalWrite(13, LOW);                                              // Turn off the LED
Serial.println("");
Serial.println("-----------------------------");
Serial.print("|--- Satellites Used -->");
Serial.print(sat);
Serial.println(" |");
Serial.println("|----Waiting location----|");
Serial.println("-----------------------------");
Serial.println("");
}
}  

 In our Serial monitor will see the next data. 

Data in our Serial monitor

​Search in our Blog

GPS shields using Arduino
Bernat Garcia February 7, 2019

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>