Adding 2 GPS Modules to 1 Arduino

Hi All,
Im attempting to run 2 UART GPS modules. What Im hoping to achieve is the first GPS (gpsr) on pins 6,5 sends serial data. Second GPS (gpsb) on pins 4,3 also sends serial data. TinyGPSplus libray interprets the 2 sets of serial data to determine distance and cardinals between the 2 sets of data and this is displayed on the LCD via LiquidCrystal_I2C library. No error on compiling. When I upload the code the void setup displays on the LCD then hangs. The serial monitor returns

WARNING: No GPS data. Check wiring.

The ventual aim is to replace the hardwired first GPS with a LoRa module so that the 2 GPS modules can be several hundred meters apart
My code is
Thanks
GRI2A

#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
TinyGPSPlus gpsr;
TinyGPSPlus gpsb;
SoftwareSerial portRocket(6, 5);
SoftwareSerial portBase(4, 3);

void setup()
{
  Serial.begin(9600);
  portRocket.begin(9600);
  portBase.begin(9600);
  Serial.print(F("Testing TinyGPSPlus library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println();
  //LCD
	lcd.init();
	lcd.backlight();
	lcd.setCursor(0,0);
	lcd.print("Geoff's GPS");
	lcd.setCursor(0,1);
	lcd.print("Dist & Coord");
	delay(3000);
}

void loop()
{
   while (portRocket.available() > 0)
    gpsr.encode(portRocket.read());
 
   while (portBase.available() > 0)
    gpsb.encode(portBase.read());
 
    if ((gpsr.location.isValid()) && (gpsb.location.isValid()))
    {
      double distanceToRocket =
        TinyGPSPlus::distanceBetween(
          gpsb.location.lat(),
          gpsb.location.lng(),
          gpsr.location.lat(),
          gpsr.location.lng());
      double courseToRocket =
        TinyGPSPlus::courseTo(
          gpsb.location.lat(),
          gpsb.location.lng(),
          gpsr.location.lat(),
          gpsr.location.lng());
    
      Serial.print(F("Distance="));
      Serial.print(distanceToRocket/1000, 6);
      Serial.print(F(" km"));
      Serial.print(F(" Co-ords="));
      Serial.print(TinyGPSPlus::cardinal(courseToRocket));
      Serial.println(F("-"));
      
  lcd.clear();    
  lcd.setCursor(0,0);
  lcd.print("Dist :");
  lcd.setCursor(7,0);
  lcd.print(distanceToRocket, 0);
  lcd.setCursor(13,0);
  lcd.print("Mts");
  lcd.setCursor(0,1);
  lcd.print("Co-ord :");
  lcd.setCursor(9,1);
  lcd.print(TinyGPSPlus::cardinal(courseToRocket));
delay(1000);
    }

    if ((gpsr.charsProcessed() < 10) || (gpsb.charsProcessed() < 10))
      Serial.println(F("WARNING: No GPS data.  Check wiring."));

    //last = millis();
    Serial.println();
  }

What Arduino are you using? That is very important in this case.

Only one software serial port can listen at a time. See the 2 port receive example from the SoftwareSerial library.

Really, I would use an Arduino with multiple hardware serial ports. Managing more than one software serial ports is usually a hassle.

Thank you for properly posting code in your first post.

Hello gri2a
Can the GPS receiver see the satellites or just the ceiling of your room ?

Paul,

If I rem out the gpsr code, gpsb can see upto 6 satellites, and successfully delivers all NMEA sentences.

If I rem out the gpsb code, gpsr can see upto 6 satellites, and successfully delivers all NMEA sentences.

Nothing wrong with the GPS modules. Its a dual serial problem

GRI2A

Showing your age....

Groundfungus,

This is part of a longer term plan. If I can get the code working on a UNO or NANO, I will be bootloading to ATMEGA328P chips, creating a PCB (add the LCD, power regulator etc) so that it can be used by many people that share my hobby of amateur rocketry. A rocket that goes up 3000m in a 20kmh wind, can be difficult to find and retrieve without a GPS tracker, hence the 2 GPS modules, one in the rocket and one in the base (ground) station

GRI2A

Groundfungus,

In restrospect, you are absolutely right. Im trying to get too much out of a UNO/NANO.

The Mega has multiple hardware TX/RX ports... why not use them. Much easier than trying to get serial I/Os to do something they are not supposed to.

Changing a handful lines of code to Serial1 and Serial2 and then hooking up the GPS Modules to TX/RX1 and TX/RX2...

Job done, code works a treat.

Next job, replace Serial1 with LoRa so I can physically move one of the GPS modules a kilometer or so away

Thanks for your help

GRI2A

Are you aware of the Mega Pro. It is a Mega in a more compact form factor.

The more I look, the more people I find with this isssue. As I have overcome the problem, I am raising this one last post.
I re-wrote the sketch for a MEGA that has multiple hardware RX/TX ports as mentioned above BUT, I persisted with the simultaneous serial port issue and found a solution for UNO, NANO style boards.
It involves using SoftwareSerial Library to control one set of I/O ports AND AltSoftSerial to control the second one. Take special not of lines 2 & 3 and 8 & 9 to overcome the .simultaneous issue with SoftwareSerial

#include <TinyGPSPlus.h>
#include <AltSoftSerial.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
TinyGPSPlus gpsr;
TinyGPSPlus gpsb;
SoftwareSerial SerialGPSR(4,3);
AltSoftSerial SerialGPSB(9,8);

GRI2A

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.