Problem Using Multiple Serials

I can’t seem to get more than one serial up and running in my program. I’m trying to get some GPS data and then send it via SMS. I’m using sparkfun’s GPS shield and the cell shield in conjunction with new soft serial.

I know you can’t run two at a time but I thought my program addressed this problem. Anyway, any input would be greatly appreciated.

The code is as follows:

#include <NewSoftSerial.h>
#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of NewSoftSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 2(rx) and 3(tx).
*/

//GPS setup
TinyGPS gps;
NewSoftSerial nss(13, 12);

void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);

//Cell setup
NewSoftSerial cell(2,3);
const int buttonPin = 7;
int buttonState = 0;
char incoming_char=0;      //Will hold the incoming character from the Serial Port.


//Button Setup

void setup()
{
  //begin the serial connections
  Serial.begin(115200);
  nss.begin(4800);
  //cell.begin(9600);
  
  //setup the button
  pinMode(buttonPin, INPUT);
  
  Serial.print("Using TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println();
  Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS));
  Serial.println();
  Serial.println("SYSTEM: Starting chip comms");
  
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  
  bool newdata = false;
  unsigned long sysTime = millis();
  
  checkButton(gps);
  
  
  //if(cell.available() >0)
  {
    //incoming_char=cell.read();    //incoming char fetch.
    //Serial.print(incoming_char);  //Print the sucker
  }
  //and the same thing...but backwards, check to see if it's coming from the system to the cell
  if(Serial.available() >0)
  {
    incoming_char=Serial.read();  //Get the character coming from the terminal
    //cell.print(incoming_char);    //Send the character to the cellular module.
  }
  
}

void checkButton(TinyGPS gps)
{
  if(buttonState == LOW and feedgps())
  {
    Serial.println();
    Serial.println("SYSTEM: Button Pushed");
    sendData(gps);
    delay(100);
  }
}
    
    
void sendData(TinyGPS gps)  //uses cell as the active device
{

  long lat, lon;
  unsigned long age;
  
  gps.get_position(&lat, &lon, &age);
  
  cell.begin(9600);
  
  cell.begin(9600);
  
  if(cell.available())
  {
  //begin the print statements
  cell.print("AT+CMGF=1\r");
  Serial.print("AT+CMGF=1\r");
  
  delay(100);
  
  cell.print("AT+CMGS=\"2403426240\"\r");
  Serial.print("AT+CMGS=\"2403426240\"");
  
  delay(100);
  
  String latString = lat;
  String lonString = lon;
  
  String printString = (latString);  
  cell.print(printString);
  Serial.print(printString);
  
  }
}

  
bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

Please modify your posting by adding the code tags around the code : use the # button in the editor .


No experience with GPS but there are some code snippets I don't understand (did not really dive into it yet)

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of NewSoftSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 2(rx) and 3(tx).
*/

NewSoftSerial nss(13, 12);

bool feedgps()
{
 while (nss.available())
 {
   if (gps.encode(nss.read()))
     return true;
 }
 return false;
}

In the comment it is stated that pin 2,3 must be used but feedgps() calls nss that uses pin12,13. So if I am correct this application has 3 serialports nss(12,13) nss(2,3) and the hardware Serial. If I recall correctly NSS can do multiple connections but only under certain conditions - not receiving at the same time.

Could you share with us the exact shields used including the pins they use?

Thanks for the tip. Seems I pushed every other button looking for that.