GPS 

Example

: Complete Example

This example shows how to use the different functions of the Waspmote GPS API


File:
"WaspGPS_4_completeExample.pde"


Code



/*
 *  ------Waspmote GPS Complete Example--------
 *
 *  Explanation: This example shows how to use the different functions
 *  of the Waspmote GPS API
 *
 *  Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L.
 *  http://www.libelium.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Version:           0.1
 *  Design:            David Gascón
 *  Implementation:    Alberto Bielsa
 */

void setup(){
  
  //setup for Serial port
  USB.begin();
 
  // setup the GPS module
  USB.println("Setting up GPS...");
  
  // Inits SD pins
  SD.begin();
  
  // Power SD up
  SD.setMode(SD_ON);
  
  // Ephemeris Handling
  USB.println("Initializing SD");
  USB.println(SD.init());
  
  // set GPS on
  GPS.setMode(GPS_ON);
  
  // Gets Power Mode
  USB.println(GPS.getMode(),DEC);
  
  // Gets Library Version
  USB.println(GPS.getLibVersion());
     
}

long time=0;

void loop(){

  // open the uart
  GPS.begin();
  
  // Inits the GPS module
  GPS.init();
  
  // Checking for satellite connection
  while(!GPS.check()) delay(1000);
  
  // Getting Time
  GPS.getTime();  
  USB.print("Time: ");
  USB.println(GPS.timeGPS);

  // Getting Date  
  GPS.getDate();
  USB.print("Date: ");
  USB.println(GPS.dateGPS);
  
  // Getting Latitude  
  GPS.getLatitude();
  USB.print("Latitude: ");
  USB.println(GPS.latitude);

  // Getting Longitude
  GPS.getLongitude();
  USB.print("Longitude: ");
  USB.println(GPS.longitude);

  // Getting Altitude
  GPS.getAltitude();
  USB.print("Altitude: ");
  USB.println(GPS.altitude);
  
  // Getting Speed
  GPS.getSpeed();
  USB.print("Speed: ");
  USB.println(GPS.speed);
  
  // Getting Course  
  GPS.getCourse();
  USB.print("Course: ");
  USB.println(GPS.course);
  
  USB.print("Ephemeris saved ok(1), Ephemeris error(0): ");
  USB.println(GPS.saveEphems(),DEC);
  
  USB.print("Ephemeris saved ok(1), Ephemeris error(0): ");
  USB.println(GPS.saveEphems("EPHEMERIS"),DEC);
  
  delay(5000);
  
  USB.print("Ephemeris loaded ok(1), Ephemeris error(0): ");
  USB.println(GPS.loadEphems(),DEC);
  
  USB.print("Ephemeris loaded ok(1), Ephemeris error(0): ");
  USB.println(GPS.loadEphems("EPHEMERIS"),DEC);
  
  SD.close();
  
  // Changing Communication Mode
  if(GPS.setCommMode(GPS_NMEA_GGA)) USB.println("Changed OK");
  USB.println(GPS.getCommMode(),DEC);
  if(GPS.setCommMode(GPS_BINARY)) USB.println("Changed OK");
  if(GPS.setCommMode(GPS_BINARY_OFF)) USB.println("Changed OK");  
  
  // Closing UART
  GPS.close();
}
 

Download code

You can download the code of this example.


© 2009 Libelium Comunicaciones Distribuidas S.L.

| Terms of use