Help needed with GPS project SOLVED!

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

If the module doesn't have a clear view of the sky, the measurements won't be updated from time to time.

TinyGPS++ has a function to read the "age" of the most recent update, so you can decide whether the measurements are still useful.

I don't believe it is having trouble seeing the satellites as i have another program that displays the data just fine. But it dosent show all the data i need.

Rick

Check the age and then you can be sure. You don't need to convince me of anything.

When I see your code - it looks like you miss a curly bracket (the { )
Your code is this:

while (GPS.available() > 0)
if (gps.encode(GPS.read()))

if (millis() > 5000 && gps.charsProcessed() < 10){
    while(true);}

For a better view, it looks like this (symbolic):

WHILE ()
{
    if (A)
    {
        if (B) { ... }
    }
}

All the rest of code is "outside" your WHILE ! Your WHILE() has just two IF()s, which are "nested".
Are you sure the code is right?
For me it looks like, you miss curly brackets.

I will check that out shortly. Hopefully, that is my issue!

Rick

tjaekel, preliminary testing looks like that was the issue. I will fully test it out tomorrow in the car
and let you know.

Thanks,
Rick

tjaekel, that did it! Thank you so much!

Rick

Hint.
Do a press [ CTRL ] [ T ] when you edit your code and check the { and } indenting, that way you could have possibly found it earlier.

Tom... :smiley: :+1: :coffee: :australia:

COOL! Well done.
Happy coding...!

Torsten (tjaekel)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.