Hi Guys;
I have a project that is using a GPS receiver and I am lost with some of the commands.
My issue is getting the latest data from the GPS and updating the variables for my program.
I am after SPEED, Course, Altitude and Quantity of Satellites.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
SoftwareSerial GPS(8, 7);
const char UBLOX_INIT[] PROGMEM = {
0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0x64, 0x00, 0x01, 0x00, 0x01, 0x00,
0x7A, 0x12,0x12, 0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x0E, 0x30,}; //(Set GPS to Read at 10Hz)
float Dir, S, SK, SM;
void setup(){
Serial.begin(115200);
GPS.begin(9600);
for (int i = 0; i < sizeof(UBLOX_INIT); i++) {
GPS.write( pgm_read_byte(UBLOX_INIT + i) );
delay(5);}}
int C;
int Alt;
int AltM;
int AltF;
int Sat;
void loop(){
while (GPS.available() > 0)
if (gps.encode(GPS.read()))
if (millis() > 5000 && gps.charsProcessed() < 10){
while(true);}
if (gps.speed.isValid()){
SK = (gps.speed.kmph()); // Read Speed in KM/H
SM = (gps.speed.mph());} // Read Speed in MPH
if (gps.altitude.isValid()){
AltM= gps.altitude.meters(); // Read Altimeter in Meters
AltF= gps.altitude.feet();} // Read Altimeter in Feet
if (gps.course.isValid()){
Dir = gps.course.deg();} // Read Course Direction
if (gps.satellites.isValid()){
Sat = gps.satellites.value();} // Read Satellite Quantity
if (digitalRead(5) == LOW){
S = SK;
Alt = AltM;
Serial.print(S); // Speed in KM/H
Serial.println(F(" KM/H"));
Serial.print(Alt); // Altimeter in Meters
Serial.println(F(" M Alt"));}
if (digitalRead(5) == HIGH){
S = SM;
Alt = AltF;
Serial.print(S); // Speed in MPH
Serial.println(F(" MPH"));
Serial.print(Alt); // Altimeter in Feet
Serial.println(F(" F Alt"));}
// SERIAL PRINT VALUES
Serial.print(Dir); // Show Course Direction
Serial.println(F(" Dir"));
Serial.print(Sat); // Show Satellite Quantity
Serial.println(F(" Sats"));
Serial.println(" ");
}
The problem I am seeing is that the data is not updating any ware close to real time or accuracy.
what am I doing wrong?
Thanks
Rick