Go Down

Topic: TinyGPS and hardware serial? (Read 23120 times) previous topic - next topic

PaulS

Quote
but i get the same data,
And you, too, failed to post your code.
The art of getting good answers lies in asking good questions.

akku_123

After i re-installing the library the error got disappeared..but after i execute the following code the serial monitor shows nothing..

akku_123

    #include <SoftwareSerial.h>
    #include <TinyGPS.h>
     
    long lat,lon; // create variable for latitude and longitude object
     
    SoftwareSerial gpsSerial(2, 3); // create gps sensor connection
    TinyGPS gps; // create gps object
     
    void setup(){
      Serial.begin(9600); // connect serial
      gpsSerial.begin(4800); // 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
       }
      }
    }

PaulS

Code: [Select]
      while(gpsSerial.available()){ // check for gps data
       if(gps.encode(gpsSerial.read())){ // encode gps data

Assuming that there is data on the SoftwareSerial port, read it and, if it ends a sentence, do some stuff and show the results.

Now, there are two assumptions about that you do NOT know to be true.

You do NOT know that there is really data to read on the SoftwareSerial port.
And, even if there is, you don't know that the data is any good.

So, your loop() should look like:
Code: [Select]
  void loop()
  {
    while(gpsSerial.available())
    {
        char c = gpsSerial.read();
        Serial.print(c);
    }
  }

until you KNOW that you are reading good data.
The art of getting good answers lies in asking good questions.

akku_123

after i use character datatype it returns garbage values and for integer it returns 0

PaulS

after i use character datatype it returns garbage values and for integer it returns 0
You have some code? You have some output you want to show (screenshots of)?
The art of getting good answers lies in asking good questions.

akku_123

hi there, sorry for my late reply....
 
my problem got solved.... i used tinyGPSplus library serial 2 of my arduino..thanq..

Go Up