mikalhart / TinyGPSPlus

A new, customizable Arduino NMEA parsing library
http://arduiniana.org
1.05k stars 486 forks source link

encode always returns false #96

Closed preshantram closed 2 years ago

preshantram commented 2 years ago

When trying to use DeviceExample with Arduino nano , using software serial on pin 8 , 7 encoding always returns false. when using the basic example it seems to be running just fine.

What i've tried so far:

I tried if the ss.read() gets any valid NMEA data, which seem to be the case.

Any ideas?

preshantram commented 2 years ago

#include <SoftwareSerial.h>

const char *gpsStream = "$TESTI,3,1,2,1,2,0,2,2,75*72\r\n";
static const int RXPin = 8, TXPin = 7;
static const uint32_t GPSBaud = 19200;

// The TinyGPS++ object
TinyGPSPlus gps;
TinyGPSCustom test(gps, "TESTI", 9); 
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
  Serial.begin(19200);
  ss.begin(GPSBaud);

  // works
  while (*gpsStream)
    if (gps.encode(*gpsStream++)) //This works here
      displayInfo();

  Serial.println(F("Done."));
}

void loop()
{ 
  //doesn't work when sending data
  while (ss.available() > 0){  //Data is being received only not encoded
    if (gps.encode(ss.read())) // //This doesn't work
      displayInfo();
  }
}

void displayInfo()
{
  Serial.print(test.value());
  Serial.println();
}```
mikalhart commented 2 years ago

Hi @preshantram. If encode never returns true, it's almost certainly (a) not getting any characters [usually crossed wires] or (b) getting bad characters [usually incorrect baud rate]. I'd suspect the latter. 19200 is a rather unusual baud rate in my experience.

M

preshantram commented 2 years ago

It was due missing CR, LF in the stream.