Problem with comparison.

The device to which I send data, to correctly display the letters E, N, W, S at coordinates, needs the following data:

digit 1 display N.W
digit 2 display S.E
digit 3 display N.E
digit 4 display S.W

For this purpose, I used the TinyGPS ++ library and made such a program to download data, then check them and finally use the appropriate number for the currently given letters at the coordinates.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
TinyGPSCustom Lat1(gps, "GPGGA", 3);
TinyGPSCustom Lon1(gps, "GPGGA", 5);

int cord;
int co1 = 1;
int co2 = 2;
int co3 = 3;
int co4 = 4;

char N = 'N';
char S = 'S';
char W = 'W';
char E = 'E';

void setup()

void loop()
Serial.print(" ALT="); Serial.print(gps.altitude.meters());
Serial.print(" LAT="); Serial.print(Lat1.value());
Serial.print(" LON="); Serial.print(Lon1.value());
Serial.print(" cord="); Serial.print(cord);
Serial.print(" SATS="); Serial.println(gps.satellites.value());

while (Serial.available() > 0)

//(1 =N.W)(2 =S.E)(3 =N.E)(4 =S.W)
if ( Lat1.value() == N && Lon1.value() == E)
  cord = co3;
if ( Lat1.value() == N && Lon1.value() == W)
  cord = co1;
if ( Lat1.value() == S && Lon1.value() == W)
  cord = co4;
if ( Lat1.value() == S && Lon1.value() == E)
  cord = co2;

The program does not report errors but does not work.
I tried sending comparisons to the serial monitor.

Serial.print(" TEST ="); Serial.print(Lat1.value());      
Serial.print(", TEST1 ="); Serial.print(Lat1.value() == 'N' );
Serial.print(", TEST2 ="); Serial.print(Lat1.value()== N );

I received the results:

TEST1 = 0
TEST2 = 0

Comparisons don’t work and I don’t know why.

TEST2 = 0
TEST3 = 0

Not from that code.

Have you tried strcmp?

I corrected the mistake. I haven't tried strcmp. I'll try and let you know the effects.

Why don’t you just check the return type of the relevant functions?

If you want to be cheesy, I think you could de-reference the C string, because you are only comparing one character: *Lat1.value() == 'N'(untested) Don't tell anyone I suggested it. :)

Thanks to everyone, the problem was solved by using string.

stringOne = String(Lat1.value());
stringTwo = String(Lon1.value());

if (stringOne == "N" && stringTwo == "S") {
   cord = co1;

Result in serial monitor:

Stringone=N Stringtwo=E cord=0 Stringone=N Stringtwo=S cord=1

Everything works, now only expand the program with a few formula and everything will be OK. Thanks again for your help :)

Thanks to everyone, the problem was solved postponed by using String.

Fixed that for ya.

Strings introduce new problems, like unpredictable program crashes.

My program with strings has been running for an hour without problems, sending all data without errors.

Damian01: My program with strings has been running for an hour without problems, sending all data without errors.

... wait until the heap gets fragmented. It can take some time.