Difference between revisions of "Arduino: TinyGPS"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "==library== cd ~/Arduino/libraries/ wget https://github.com/mikalhart/TinyGPS/archive/master.zip unzip master.zip ==Code== #include <SoftwareSerial.h> #include...")
 
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
 
==Code==
 
==Code==
  
    #include <SoftwareSerial.h>
+
#include <SoftwareSerial.h>
    #include <TinyGPS.h>
+
#include <TinyGPS.h>
   
+
 
    long lat,lon; // create variable for latitude and longitude object
+
long lat,lon; // create variable for latitude and longitude object
   
+
 
    SoftwareSerial gpsSerial(2, 3); // create gps sensor connection
+
SoftwareSerial gpsSerial(3, 4); // RX 3 TX 4 create gps sensor connection
    TinyGPS gps; // create gps object
+
TinyGPS gps; // create gps object
   
+
 
    void setup(){
+
void setup(){
      Serial.begin(9600); // connect serial
+
  Serial.begin(9600); // connect serial
      gpsSerial.begin(4800); // connect gps sensor
+
  gpsSerial.begin(9600); // connect gps sensor
    }
+
}
   
+
 
    void loop(){
+
void loop(){
      while(gpsSerial.available()){ // check for gps data
+
  while(gpsSerial.available()){ // check for gps data
      if(gps.encode(gpsSerial.read())){ // encode gps data
+
    if(gps.encode(gpsSerial.read())){ // encode gps data
        gps.get_position(&lat,&lon); // get latitude and longitude
+
    gps.get_position(&lat,&lon); // get latitude and longitude
        // display position
+
    // display position
        Serial.print("Position: ");
+
    Serial.print("Position: ");
        Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
+
    Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
        Serial.print("lon: ");Serial.println(lon); // print longitude
+
    Serial.print("lon: ");Serial.println(lon); // print longitude
      }
 
      }
 
 
     }
 
     }
 +
  }
 +
}

Latest revision as of 13:51, 14 June 2018

library

cd ~/Arduino/libraries/
wget https://github.com/mikalhart/TinyGPS/archive/master.zip
unzip master.zip


Code

#include <SoftwareSerial.h>
#include <TinyGPS.h>
 
long lat,lon; // create variable for latitude and longitude object
 
SoftwareSerial gpsSerial(3, 4); // RX 3 TX 4 create gps sensor connection
TinyGPS gps; // create gps object
 
void setup(){
  Serial.begin(9600); // connect serial
  gpsSerial.begin(9600); // connect gps sensor
}
 
void loop(){
  while(gpsSerial.available()){ // check for gps data
   if(gps.encode(gpsSerial.read())){ // encode gps data
    gps.get_position(&lat,&lon); // get latitude and longitude
    // display position
    Serial.print("Position: ");
    Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
    Serial.print("lon: ");Serial.println(lon); // print longitude
   }
  }
}