0

I am currently trying to to use two different serial ports on my arduino uno that is (2,3) for gsm and (8,9) for gps. I have tried both of this links;

1) arduino-uno-with-multiple-software-serial-devices

2) Two port receive using software serial on Arduino.

But nothing seems to be working. The serial monitor displayed nothing.

UPDATE

I changed the libraries of my gps and serial ports to AltSoftSerial and NeoSWSerial. Although both of them working just fine if I use it in the examples. But when I implement both of the libraries and run the code, there are no results in the serial monitor.

#include <NMEAGPS.h>
#include <GPSport.h>
#include <AltSoftSerial.h>

AltSoftSerial sim900a;

NMEAGPS  gps; // This parses the GPS characters
gps_fix  fix;

void setup()
{
  Serial.begin(9600);
  sim900a.begin(9600);
  gpsPort.begin(9600);
}

void loop()
{
  while (gps.available(gpsPort))
  {
    fix = gps.read();

    if (fix.valid.location)
    {
      Serial.println();

      Serial.print("Latitude= "); 
      Serial.print(fix.latitude(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(fix.longitude(), 6);
      sendData = 1;
    }
    else
    {
      sendData = 0;
    }
  }

  if(sendData == 1)
  {
    //do stuffs
    delay(5000); 
  }
}

P/S: I have already tried listen() method to turn off and on each ports but it doesn't seem to be working as intended. Any helps are welcomed. Thank you.

Asyraf
  • 35
  • 1
  • 8

1 Answers1

1

You will not be able to use two software serial libraries to listen to the SIM900 and the GPS.

The main problem is that SIM900 characters can arrive at any time. They could arrive while you are listening to one software serial port.

The only way is to use the hardware serial port for one of the devices. I suggest connecting the GPS TX pin to the Arduino RX pin 0. Then you will read GPS characters on Serial. You will have to disconnect pin 0 to upload new sketches over USB. You can still use Serial.print to display information on the Serial Monitor window.

The SIM900 should be on pins 8 & 9, where you can use AltSoftSerial. This is much more efficient than SoftwareSerial. SoftwareSerial disables interrupts for long periods of time, which can interfere with other parts of your sketch or with other libraries. Avoid it at all costs.

More detailed information in this answer and on my NeoGPS library Installation page: Choosing a Serial Port.

NeoGPS and AltSoftSerial are available from the Arduino IDE, under the menu Sketch -> Include Library -> Manage Libraries.

slash-dev
  • 1,569
  • 2
  • 9
  • 9
  • Sorry for late reply. Here's the update; I have successfully implement NeoGPS library and run the code by including NeoSWSerial in the GPSport.h. After testing it in the example, I move on to my project. I have include both AltSoftSerial and NeoGPS libraries into my code, but still no output received through my serial monitor. I will include my latest code into my question. Thank you for replying to me sir. – Asyraf Apr 26 '18 at 19:51
  • My bad, I forgot that I had an interrupt setup that mess up my codes, when I removed those line of codes, the code runs perfectly as intended. Thank you sir. :) – Asyraf Apr 26 '18 at 20:46
  • Btw, I want to insert those code in the void loop() into the interrupt setup. Because I wish to insert the data received from lat lng into the server. all the time. is that possible? – Asyraf Apr 26 '18 at 21:50
  • @Asyraf, I'm not sure. Show the code in another UPDATE section in your question. – slash-dev Apr 26 '18 at 23:52