Once we have the SquidBee mote programmed and the GPS board plugged, we connect the 9V battery. Our SquidBee mote with GPS will take around one minute to get connected to the satellites, when SquidBee get a good quality of signal from satellites it will start to provide the RMC sentences witch contains data of coordinates, speed, UTC (universal time coordinated), elevation... It's easy to modify the code above to get another NMEA sentences.
Here is an example of the NMEA sentences
$GPGLL,0000.000,N,00000.000,E,000243.000,V*26
$GPGGA,000244.000,0000.00000,N,00000.00000,E,0,00,99.0,082.00,M,18.0,M,,*5C
$GPVTG,0.0,T,,M,0.0,N,0.0,K*60
$GPGSA,A,1,,,,,,,,,,,,,99.0,99.0,99.0*00
/*
* Copyright (C) 2008 Libelium Comunicaciones Distribuidas S.L.
*
* This file is part of SquidBee code examples
* squidbee_GPS.pde 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/* Name: squidbee_GPS.pde
* Version 0.0.1
* Desc: A GPS module is attached to SquidBee as a new sensor
* Author: Marcos Yarza <m.yarza"at/removethis"libelium.com>
*/
// include the SoftwareSerial library
#include <SoftwareSerial.h>
// Constants
#define rxPin 9 //rx pin in gps connection
#define txPin 8 //tx pin in gps connection
// set up the serial port
SoftwareSerial gps = SoftwareSerial(rxPin, txPin);
// variables
byte byteGPS = 0;
int i = 0;
int count = 0;
int h = 0;
// Buffers for data input
char inBuffer[300] = "";
char GPS_sentence[100]="";
//variables for sensors
int sens0 = 0; //sensors
int sens1 = 1;
int sens2 = 2;
int val0 = 0; //aux var
int val1 = 0;
int val2 = 0;
// function to send data
void sendData(int id,int num, int data0,int data1,int data2,char GPS_sentence[]){
Serial.print("@");
Serial.print(id);
Serial.print("|");
Serial.print(num);
Serial.print("|data0-");
Serial.print(data0);
Serial.print("|data1-");
Serial.print(data1);
Serial.print("|data2-");
Serial.print(data2);
Serial.print("|GPS_sentence-");
h = 0;
while(GPS_sentence[h] != 42){
Serial.print(GPS_sentence[h]);
h++;
}
Serial.println("#r"); // end of message
}
void setup(){
//setup for mySerial port
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
gps.begin(4800);
//setup for Serial port
Serial.begin(19200);
// setup the GPS module
Serial.println("Configurando GPS...");
delay(1000);
gps.println("$PSTMNMEACONFIG,0,4800,64,1"); // configure NMEA sentences to show only RMC
delay(100);
// command for setting time and position
gps.println("$PSTMINITGPS,4140.000,N,00053.000,W,0197,22,10,2007,11,40,00");
// "4140.000,N" means: Latitude 41º40'00.0" North
// "00053.000,W" means: Longitude 0º53'00.0" West
// "0197" means 197 m elevation
// "22,10,2007,11,40,00" means date and time (October 22, 2.007 - 11h 40min 00sec UTC time)
}
void loop(){
val0 = analogRead(sens0);
val1 = analogRead(sens1);
val2 = analogRead(sens2);
byteGPS = 0;
i = 0;
while(byteGPS != 42){ // read the GGA sentence
byteGPS = gps.read();
inBuffer[i]=byteGPS;
GPS_sentence[i]=byteGPS;
i++;
}
sendData(1,count, val0,val1,val2,GPS_sentence);
count++;
delay(5000);
}