Software Serial inconsistent with Hardware Serial

I’m trying to get a ublox GPS module working with a Leonardo using the Software Serial libary,

if i run this code using Software Serial to read the data and spit it out over usb

#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9); // RX, TX

void setup()  
{
  Serial.begin(38400);
   while (!Serial) {}
    
  mySerial.begin(38400);  
}

void loop() 
{
  if (mySerial.available()>0)
   {
     Serial.write(mySerial.read());
  }
}

I get the output as in first picture attached bellow, as you can see this is not the correct GPS data

if i use the Leonardo’s hardware serial port with this code,

void setup()  
{
  Serial.begin(38400);
   while (!Serial) {}
  
  Serial1.begin(38400);  
  
}

void loop() 
{
  if (Serial1.available()>0)
  {
    Serial.write(Serial1.read());
  }
}

I get the correct NMEA GPS messages as attached bellow

I think the data is the same but in a different format?? or have I messed up the code?

Thanks for any help or advice

Not all pins on the various Arduinos support pin change interrupts, which is a requirement of pins used for SoftwareSerial. You need to see which ones support pin change interrupts on the Leonardo.

as you can see I am using pin 8 of the leo and according to the Software Serial page

-Not all pins on the Leonardo support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

so that should be fine?

also in some more testing i have found the ublox gps test PC software accepts the Software serial data and plots the correct location, but it cant find as much data in it as the hardware serial data, ie software serial does not have the time and date whereas the it gets it from the hardware serial data

Thanks

I have this exact problem! I posted a question a question about it this morning, but I haven't solved it yet. There were some posts on the Sparkfun site where I bought my GPS module (a Locosys LS20031) about increasing the receive buffer size in the SoftwareSerial.h header.

In NewSoftSerial.h: NewSS_MAX_RX_BUFF 64 to NewSS_MAX_RX_BUFF 256

Here's the link to that post, it's at the bottom in the customer comments: https://www.sparkfun.com/products/8975 This did NOT fix the problem for me, unless I did something wrong modifying the Library (I learned some things about OSX while trying to find where those library files were hidden!) But it seems like a possibility for you.

Let me know if you solve this!

thanks for the help,

no luck though, still spits out the same data, I think the hardware buffer is 64 bytes as-well so it wouldn't account for the difference between the two methods.