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:
/*
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);
}
}
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
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 ;)
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: