2

I am trying to run below code on Arduino Mega using GPS module(skg13 bl). It is working fine with pins 10, 11 as rx, tx in the SoftwareSerial but it is not showing output when other pins such as 4, 5 are used.

I further have to send this data through RF module using virtual wire library.

Code is as follows:

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
TinyGPSPlus gps;
SoftwareSerial mySerial(10, 11);
void setup() {
 mySerial.begin(9600);
 Serial.begin(9600);
 Serial.println("GPS start");
}
void loop() {
 while (mySerial.available()) {
 gps.encode(mySerial.read());
 }
 if (gps.location.isUpdated()) {
 double a = gps.location.lat();
 Serial.println(a);
 Serial.println(gps.location.lat(), 6);
 double b = gps.location.lng();
 Serial.println(gps.location.lng(), 6);
 }
}

Thanks in advance!!

per1234
4,2782 gold badges23 silver badges43 bronze badges
asked Mar 12, 2017 at 9:38
1
  • Thanks for your help that problem is solved but another problem is arise working with virtual wire library it is not showing gps data code is as : Commented Mar 12, 2017 at 14:52

1 Answer 1

2

From https://www.arduino.cc/en/Reference/softwareSerial:

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, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

So you will need to use one of the pins from that list for RX, pin 4 or 5 will not work.

answered Mar 12, 2017 at 13:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.