Problem with Neo 6M and Arduino Mega 2560

Hey there!

I'm facing a problem with my ublox Neo 6M and the Arduino Mega 2560.
The GPS module is connected to 5V, RX to Pin 0, TX to Pin 1.
I've also tried different setups like RX/TX to 14-19 or in reverse or RX to 10/11, since I've read there are some issues with the Mega and the RX Pins.

I'm using the TinyGPSPlus library which is in the library folder of the IDE installation.
The baud rate of the serial monitor is set to 9600.
I'm working with OSX.

This is the code I'm using:

/*
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
 */
 
#include <SoftwareSerial.h>

// The serial connection to the GPS module
SoftwareSerial ss(0, 1);

void setup(){
  Serial.begin(9600);
  ss.begin(9600);
}

void loop(){
  while (ss.available() > 0){
    // get the byte data from the GPS
    byte gpsData = ss.read();
    Serial.write(gpsData);
  }
}

This is what is given out at the serial monitor:

�b��b��b��b��b��bbbbb�r��b�r��b�r��R��j
$GPGSV,3,1,10,01,5�

or alternativly:


/*
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
 */
 
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 0, TXPin = 1;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
}

void loop(){
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(gps.location.lng(), 6);
    }
  }
}

The serial monitor stays empty in this case.

Both Sketches work perfectly on the Arduino Uno.

I hope you can help me.
Thank You!
Marc

Look at the reference for the SoftwareSerial library at the section Limitations of This Library and in particular the part about the Mega.

Use a hardware serial port on the Mega. There are 3 extra besides Serial (UDB). Try this code. Connect GPS TX to Mega pin 19 (RX1) GPS RX not connected.

//gps test
// connect GPS TX to Mega pin 19 (RX1)  GPS RX not connected

void setup()
{
   // Open serial communications
   Serial.begin(9600);  
   Serial1.begin(9600);
   Serial.print("Mega up");
}

void loop()
{
   if (Serial1.available())
   {
      Serial.print(char(Serial1.read()));
   }
}

What do you see in serial monitor?

It works just perfekt!

Adjusting your code to this:

//gps test
// connect GPS TX to Mega pin 19 (RX1)  GPS RX not connected
#include <TinyGPS++.h>

// The TinyGPS++ object
TinyGPSPlus gps;

void setup()
{
   // Open serial communications
   Serial.begin(9600);  
   Serial1.begin(9600);
   //Serial.print("Mega up");
}

void loop(){
  // This sketch displays information every time a new sentence is correctly encoded.
  while (Serial1.available() > 0){
    gps.encode(Serial1.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude= "); 
      Serial.println(gps.location.lat(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(gps.location.lng(), 6);
    }
  }
}

Gives me:

 Longitude= X.XXXX21
Latitude= XX.XX890
...

I've read the limitations section in the library description.

Can you please explain it to me, why you decided to connect the GPS TX to 19(RX of the Mega) and don't connect the GPS RX to any pin? Whats the theory behind this? @groundFungus

Thank you so much!
Marc

TinyGPS++ does not ever send anything to the GPS unit so there is no reason to connect the Mega TX pin to the GPS RX pin.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.