I'm stuck at this seemingly simple thing. I have a NMEA GPS module. It doesn't matter how it operates, it just transmit serial data stream at a baud rate of 38400.
I have an arduino Mega which has several hardware serial modules. If i directly connect GPS Tx to Arduinos Tx pin (and program arduino to not to use default serial module, Serial0
) then i can observe raw GPS sentences transmitted by the GPS module using the arduino serial monitor.
What I really want is to read the GPS module to arduino Serial1
port and forward the receiving data through the default serial port Serial0
without doing anything. So that i should be able to monitor the data from the serial monitor as exactly in the previous case.
I tried something like follows, but it's not working (it gives a stream of digits, i tried doing all the possible changes but nothing worked)
void setup(){
Serial.begin(38400); // the default serial module, serial0
Serial1.begin(38400); // GPS is connected to this
}
void loop(){
if(Serial1.available()){ // if GPS data available
Serial.print(Serial1.read()); // write it to serial0
}
}
Hope someone here will be able to give me some solution.