This simplified code:
#include <SoftwareSerial.h>
SoftwareSerial SSerial(10, 11); // RX, TX
void setup() {
SSerial.begin(9600);
Serial.begin(9600);
}
void loop() {
String content = "";
char character;
while(SSerial.available()) {
character = SSerial.read();
content.concat(character);
}
if (content != "") {
Serial.print(content);
}
}
The pins are rx:10, tx:11, because it’s a Mega ADK:
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Produces sensible GPS data (although no fix as it can't see sky):
$GPRMC,141227.080,V,,,,,0.00,0.00,080318,,,N44
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N32
$GPGGA,141228.080,,,,,0,0,,,M,,M,,4C
$GPGSA,A,1,,,,,,,,,,,,,,,1E
$GPRMC,141228.080,V,,,,,0.00,0.00,080318,,,N4B
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N32
$GPGGA,141229.080,,,,,0,0,,,M,,M,,4D
$GPGSA,A,1,,,,,,,,,,,,,,,1E
$GPRMC,141229.080,V,,,,,0.00,0.00,080318,,,N4A
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N32
$GPGGA,141230.080,,,,,0,0,,,M,,M,,45
$GPGSA,A,1,,,,,,,,,,,,,,,1E
$GPRMC,141230.080,V,,,,,0.00,0.00,080318,,,N42
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N32
$GPGGA,141231.080,,,,,0,0,,,M,,M,,44
$GPGSA,A,1,,,,,,,,,,,,,,,1E
$GPRMC,141231.080,V,,,,,0.00,0.00,080318,,,N43
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N32
If I change it to the following (add 'SSerial.print(content);' after the hardware serial print to console):
#include <SoftwareSerial.h>
SoftwareSerial SSerial(10, 11); // RX, TX
void setup() {
SSerial.begin(9600);
Serial.begin(9600);
}
void loop() {
String content = "";
char character;
while(SSerial.available()) {
character = SSerial.read();
content.concat(character);
}
if (content != "") {
Serial.print(content);
SSerial.print(content);
}
}
It produces this:
G MY⸮ 9&⸮Sj
$⸮5 ⸮⸮.S⸮&LU⸮⸮0⸮b⸮ i K⸮⸮2 HGPVTG,0.00,T,,M,0.00,N,\⸮-⸮⸮⸮⸮⸮$G ⸮њ⸮⸮ &⸮⸮⸮⸮ &%SK⸮X⸮5":A M ⸮A⸮bĉ⸮⸮⸮⸮JL
$AI ⸮⸮ r⸮b⸮⸮,,⸮⸮ ⸮⸮NKN4 ⸮AYu &U⸮⸮0.9⸮r )⸮Ji⸮j $⸮G ⸮h⸮⸮r⸮⸮ ⸮⸮⸮ &%S⸮⸮,,*4B $G⸮ ⸮⸮⸮⸮⸮⸮⸮JL⸮ $GPRMC,141359.ᱱbb &&LK⸮⸮18X⸮D⸮H⸮ ⸮K⸮0Q⸮j⸮ ⸮br⸮0.00,K,N*32 $G ⸮⸮т⸮ &⸮⸮⸮⸮ ⸮K⸮ !!TP⸮,1,,,,⸮⸮bbbĉ9LQ $GI5 ⸮⸮ ⸮r⸮b⸮⸮,X⸮⸮ ⸮ ⸮'KN*n) AEu L⸮⸮M,⸮⸮r⸮r )Ji⸮j $G ⸮Ѣ⸮⸮ &⸮⸮⸮⸮ &⸮K⸮SA!TP⸮,1,,,,⸮⸮bbb⸮⸮9LQ $GI5 ⸮⸮ ⸮r⸮b⸮⸮,X⸮⸮ ⸮ ⸮'KN*l) AEu L⸮⸮,0
⸮⸮r Ji⸮j
$G ⸮⸮т⸮ '⸮⸮⸮⸮ ⸮⸮⸮⸮2 HGPGSA,A,⸮bbĉ⸮⸮⸮9LQ
Both outputs are from the IDE monitor, I can understand if the output (tx) is not in the correct format but I can’t see why the serial monitor output is affected by the change above. Can you see what I’m missing?
The requirement is send non-GPS data through an existing RF system. To read GPS data on softwareserial rx, substitute a sensor reading into the lat/log values in the data, then send the substituted data out on tx. The sensor read, NMEA decode and substitution bit is all working.
At this stage I want to receive the NMEA data on rx and forward it straight out on tx. Thank you for advice.