Arduino Mega 2560-GPS module and Serial1,2,3 problem

Hello everyone,

I have an arduino Mega 2560 connected with the GPS module from coocking-hacks (http://www.cooking-hacks.com/index.php/shop/arduino/gps-module-for-arduino-166.html). When I connect the module on serial 0 (plain "serial" in software) everything works fine (i can even see data in the serial monitor, if I run a no sketch), but when I connect it to Serial 1 ,2 or 3 (serial1,2,3 in software) nothing works. I tried connecting serial1(or 2 or 3) to serial with 2 cables and run the following sketch:

void setup(){ Serial.begin(4800); Serial1.begin(4800); }

void loop(){ Serial1.println("Test"); delay(2000); }

witch should display: Test Test Test ... in serial monitor but it didn't. Is there anything wrong with arduino mega 2560 and it's serial ports?

I am writing in arduino IDE 0022, on windows 7 x64.

Thanks in advance.

I will look at this later if nobody else does I have the same board...

I presume that you put Two wires from (tx to rx)and (rx to tx) Just asking? I know I have made mistakes like that... :roll_eyes:

Exactly! RX0->TX1, RX1->TX0.

Thanks you for your help.

I presume that you put Two wires from (tx to rx)and (rx to tx) Just asking? I know I have made mistakes like that.

I hope that you also connected the grounds. Otherwise, there will be flow of electrons.

I hope that you also connected the grounds. Otherwise, there will be flow of electrons.

Well something like that. :D

This works…

/*
  Mega multple serial test
 
 Receives from the main serial port, sends to the others. 
 Receives from serial port 1, sends to the main serial (Serial 0).
 
 This example works only on the Arduino Mega
 
 The circuit: 
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:
 
 created 30 Dec. 2008
 by Tom Igoe
 
 This example code is in the public domain.
 
 */

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);

/// note this line which "primes the pump"  otherwise you get nothing...
  Serial.print("a");

}

void loop() {
  // read from port 1, send to port 0:

  if (Serial1.available()) {
    byte inByte = Serial1.read();
    Serial.print(inByte, BYTE);
}
}

Hope that helps…

And this works too...

void setup(){
  Serial.begin(9600);
  Serial1.begin(9600);


}

void loop(){
    Serial.print("Test"); 
  if (Serial1.available()) {
    byte inByte = Serial1.read();
    Serial.print(inByte, BYTE);
  }

  delay(100);
}

Happy GPSing...

Now make sure you report back... I want to add a GPS and I would rather copy someone elses work as my C++ skills are about -2 on a scale of 1 to 100. ]:D

Back to the real problem...

GPS systems tend to work in one of two ways...

1) Send them a command and they spout data forever... 2) Send them a command and they return only what you asked for one time.

Sooo.. which is yours...

Either way you will send a command them wait for data as shown...

PaulS:

I presume that you put Two wires from (tx to rx)and (rx to tx) Just asking? I know I have made mistakes like that.

I hope that you also connected the grounds. Otherwise, there will be flow of electrons.

Ground was connected. It gets power from arduino borad

WillR,

both codes you have supplied work because you actually print on serial0 (Serial.print("a") and Serial.print("Test")). That is why you get data on serial monitor!!! :)

With the first code, if I connect the gps to serial1, I only get an "a" and nothing more, where I should get raw gps data since the module start to transmit as soon as it gets connected to power. (you can then send commands to activate or deactivate required NMEA sentences)

However, I did SOLVED the problem where I wasn't expecting to!

Pin 1 of the GPS module is the RX and pin 2 is the TX. To work with serial0 you connect pin 1 of the module to RX0 of the Arduino and pin 2 to TX0(the antenna is facing towards the USB connector)!!! As far as I kown RX pin shout be connected to TX pin. And that is how you should connect it for serial1, 2 and 3 to work. (the antenna should face to the opposite direction)!!!!! :astonished:

So I suppose something is printed wrong on arduino MEGA 2560!!!

Anyway, thanks for your responses.

P.S.1 - Any question for the GPS are welcome. P.S.2 - There are some very nice libraries for manipulating gps data, although it is quite easy to do it by your self ;)

Hi Katsikar,

I am having same trouble as you were. But i didn’t really get it how did you solve it.
For example even the simple code that is given on arduino website doesn’t work on arduino mega. http://arduino.cc/en/Serial/Begin

// Arduino Mega using all four of its Serial ports
// (Serial, Serial1, Serial2, Serial3),
// with different baud rates:

void setup(){
Serial.begin(9600);
Serial1.begin(38400);
Serial2.begin(19200);
Serial3.begin(4800);

Serial.println(“Hello Computer”);
Serial1.println(“Hello Serial 1”);
Serial2.println(“Hello Serial 2”);
Serial3.println(“Hello Serial 3”);
}

void loop() {}

I am also trying to use GPS module on the serial port and it doesnt work with 1, 2 or 3 but it works with serial 0.

Thanks,
Zubin

I got the Arduino Mega 2650 working nicely with the ITEAD GPS shield v1.1 using the Serial1 interface. More in my blog at http://davidhoulding.blogspot.com/2014/06/gps-location-sensing-with-arduino-mega.html

blog post didn't help, nothing there other than the boilerplate code that comes with the GPS.

anyone have anything specific to the Mega 2560 and how to get serial1/2/3 working?

That blog code looks good to me. It looks Mega specific, using Serial and Serial1. I haven't tried it tho.

If you make a boilerplate request, you'll get boilerplate code.

NeoGPS examples work with Serial1 by default, but you can easily change that.

Be sure to connect the GPS TX to the Arduino RX, and the GPS RX to the Arduino TX. Use level shifting if the GPS module is 3.3V, not 5V.

Cheers, /dev

-dev: NeoGPS examples work with Serial1 by default, but you can easily change that.

Be sure to connect the GPS TX to the Arduino RX, and the GPS RX to the Arduino TX. Use level shifting if the GPS module is 3.3V, not 5V.

Cheers, /dev

Thank you for this library. I believe it might help me with my project. Nothing else has worked on Mega with my Dragino GPS.