1

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!!

  • 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 : – Akshay Mar 12 '17 at 14:52
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.