I am using a Bluetooth mate with an Arduino Mega 2560 and finding that the Mega is only receiving serial communication when I use pin 13 for RX which is connected to TX-0 on the mate. I am trying to determine why this is occurring since the documentation indicates I should be able to use pins like 15,17, or 19 for RX.
I can use different pins on the mega for TX without issue. When it's working I see the TX LED on the Mega blink when I send a message, but when not on pin 13 I get nothing. My code is below:
#include <SoftwareSerial.h>
int bluetoothTx = 13; // RX-I pin of bluetooth mate connects to TX of Arduino
int bluetoothRx =22; // TX-O pin of bluetooth mate connects to RX of Arduino
String bluetoothMsg = "";
SoftwareSerial bluetooth(bluetoothTx,bluetoothRx);
void setup() {
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
}
void loop() {
bluetooth.listen();
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Read the char
char newChar = (char)bluetooth.read();
//
// Append the chart to the string
//
if(newChar == '^')
{
Serial.print(bluetoothMsg);
}
else if(newChar == '~')
{
bluetoothMsg = "";
}
else
{
bluetoothMsg += newChar;
}
}
}