While searching, I've seen some posts that indicate others are running Bluetooth Software Serial and GPS Software Serial psuedo simultaneously.
In the example below, when I uncomment the 4 GPS related lines in void setup(), my Bluetooth portion no longer works, when I comment those lines out again, my Bluetooth code will work.
What am I doing wrong that I'm not able to run both at the same time (in the same sketch) on my Arduino Mega?
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
SoftwareSerial BTSerial(12, 13); // RX , TX
// Serial In/Out Variables
String serialInString;
boolean newData = false;
// GPS Variables
TinyGPSPlus gps;
byte last_second;
char Time[] = "TIME:00:00:00";
char Date[] = "DATE:00/00/2000";
#define S_RX 11 // Define software serial RX pin
#define S_TX 10 // Define software serial TX pin
const int UTC_offset = -5; // Eastern Time
SoftwareSerial GPSSerial(S_RX, S_TX);
String getSettingValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
} // getSettingValue
void setup()
{
Serial.begin(9600);
while (!Serial)
{
; // Wait for serial to connect
}
BTSerial.begin(9600);
while (!BTSerial)
{
; // Wait for BTSerial to connect
}
//GPSSerial.begin(9600);
//while (!GPSSerial)
//{
// ; // Wait for BTSerial to connect
//}
delay(2000);
Serial.println("");
Serial.println(" ***** Start ***** ");
Serial.println("");
} // setup()
void loop()
{
while(BTSerial.available() > 0 && newData == false)
{
serialInString = BTSerial.readString();
Serial.print("New BT data: "); Serial.println(serialInString);
char serialInCharArr[serialInString.length() + 1];
serialInString.toCharArray(serialInCharArr, (serialInString.length() + 1));
String serialData = "";
for (int i = 0; i < serialInString.length(); i++)
{
if (serialInCharArr[i] == '<')
{
bool startCharFound = true;
serialData = "";
}
else if (serialInCharArr[i] == '>')
{
bool endCharFound = true;
Serial.print("End char found. serialData is: "); Serial.println(serialData);
newData = false;
String s_settingName = getSettingValue(serialData, '=', 0);
String s_settingValue = getSettingValue(serialData, '=', 1);
Serial.print("s_settingName: "); Serial.println(s_settingName);
Serial.print("s_settingValue: "); Serial.println(s_settingValue);
}
else
{
serialData = serialData + serialInCharArr[i];
}
}
delay(15);
}
} // loop()