NEO 6M No altitude

I'm using a NEO-6M GPS, TinyGPS++ and NEOSWSerial to retrieve altitude data. Position is provided correctly

while (ss.available() > 0) {
      byte gpsData = ss.read();
      Serial.print((char)gpsData);
      gps.encode(gpsData);
    }
    if (gps.location.isUpdated()) {
      Serial.println(gps.location.lat()); 
      lat = gps.location.lat();
      lon = gps.location.lng();


    }
    if (gps.altitude.isUpdated()) {
      Serial.println(gps.altitude.meters());
      Serial.println(gps.altitude.value());
      altitude = gps.altitude.meters();
    }

Altitude is not provided or updated and the GPGGA record is shorter than documented:

$GPGGA,044846.00,4801.98814,N,01108.,4801.98826,N,01109.13744,E,044846.00,A,A*6D

You don’t use the library as it’s shown in the example (testing the output of gps.encode() to see if the sentence was complete before calling the library functions)

Try with one of the simple example of the library to see if you get the correct sentence out.

judging by this line, there are problems with receiving data in your sketch. The string shown consists a mess of three GPGGA strings.
It's amazing that you even show lat and lon.
Show the whole code.

I think the problem is the NeoSWSerial library. According to the documentation there should be an interrupt routine for newlines

#include <NeoSWSerial.h>
    NeoSWSerial ss( 4, 3 );
    
    volatile uint32_t newlines = 0UL;
    
    static void handleRxChar( uint8_t c )
    {
      if (c == '\n')
        newlines++;
    }
    
    void setup()
    {
      ss.attachInterrupt( handleRxChar );
      ss.begin( 9600 );
    }

If I add this interrupt handler - nothing ist retourned (I think this is caused be lack of interrupts on the Uno). Using AltSoftSerial returns no results and SoftwareSerial is not useable due to conflicts with other libraries.

You don't need to handle newlines in any specific way. Just read all the chars from port and put it in gps.encode() method. For works correctly, your code shouldn't contains any delays more than 5-10ms.

if you want further help - show the whole code, without the code there is nothing to talk about.

There should not be any code causing any delays. Below is the GPS relevant part of the code

#include <NeoSWSerial.h>
#include <TinyGPS++.h>
...
void setup(void) {
...
  Serial.begin(9600);
  ss.begin(9600);
...
}

void loop(void) {
...
while (ss.available() > 0) {
      byte gpsData = ss.read();
      Serial.print((char)gpsData);
      gps.encode(gpsData);


    }
    if (gps.location.isUpdated()) {

      Serial.println(gps.location.lat());

      
      lat = gps.location.lat();
      lon = gps.location.lng();


    }
    if(gps.speed.isUpdated()){
      speed = gps.speed.kmph();
    }
    if (gps.altitude.isUpdated()) {
      Serial.println(gps.altitude.meters());
      Serial.println(gps.altitude.value());
      
      altitude = gps.altitude.meters();
      lastAltitude = altitude;
    }
...
}

That doesn't look right. It includes two full latitudes:
4801.98814,N and 4801.98826,N
Two partial longitudes:
01108. and 01109.13744,E
And some other value twice:
044846.00 and 044846.00

Something is very wrong with the input. Maybe one of the devices has a clock that is slightly off so it is getting errors on a lot of characters?

Indeed. This may cover a multitude of sins though:

...

If you're doing a lot of printing, that may cause problems - you should be able to substantially increase the baud rate on Serial.

The ... were indeed the issue. The code was doing to much work and the buffer was full.
Thx for the hint

does delay() count as work? :innocent: :thinking:

Infact it was "kind of delay".... :frowning:

It is why I told you show the whole code. But you showed only "relevant part" and were sure that there were no problems in the rest of it. Typical newbie mistake.

That’s what I assumed :innocent:

If you want the project to be reactive you should avoid any long delay and code accordingly